简体   繁体   中英

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 (ie 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'd welcome your suggestions and pointers to useful information.

Thanks

不确定其他内容,但是对于布局问题,请尝试

:layout => false

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM