javascript - Rails: Trying to render a partial on button click -


i trying render partial on button click nothing happens.
view:

 <div class ="container">    <span class ="center"><h1> title</h1>      <%= link_to "correct answer", correct_answer_courses_path, :remote => true %>      <%= link_to "false answer", false_answer_courses_path, :remote => true %>       <div id = "result">        <!-- div used render result -->      </div>    </span>  </div>  <%= render 'layouts/coursefooter' %> 

my controller (courses_controller)

def correct_answer   respond_to |format|                    format.js   end         end   def false_answer   respond_to |format|                    format.js   end         end  

correct_answer.js.erb (in courses folder)

$("#result").prepend('<%= escape_javascript(render :partial => "correct") %>'); 

my partial called _correct , located in courses folder. right when click nothing happens, no errors @ all.

i think help...

add div id correct_answer above result div , try in js.erb file :

$("#correct_answer").html("<%= j render partial: "correct", :locals => {:questionnumber => @questionnumber} %>"); 

and in controller set variable :

def correct_answer   @questionnumber = 2   respond_to |format|                    format.js   end         end  

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -