I want to add a Ajax link into my application. When I click on the link it should pop up a modal dialog which contains event’s details..
I add this link in my helper class.
link_to(event.name, events_path(@event), :remote => true
Then I create js file to insert content into hidden div.
$('.modal').html(<%= escape_javascript(render(@event)) %>);
$('.modal').dialog();
In here modal is my hidden div. But it could not pop up any modal dialog. I cannot understand what is the error and why is it not working. Plz can anybody help me to correct this?
Change
$('.modal').html(<%= escape_javascript(render(@event)) %>);to
$('.modal').html("<%= escape_javascript(render(@event)) %>");From a JS point of view, your code will be invalid because you’re not wrapping your render in quotes and it will try to evaluate your HTML.
EDIT
If you’re trying to link to this on a
showclick, you’ll need to useshow.js.erbto show your modal dialog rather thancreate.js.erb.createwill only be called if youPOSTa form to/eventswhereas here it looks like you’re trying to show just the details of the event.Put the code above (with quotes) in the
show.js.erb, make sure you have arespond.jsresponse in yourshowmethod on the controller, and try it again.