There is a Session model with a One-to-Many relationship with Suggestions , i.e. offers. The session has a lot of suggestions. Made a separate page list_sug.html.haml , in which there is a list of all the proposals for this session. Made for convenience. But I can not get on this page. In routes.rb registered:

 resources :sessions do get :list_sug end 

In show.html.haml added the following line to session :

= link_to session_list_sug_url(:session_id => @session.id)

In the controller added:

 def list_sug @session = Session.find(params[:session_id]) end 

And the problem is that on the session page below the link is lit

 http://127.0.0.1:3000/sessions/2/list_sug 

at the same time, if you hover / click on it, it goes to /sessions/2 , and if you manually enter the above link, it gets to the desired page with suggestions. Why is this happening and how can it be corrected?

    2 answers 2

    In routes:

     resources :sessions do member {get :list_sug} end 

    Link:

     = link_to 'Посмотреть список, например', session_list_sug_path(@session) 

    Controller action:

     def list_sug @session = Session.find(params[:id]) end 

    About member here

      Total, symptom: in the text of the link you got the correct route, but in the address something is not right.

      And now how it happened. link_to (if you forget about the second hash) has two forms of invocation.

      1. Without a block ( text, *url_args ), where the first argument is the text of the link, and all subsequent url_for fed
      2. With a block ( *url_args, &block ), where all arguments (except for the block) are passed to url_for , and the output from the block becomes the contents of the <a> tag

      And you have a very funny situation. You used the first form . And url_for received an empty list of arguments ( [] ), that is, an instruction to take all the default parameters , and they are taken ... from the current page . Oh oh!

      Give him the contents of the link and everything will be in place. In either of two ways:

       = link_to "Предложения", путь = link_to путь do %i.fa.fa-list- # Произвольная разметка, для примера значок из FontAwesome