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.

2
  • We can't possibly help you without seeing relevant code that is giving you trouble. Commented Jan 10, 2013 at 12:39
  • My code is same as with this tutorial's code: railscasts.com/episodes/… But in that tutorial all of the answers are shown for corresponding question. Commented Jan 10, 2013 at 12:52

1 Answer 1

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
   }
}
Sign up to request clarification or add additional context in comments.

2 Comments

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.
Well, are you using a javascript to do that? if yes, then the $("#form_id").attr("player_id").val holds the player_id val

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.