true\" when it\'s updating a record, but not when creating a new one." />
开发者

How to make "form_for" use "remote => true" based on condition?

开发者 https://www.devze.com 2023-03-22 09:37 出处:网络
I have a form that shoul开发者_如何学God use \"remote => true\" when it\'s updating a record, but not when creating a new one.

I have a form that shoul开发者_如何学God use "remote => true" when it's updating a record, but not when creating a new one.

I tried:

<%= form_for position position.new_record? ? (, :remote => true do) |p| %>

syntax error...


To fix your example:

<%= form_for position, (position.new_record? ? {} : {:remote => true}) do |p| %>

But to make it a bit nicer you could do this:

<%= form_for position, :remote => position.new_record? do |p| %>
0

精彩评论

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