ruby - Render own partial via javascript in Rails -



ruby - Render own partial via javascript in Rails -

say there partial called _hello_world.html.erb

<% if toggle %> hello world on <%= link_to "turn off", what_should_come_here %> <% else %> hello world off <%= link_to "turn on", what_should_come_here %> <% end %>

intially partial called index file this,

<%= render :partial => 'test/hello_world', :locals => {:toggle => true} %>

but after click toggle link should switch between on , off states should render own partial 1 time again overriding previous partial. how ?

note: have given question in http://sscce.org/ format.

instead of link_to improve utilize link_to_remote

index.html.erb

<div id="toggle_div"> <%= render :partial => 'test/hello_world', :locals => {:toggle => @toggle} %> </div>

_hello_world.html.erb

<% if toggle %> hello world on <%= link_to_remote "turn off", my_action_path(:toggle => toggle) %> <% else %> hello world off <%= link_to_remote "turn on", my_action_path(:toggle => toggle) %> <% end %>

in action

def myaction value = params[:toggle] // toggle value @toggle = value == "true" ? false: true render :update |page| page.replace_html 'toggle_div', :partial => 'hello_world', :locals => {:toggle => @toggle} end end

ruby-on-rails ruby renderpartial

Comments

Popular posts from this blog

delphi - blogger via idHTTP : error 400 bad request -

c++ - compiler errors when initializing EXPECT_CALL with function which has program_options::variables_map as parameter -

How do I check if an insert was successful with MySQLdb in Python? -