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?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜