Reputation: 665
I use Rails 5.1 and have this code snippet. How can I refactor it to make it more readable?
In views/imagecapturings/index.html.erb
<% if params.has_key?(:select) %>
<%= link_to 'St. Gallen', digitized_in_stgallen_imagecapturings_path('select[year]' => params[:select][:year], 'select[month]' => params[:select][:month]) %>
<% else %>
<%= link_to 'St. Gallen', action: "digitized_in_stgallen", method: :get %>
<% end %>
Upvotes: 0
Views: 17
Reputation: 2384
You could use ternary operator
<%= params.has_key?(:select) ?
link_to('St. Gallen', digitized_in_stgallen_imagecapturings_path('select[year]' => params[:select][:year], 'select[month]' => params[:select][:month])) :
link_to('St. Gallen', action: "digitized_in_stgallen", method: :get) %>
Upvotes: 1