Creation of a Select in a View I have the following code in a VIEW:

&lt;select name="selected_budget_mode" class="" onchange="OnBudgetModeChanged(this)"&gt;
&lt;option value="0"
        &lt;% if params[:current_budget_mode].to_i == 0 %&gt;selected
        &lt;% end %&gt;&gt;&lt;%= show_budget_mode(0) %&gt;&lt;/option&gt;
&lt;option value="1"
        &lt;% if params[:current_budget_mode].to_i == 1 %&gt;selected
        &lt;% end %&gt;&gt;&lt;%= show_budget_mode(1) %&gt;&lt;/option&gt;
&lt;option value="2"
        &lt;% if params[:current_budget_mode].to_i == 2 %&gt;selected
        &lt;% end %&gt;&gt;&lt;%= show_budget_mode(2) %&gt;&lt;/option&gt;
&lt;/select&gt;


I am aware of the select_tag and the options_for_select form helpers, but that implies that I need to create a list with the options and then pass it to the options_for_select.

The budgets_mode are not dynamic. They don't come from calling a service or other function, there are only 3 modes.

What would be the best approach to simplify this code and make it as readable as possible?
You could still use options_for_select without much hassle:

&lt;%= options_for_select (0..2).map { |i| [show_budget_mode(i), i] }, params[:current_budget_mode].to_i %&gt;


Of course, I'd recommend creating the array in the controller or a helper, rather than the view. The view should ideally do as little logic as possible.

Alternatively, you could use content_tag just the keep the code cleaner:

&lt;% (0..2).each do |i| %&gt;
  &lt;%= content_tag :option, show_budget_mode(i), selected: params[:current_budget_mode].to_i == i %&gt;
&lt;% end %&gt;


Again, I'd recommend moving stuff to the controller. Even a current_budget_mode helper method would help clean things up:

class SomeController &lt; ActionController
  helper_method :current_budget_mode, :budget_modes

  def current_budget_mode
    params[:current_budget_mode].to_i
  end

  def budget_modes
    (0..2).to_a
  end
end


which would clean up the view:

&lt;% budget_modes.each do |i| %&gt;
  &lt;%= content_tag :option, show_budget_mode(i), selected: current_budget_mode == i %&gt;
&lt;% end %&gt;


or

&lt;%= options_for_select budget_modes.map { |i| [show_budget_mode(i), i] }, current_budget_mode %&gt;