0

试图找到一种方法将一个 simple_form_for 用于两个功能——新建和编辑。

= simple_form_for @news_item, :url => url_for(:action => 'create', :controller => 'news_items'), :method => 'post' do |f| = f.input :title, input_html: { class: 'title-input' } = f.input :contents, input_html: { class: 'contents-input' } .actions = f.submit 'Save', class: 'btn btn-success'

目前,每次点击提交按钮时,此表单都会创建新表单,但我也可以将其发送到 :url => url_for(:action => 'update') 吗?

4

1 回答 1

0

尝试这个:

= simple_form_for @news_item, url: (@news_item.new_record? ? news_items_index_path(@news_item) : news_items_path(@news_item)), method: (@news_item.new_record? ? :post : :patch) do |f|

或者类似的东西,你得到图片......

于 2015-09-04T20:23:51.447 回答