开发者

Add a modal dialog into Rails?

开发者 https://www.devze.com 2023-04-01 07:09 出处:网络
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 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 hi开发者_StackOverflowdden 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 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.


Could be possible that you didnt install Jquery since the rails default is Prototype library. I would upgrade to Rails 3.1 which makes it easy to use jquery:

rails new example -j jquery

or install jquery: http://railscasts.com/episodes/136-jquery

0

精彩评论

暂无评论...
验证码 换一张
取 消