Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a modal dialog into Rails?

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?

like image 657
Rosh Avatar asked Jan 21 '26 18:01

Rosh


1 Answers

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 show click, you'll need to use show.js.erb to show your modal dialog rather than create.js.erb. create will only be called if you POST a form to /events whereas 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 a respond.js response in your show method on the controller, and try it again.

like image 59
Kristian PD Avatar answered Jan 24 '26 09:01

Kristian PD