一个simple_form_for New和Edit方法

时间:2015-09-04 20:09:07

标签: ruby-on-rails haml simple-form-for

试图找到一种方法,将一个simple_form_for用于两个函数 - new和edit。

= 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')以及?

1 个答案:

答案 0 :(得分: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|

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