How to DRY up this conditional collection_select in form partial?
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 } %>
精彩评论