Question

I have a form partial that is being called in a content_for :sidebar. 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

Was it helpful?

Solution

How about:

<%= f.collection_select :package_name, Package.all, :name, :name, 
      @package.blank? ? { :prompt => "Please Select" } : { :selected => @package.name } %>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top