简体   繁体   中英

Conditional options for Rails methods?

I want to add a class to a form_for method, but how would I do that?

<% if @plan.price == 0 %>
   <%= form_for @account, :html => { :class => 'new_account' } do |f| %>
<% else %>
   <%= form_for @account, :html => { :class => 'new_account payment-form' } do |f| %>
<% end %>

Seems there's gotta be a more concise way to pull that off.

您可以这样做:

<%= form_for @account, html: { class: "new_account #{(@plan.price == 0) ? '' : 'payment-form'}" } do |f| %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM