0

I've to modals teams and players, and as usual team has many players.

In teams' show page, I'm showing the players and so on. (I've followed railscasts.com/episodes/196-nested-model-form-part-1 tutorial.)

My problem is, when I click on the player's name in team show page, I would like to show team's edit form but with only clicked player's data in it. In current case, I have huge form which has all players' information.

That would be great if you can help me.

Thanks.

CanCeylan
  • 2,890
  • 8
  • 41
  • 51
  • We can't possibly help you without seeing relevant code that is giving you trouble. – deefour Jan 10 '13 at 12:39
  • My code is same as with this tutorial's code: http://railscasts.com/episodes/196-nested-model-form-part-1?view=asciicast But in that tutorial all of the answers are shown for corresponding question. – CanCeylan Jan 10 '13 at 12:52

1 Answers1

1

You could put a hidden_field in your team form that passes the player_id to the controller as a parameter when submitted.

In the controller you could then perform a search only for the params[:player_id] and change your view s you display that.

In your form:

<%= form_for .... do |f| %>
  <%= f.hidden_field 'player_id', value: player.id %>
  ...
<% end %>

In your controller:

if(params[:player_id])
   @information = Information.find_by_user_id(params[:player_id].to_i)
end

And, finally, in your view, you can display the @information variable as you wish.

If you dont want to submit to your controller write a javascript program:

$(document).ready( function () {
   $(".team_form").live("click", function() {
       $(this).attr("player_id").val //holds the player_id
       //load the other form using the player_id
   }
}
John Furtado
  • 555
  • 2
  • 9
  • But when I click on anyplayer, I'm not submitting any form. I want a new form to be opened with clicked player's information in it. – CanCeylan Jan 10 '13 at 12:51
  • Well, are you using a javascript to do that? if yes, then the `$("#form_id").attr("player_id").val` holds the player_id val – John Furtado Jan 10 '13 at 13:07