开发者

No route matches for something that should be working

开发者 https://www.devze.com 2023-03-12 06:41 出处:网络
I have: <%= button_to \'Remove\', remove_attendee_event_path(:event_id => @event.id, :user_id => user.id), :method => :post %>

I have:

<%= button_to 'Remove', remove_attendee_event_path(:event_id => @event.id, :user_id => user.id), :method => :post %>

in one partial and it works fine. Then, in another partial in the same view, I tried to copy/paste this code while changing @event.id t开发者_开发问答o event.id and user.id to current_user.id and it doesn't work. It tells me RoutingError in Events#index

No route matches {:action=>"remove_attendee", :controller=>"events", :event_id=>4, :user_id=>108}

WHat am i doing wrong?


It's not the route it is your object. You are padding nil objects to the method.

Check which object is nil with:

<%= debug @event %>
<%= debug user #most likely this one %>

Local variables need to be sent to views like this:

<%= render :partial => 'somethign' :user => user %>


I think the problem is that you're passing an :event_id parameter to the path helper instead of :id. A member action requires an :id attribute to specify the member to work with, which in the EventsController will be an Event.

In the partial where this line of code worked, rails was filling in the :id for you based on the current request (which must have been another member action where an Event id was available). The :event_id that you supplied as an argument was ignored (or actually it was probably tacked onto the end of the URL after the question mark and then ignored by the remove_attendee method in the controller).

But now when you try the same line in the index view, it has no :id to fill in the gap, so it's cryptically complaining.

0

精彩评论

暂无评论...
验证码 换一张
取 消