Note that there are some explanatory texts on larger screens.

plurals
  1. POChange a route to a controller
    primarykey
    data
    text
    <p>I have a basic app and I'm trying to destroy a record in a table called meeting_participants based on both the meeting_id and participant_id (which are columns in meeting_participants).</p> <p>I have changed the destroy action in my meeting_participants_controller, to accept the meeting_id and participant_id and then delete the appropriate record.</p> <pre><code>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 </code></pre> <p>I have a button in a view I would like to use to call the meeting_participants#destroy controller, using the following code.</p> <pre><code>&lt;table&gt; &lt;% @participants.each do |participant| %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= participant.name %&gt;&lt;/dt&gt; &lt;td&gt; &lt;% participant.meetings.each do |meeting| %&gt; &lt;%= meeting.name %&gt; &lt;%= button_to( "Remove Meeting", {:controller =&gt; "meeting_participants", :action =&gt; "destroy", :meeting_id =&gt; meeting.id, :participant_id =&gt; participant.id }, :method =&gt; :delete, :confirm =&gt; "Are you sure?") %&gt; &lt;br/&gt; &lt;% end %&gt; &lt;/td&gt; &lt;/tr&gt; &lt;% end %&gt; &lt;/table&gt; </code></pre> <p>I think that I am successfully sending the correct participant_id and meeting_id parameters to the controller but I am getting a "No route matches" error because my route for meeting_participants#destroy is expecting a single :id parameter instead. rake routes gives...</p> <pre><code>meeting_participant DELETE /meeting_participants/:id(.:format) meeting_participants#destroy </code></pre> <p>Does anyone know of a way to change my route to expect the two new parameters instead of id? Or maybe there is a better approach altogether. I find routes very confusing.</p> <p>Thanks.</p> <p>My routes.rb files is...</p> <pre><code>MyApp::Application.routes.draw do resources :meeting_participants resources :participants resources :meetings end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload