开发者

Dynamically updating belongs_to select field in Rails form

In a Rails3 app I have a Site model, which belongs to a Region model, which in turn belongs to a Country.

On the site form I currently have a select field for Region, which is populated from the Region model.

I would like users to be able to dynamically update this list. I have tried to implement a Facebox modal popup form for the Region modal, following this tutorial http://slawosz.github.com/2011/04/26/add-new-resource-with-ajax/. However I've run into a problem.

When I click the "add new" link, the popup form does not display. When I examine what's happening in Firebug, I can see that a GET command is called to the correct URL, and in the response tab the correct HTML is displayed. Nonetheless no popup form is displayed.

This may be a very simple question (I'm still learning my way) but what would prevent this from rendering if the HTML is being called.

A second issue is that the HTML is for the full page (i.e. application layout, headers, footers, etc) when I only need the form partial to display. In new.js.erb I have the following code for rendering:

$.facebox('<%= escape_javascript(render :template => 'divesites/new.html, :layout => nil') %>'); 

Apart from the addition of the layout => new my relevant code for this is identical to the tutorial above. Please let me know if I should provide any more excerpts from my code here.

I'd be grateful for any suggestions as to how to resolve this issue. Or if there are other easier ways to update a parent model dynamically I开发者_如何学JAVA'd welcome your suggestions and pointers to useful information.

Thanks


Not sure about the other stuff, but for the layout question, try

:layout => false
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜