开发者

Ruby on Rails: load different partial with radio buttons

I want to load different partials with generated content into a form with ajax.

So how do i make this work?

For example, i have a form with the radio buttons "fruits" and "vegetablles", so when i select one of them, the corresponding partial should be loaded directly into the template dynamically with the right content.

Its a simple form created with scaffolding (edit, show, destroy) should be prototype norma开发者_StackOverflow社区lly?


All you do is :

In your controller, you should have the following methods:

def fruits
  @myfruit = Fruit.new # what you want!
  respond_to do |format|
    format.js
  end
end

Then, you should have your fruit.js.erb corresponding to that action (suppose you have jQuery here) :

$("#fruits-holder").replaceWith('<%= escape_javascript(render @myfruit) %>');

You then need a partial view like _fruit.html.erb that contains the html you want

As Codeglot stated, if you want more precise answer, post more information about your problem. I cannot be more specific right now.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜