2015-10-17 45 views
0

我正在嘗試執行此路線時收到此錯誤。沒有方法錯誤 - 設計

未定義的方法`user_tourcomplete_offer_path」

我不知道如何解決它,嘗試過一切。

的routes.rb

devise_for :users 
    resources :offers 

    # Root 
    root 'welcome#index' 

    # Rails Admin Engine 
    mount RailsAdmin::Engine => '/admin', as: 'rails_admin' 

    # User ID in URL 
    resources :users, path:"u" do 
    resources :offers do #-> url.com/users/:user_id/offers 
     put :tourcomplete #-> you don't need member do 
    end 
    resources :categories, only: :show 
    end 

index.html.erb

<% if current_user.tourcomplete == true %> 

<% else %> 

<ol id="tour"> 

    <li class="welcome-tour"> 
    <%= image_tag "welcome-smiley.png" %> 
    <h2>Welcome to Bundel</h2> 
    <p>Pick from over 3,000 offers available at Bundel, all you have to do is click and shop just like usual.</p> 
    <a href="#" class="joyride-next-tip">Start Tour</a> 
    </li> 

    <li data-class="offer"> 
    <h4>Pick your Offer</h4> 
    <p>Pick from over 3,000 offers available at Bundel, all you have to do is click and shop just like usual.</p> 
    <a href="#" class="joyride-next-tip">Next</a> 
    </li> 

    <li data-class="balance"> 
    <h4>Your Balance</h4> 
    <p>How much you've earnt via Bundel, this will increase on purchasing.</p> 
    <a href="#" class="joyride-next-tip">Next</a> 
    </li> 

    <li data-class="values"> 
    <h4>Cashback Values</h4> 
    <p>This is how much cash back you will receive on any purchase made with this retailer. (Please read the terms on hover)</p> 
    <%= link_to "Finish", user_offer_tourcomplete_path(current_user), class: "joyride-next-tip", method: :put %> 
    </li> 
</ol> 

<script> 
$(window).load(function() { 
    $('#tour').joyride({ 
    autoStart : true, 
    tipLocation: 'right',   // 'top' or 'bottom' in relation to parent 
    nubPosition: 'auto',   // override on a per tooltip bases 
    scrollSpeed: 300,    // Page scrolling speed in ms 
    nextButton: false,    // true/false for next button visibility 
    tipAnimation: 'fade',   // 'pop' or 'fade' in each tip 
    }); 
}); 
</script> 

<% end %> 

offers_controller.rb

def index 
    @offers = Offer.all 

    def tourcomplete 
     current_user.update_attributes(tourcomplete: true) 
     redirect_to root_url 
    end 

    @featured_offers = Offer.where(featured: true) 

    end 

條耙路線

user_offer_tourcomplete PUT /u/:user_id/offers/:offer_id/tourcomplete(.:format) 

提供#tourcomplete

完全錯誤

No route matches {:action=>"tourcomplete", :controller=>"offers", :offer_id=>nil, :user_id=>#<User id: 2, email: "[email protected]", encrypted_password: "$2a$10$RSX5sD9G5ipdtDAG32BirOw3WDma13yuHYV6bNQTb5Y...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 1, current_sign_in_at: "2015-10-17 18:16:55", last_sign_in_at: "2015-10-17 18:16:55", current_sign_in_ip: "127.0.0.1", last_sign_in_ip: "127.0.0.1", created_at: "2015-10-17 18:16:55", updated_at: "2015-10-17 18:16:55", beta_key: "ahfyqom124k19jsalx9", paypal: nil, balance: 0.0, admin: false, tourcomplete: false>} missing required keys: [:offer_id] 
+0

Pavan的回答是正確的。作爲提示,耙路線是你的朋友!只需在命令行輸入'rake routes'或'bundle exec rake routes'。您將看到當前的所有路由,第一列將是路徑幫助程序方法(如'user_offer_tourcomplete')。 – dwenzel

回答

1

您只是將路徑傳遞給用戶。

user_offer_tourcomplete_path(current_user) 

但產生的實際路徑將是:

user_offer_tourcomplete PUT /u/:user_id/offers/:offer_id/tourcomplete(.:format) 

所以提供全球化志願服務青年也necesssary。您還需要在路徑中傳遞offer_id。

<% offer = some_offer_object %>  
<%= link_to "Finish", user_offer_tourcomplete_path(current_user,offer), class: "joyride-next-tip", method: :put %> 
+0

不幸的是,這是行不通的 – Jonathan

+0

你可以嘗試在link_to函數中使用user_offer_tourcomplete_path(current_user,1)並檢查 –

+0

@Jonathan是否有任何運氣,我提到了上述建議? –

1

未定義的方法`user_tourcomplete_offer_path」

根據您的routes,應該是user_offer_tourcomplete_path

<%= link_to "Finish", user_offer_tourcomplete_path(current_user), class: "joyride-next-tip", method: :put %> 
+0

未定義的方法'user_offer_tourcomplete'仍然得到它。我將發佈耙路線和我的控制器在問題 – Jonathan

+0

@Jonathan還發布你現在得到的完整錯誤。 – Pavan

+0

我現在已經更新了提供耙路和控制器的問題。感謝您的幫助:) – Jonathan