我有一个基本的应用程序,我正在尝试根据 meeting_id 和参与者 ID(它们是 meeting_participants 中的列)销毁名为 meeting_participants 的表中的记录。
我已经更改了 meeting_participants_controller 中的销毁操作,以接受 meeting_id 和参与者 ID,然后删除相应的记录。
def destroy
session[:return_to] = request.referer
@meeting_participant = MeetingParticipant.find_by_meeting_id_and_participant_id(params[:meeting_id], params[:participant_id])
@meeting_participant.destroy
redirect_to session[:return_to]
end
我在视图中有一个按钮,我想使用以下代码调用 meeting_participants#destroy 控制器。
<table>
<% @participants.each do |participant| %>
<tr>
<td><%= participant.name %></dt>
<td>
<% participant.meetings.each do |meeting| %>
<%= meeting.name %>
<%= button_to( "Remove Meeting",
{:controller => "meeting_participants",
:action => "destroy",
:meeting_id => meeting.id,
:participant_id => participant.id },
:method => :delete,
:confirm => "Are you sure?") %>
<br/>
<% end %>
</td>
</tr>
<% end %>
</table>
我认为我已成功将正确的参与者 ID 和会议 ID 参数发送到控制器,但我收到“无路由匹配”错误,因为我的 meeting_participants#destroy 路由需要一个 :id 参数。rake 路线给...
meeting_participant DELETE /meeting_participants/:id(.:format) meeting_participants#destroy
有谁知道改变我的路线以期望两个新参数而不是 id 的方法?或者也许有更好的方法。我发现路线非常混乱。
谢谢。
我的 routes.rb 文件是...
MyApp::Application.routes.draw do
resources :meeting_participants
resources :participants
resources :meetings
end