开发者

Ruby on Rails - observe_field, rjs partial not displayed when editing main form

开发者 https://www.devze.com 2023-02-09 20:20 出处:网络
I am using observe_field to read a textfield and based on the value from that textfield, i am displaying a partial via rjs.

I am using observe_field to read a textfield and based on the value from that textfield, i am displaying a partial via rjs.

Main form code:

<%= f.text_field :playerId %>

<%= observe_field("submission_playerId", :frequency => 1,
:url => { :controller => 'submissions', :action => :display_player_name },
:with => "'id='+value") %>
<div id="span1"></div>

display_player_name.rjs:

page.replace_html "span1"开发者_如何学JAVA, :partial => "playerName"

_playerName.html.erb:

<p>Player Name: <%= @submission.player.playername %> </p>

The problem is that the partial 'playerName' is only rendered when i make a change to the textfield 'text_field :playerId'. If for example, i am editing the main form, the partial is not displayed unless i change the player id.

I want the partial to be displayed in the first place when i click on the edit button to edit the form, and not only when i change the playerId.

Is there a way of doing that?


Do this in the edit.rb code:

<%= render :partial => 'playerName' %>
0

精彩评论

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

关注公众号