我在index
和edit
中都使用了_form
。問題是,在index
中,它是一個遠程表單,在edit
中,我希望它是一個普通的表單。Rails:有條件的遠程表格
也許類似
= form_for post, remote: true if params[:action] != 'edit' , html: { class: 'post-form' } do |f|
我怎麼能這樣做?
我在index
和edit
中都使用了_form
。問題是,在index
中,它是一個遠程表單,在edit
中,我希望它是一個普通的表單。Rails:有條件的遠程表格
也許類似
= form_for post, remote: true if params[:action] != 'edit' , html: { class: 'post-form' } do |f|
我怎麼能這樣做?
這裏有一個稍微不同的語法:
= form_for post, remote: (action_name == 'index'), html: { class: 'post-form' } do |f|
您只需要remote: true
或remote: false
。
這是我結束了: 當調用
= 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|
嘗試這樣
= form_for post, ({ remote: true } if params[:action] == 'edit') do |f|
僅在索引和編輯頁面中定義'form_for',並在'_form'頁面中定義了form的內部主體..我之前嘗試過類似的東西.. – Sontya 2015-02-11 06:51:00