0

So i have this link from a partial in a view:

<td><%= link_to 'Inscribir Ejemplares en la Carrera', home_carreras_path(@race, :meeting_id => meeting.id) %></td>

That link sends me to another view where two other partials are rendered.

The browser address looks like this:

http://0.0.0.0:3000/home/carreras?meeting_id=6

So you see that the value i sent from the link is there, and i want to pass that value, that number to one of the partials rendered in that view.

i haven't found how to do that, i searched a lot before asking. So please i hope someone here can help me. Thank you.

EDIT: ADDING MORE INFO

Controller:

class HomeController < ApplicationController
  def index
   render :layout => 'principal'
  end

  def carreras
   @meeting_id = params[:meeting_id]
   render :layout => 'principal'
  end
end

Not much action there :/

The Partial where the hidden field is:

<%= form_for(race) do |f| %>

   <ul>
    <% race.errors.full_messages.each do |msg| %>
      <li><%= msg %></li>
    <% end %>
   </ul>
 </div>
<% end %>

<div class="field">
  <%= f.hidden_field :meeting_id %><br />
</div>
<div class="field">
  <%= f.label :carrera_num %><br />
  <%= f.text_field :carrera_num %>
</div>
<div class="field">
  <%= f.label :caballo_num %><br />
  <%= f.text_field :caballo_num %>
</div>
<div class="field">
  <%= f.label :caballo_nombre %><br />
  <%= f.text_field :caballo_nombre %>
</div>
<div class="field">
  <%= f.label :distancia %><br />
  <%= f.text_field :distancia %>
</div>
<BR>
<div class="actions">
  <%= f.submit "Inscribir Ejemplar" %>
</div>
<% end %>
Saul
  • 69
  • 6

1 Answers1

1

If your controller actions for carreras, you can set an instance variable for the meeting_id.

def carreras
  @meeting_id = params[:meeting_id]

  # rest of controller action
end

@meeting_id will then be available to you throughout your rendered action.

You can supply your hidden_field tag with an options hash to set the value.

<%= hidden_field :meeting_id, value: @meeting_id %>

Zajn
  • 4,078
  • 24
  • 39
  • I have a hiddend field in the partial rendered in that view that is supposed to get that value. But it doesnt... do i have to pass that value in the render partial code? Something like this maybe: <%= render 'form_race', :race => Race.new(:meeting_id) %>... which doesnt work by the way – Saul Jun 05 '13 at 21:28
  • Can you add your controller action and the part of your partial where your hidden field is declared? – Zajn Jun 05 '13 at 21:30
  • Thank you!!! Cannot believe how simple and logical that was. But well im learning. Thank you for answering! – Saul Jun 05 '13 at 22:02