Нет ошибки метода - разработка
В настоящее время я получаю эту ошибку при попытке сделать этот маршрут.
неопределенный метод `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]
2 ответа
Решение
Вы только передаете ссылку на пользователя с путем.
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 %>
неопределенный метод `user_tourcomplete_offer_path'
Согласно вашему routes
, так должно быть user_offer_tourcomplete_path
,
<%= link_to "Finish", user_offer_tourcomplete_path(current_user), class: "joyride-next-tip", method: :put %>