开发者

How to DRY up this conditional collection_select in form partial?

开发者 https://www.devze.com 2023-01-11 19:11 出处:网络
I have a form partial that is being called in a content_for :sideba开发者_JAVA技巧r. This collection_select should have \"selected\" set if the page calling the partial is a specific package page. Oth

I have a form partial that is being called in a content_for :sideba开发者_JAVA技巧r. This collection_select should have "selected" set if the page calling the partial is a specific package page. Otherwise, it should have a "prompt" to select. How would I DRY this up? I tried an inline ternary on a single collection_select to no avail.

<%- if @package.blank? -%>
    <%= f.collection_select :package_name, Package.all, :name, :name, :prompt => "Please Select"  %>
<%- else -%>
    <%= f.collection_select :package_name, Package.all, :name, :name, :selected => @package.name %>
<%- end -%>

Thanks


How about:

<%= f.collection_select :package_name, Package.all, :name, :name, 
      @package.blank? ? { :prompt => "Please Select" } : { :selected => @package.name } %>
0

精彩评论

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