开发者

ajax - update listbox in parent form

I have a form where user can create a player and also associate a team with the it. The player form has a select list where user can select an existing team or select the 'new' option which displays a popup which allows user to create a new team and associate it with the player.

I have used javascript to display the popup window when user selects 'new' option.

My new team form is as follows:

<% form_remote_tag :url => {:controller => 'players', :action => 'createTeam'} do %>
    <label style="width: 150px">Team name:</label> <%= text_field_tag(:team_name, nil) %>
    <%= submit_tag("Create New Team") %>
<% end %>

controller - players, action - createTeam

def createTeam
  @team = Team.create(:team_name => params[:team_name])

  respond_to do |format|
  if @team.save
    flash[:notice] = 'Team was success开发者_如何学Pythonfully created'
    format.html { redirect_to teams_path }
    format.js
  else
    flash[:notice] = "Team failed to save."
    format.html { redirect_to teams_path }
  end

  end
end

I would like to be able to update the select list in my parent form (new.html.erb for player) dynamically each time i add a team.

I am a bit confused on how to do this.

I would be grateful if someone could give me an idea on how to go forward.

Many many thanks for any suggestion provided.


You'll need to use something like replace_html to re-render the list. This SO question should help you out.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜