我正在尝试执行此路线时收到此错误。
未定义的方法`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: "test@test.com", 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 :(得分: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 %>
答案 1 :(得分:1)
您只是通过路径传递用户的依据。
user_offer_tourcomplete_path(current_user)
但生成的实际路线将是:
user_offer_tourcomplete PUT /u/:user_id/offers/:offer_id/tourcomplete(.:format)
所以提供报复也是必要的。您还需要在路径中传递offer_id。
<% offer = some_offer_object %>
<%= link_to "Finish", user_offer_tourcomplete_path(current_user,offer), class: "joyride-next-tip", method: :put %>