Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 轨道退出事件路径';未定义的局部方法';_Ruby On Rails_Ruby On Rails 3_Path - Fatal编程技术网

Ruby on rails 轨道退出事件路径';未定义的局部方法';

Ruby on rails 轨道退出事件路径';未定义的局部方法';,ruby-on-rails,ruby-on-rails-3,path,Ruby On Rails,Ruby On Rails 3,Path,我找到了解决我一个问题的好办法 我已经把它构建到我自己的项目中,但我似乎不能称之为撤回事件 show.html.erb <p><strong>Attendees: </strong> <ul> <% for attendee in @event.users %> <% if attendee.id == current_user.id %> <li><stro

我找到了解决我一个问题的好办法

我已经把它构建到我自己的项目中,但我似乎不能称之为撤回事件

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>
与会者:
  • :post,:class=>“btn btn危险”%>

:post%>

事件控制器.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
def出席
@event=event.find(参数[:id])
当前_user.events显示我收到此错误

undefined local variable or method `withdraw_event_path' for #<#<Class:0x007fd5d575a910>:0x007fd5d22a72e0>
未定义的局部变量或方法“撤回事件路径”#
知道这条路为什么不起作用吗?我不熟悉rails


谢谢

您需要向路由中添加
draw
,这将创建方法
draw\u event\u path

resources :events do
  member do 
    post 'withdraw'
  end
end