我使用Rails 5.1并拥有此代码段。 我怎样才能重构它以使其更具可读性?
在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 %>
答案 0 :(得分:1)
您可以使用三元运算符
<%= 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) %>