2015-02-11 28 views
2

我在indexedit中都使用了_form。問題是,在index中,它是一個遠程表單,在edit中,我希望它是一個普通的表單。Rails:有條件的遠程表格

也許類似

= form_for post, remote: true if params[:action] != 'edit' , html: { class: 'post-form' } do |f| 

我怎麼能這樣做?

+0

僅在索引和編輯頁面中定義'form_for',並在'_form'頁面中定義了form的內部主體..我之前嘗試過類似的東西.. – Sontya 2015-02-11 06:51:00

回答

1

這裏有一個稍微不同的語法:

= form_for post, remote: (action_name == 'index'), html: { class: 'post-form' } do |f| 

您只需要remote: trueremote: false

0

這是我結束了: 當調用

= render 'posts/form', post: @post, remote_control: false 

而且在_form

- remote_control = true if remote_control.nil? 
= form_for post, remote: remote_control , html: { class: 'post-form' } do |f| 
0

嘗試這樣

= form_for post, ({ remote: true } if params[:action] == 'edit') do |f|