Hello, please tell me how you can pass the parameter via link_to. Found here on the site examples, but I did not. The task is as follows: There is a calendar, there are links to sessions with the specified session time:

<% session_time = SessionTime.find(id = @time_id).session_time %> <li><%= link_to session_time, film_session, { :session_time => session_time } %></li> 

In the controller I catch:

 @session_time = params[:session_time] 

But if I try to display the parameter value in the console, I get an empty string.

  • So, what markup is generated as a result? In the documentation glanced? - D-side
  • This is what is generated by <a session_time="9.00" href="/film_sessions/1"> 9.00 </a>. I look in documentation, but does not leave to find the decision. - Maxim Cherevatov
  • <% puts params [: session_time] .inspect%> - gives nil - Maxim Cherevatov
  • So you see somewhere in the link indication session_time ? - D-side
  • Please rephrase the question, I do not quite understand what it is) In my understanding in the first line I get a variable with a specific value. Next, in the link I create a parameter with the name: session_time and pass it the value of this variable. Further in the controller I accept this parameter. Maybe I do not understand correctly how it works? - Maxim Cherevatov 2:53 pm

1 answer 1

The problem was solved this way:

 <li> <%= link_to session_time, film_session_path (:session_time=>session_time,:day=>date, :id=>film_session.id) %> </li> 
  • I recommend to read the documentation for url_for , and not to fence such horrors. - D-side
  • @ D-side I will read documentation, thanks. But there is a solution here at stackoverflow.com/questions/2124862/… and judging by the number of positive evaluations, I suggested that it fits. - Maxim Cherevatov
  • There is no interpolation, the link is hardcoded. Interpolation of an arbitrary string requires screening. - D-side
  • Tell me, is it better? <li> <% = link_to session_time, film_session_path (: session_time => session_time,: day => date,: id => film_session.id)%> </ li> - Maxim Cherevatov
  • Yes, much, the above mentioned jamb corrects it. But you can still a little easier :) The model can be inserted with the first argument without the key. Link, ultimately, to her page. - D-side