ajax - Rails js.erb response not sending locals to Haml partial -


i realize similar other questions, have been through fair number of , think i'm doing suggested, code still not working.

so, title says, i'm attempting load partial js.erb file (in response ajax call.) however, not working correctly.

full_list.html.haml:

=link_to(test_path(@work), id: "privacy-button", remote: true)     = render "privacy_button_content", locals: {:show_others => @work.show_others} 

_privacy_button_content.html.haml:

-if locals[:show_others] == false     -test_string = "twas false" -else     -test_string = "twas true" %p = test_string 

works_controller.rb:

 def test_function     @work.model_function    respond_with(:layout => false)  end 

test_function.js.erb:

$("#privacy-button").html("<%= escape_javascript render(:partial => 'privacy_button_content', locals: {:show_others => @work.show_others}) %>"); 

so full_list has privacy_button, rendering partial, , response clicking #privacy-button should modify in controller, , response.js.erb.

this works correctly on page load (so passing local partial work,) whenever run ajax call i'm getting

(undefined local variable or method `locals' #<#<class:0x00000005006338>:0x000000068481f8>): 

any appreciated.

update _privacy_button_content.html.haml below:

-if show_others == false       -test_string = "twas false" -else     -test_string = "twas true" %p = test_string 

when pass show_others in locals hash, local variable created named show_others. can access show_others in partial , not locals[:show_others].

refer passing local variables in rails guides.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -