【发布时间】:2014-01-13 02:13:32
【问题描述】:
我找到了解决我的问题的好方法here
我已将它构建到我自己的项目中,但我似乎无法调用withdraw 事件。
show.html.erb
<p><strong>Attendees: </strong>
<ul>
<% for attendee in @event.users %>
<% if attendee.id == current_user.id %>
<li><strong><%= attendee.name %></strong>
<%= link_to 'Withdraw From Event', withdraw_event_path(@event.id), :method => :post, :class => 'btn btn-danger' %>
</li>
<% else %>
<li><%= attendee.username %></li>
<% end %>
<% end %>
</ul>
</p>
<p>
<%= link_to 'Attend Event', attend_event_path(@event.id), :method => :post %>
</p>
event_controller.rb
def attend
@event = Event.find(params[:id])
current_user.events << @event
redirect_to @event, notice: 'You are now attending this event'
end
def withdraw
event = Event.find(params[:id])
attendee = Attendee.find_by_user_id_and_event_id(current_user.id, event.id)
if attendee.blank?
redirect_to event
end
attendee.delete
redirect_to event, notice: 'You are no longer attending this event.'
end
当我调用 event->show 我得到这个错误
undefined local variable or method `withdraw_event_path' for #<#<Class:0x007fd5d575a910>:0x007fd5d22a72e0>
任何想法为什么路径不起作用?我是 Rails 新手
谢谢
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 path