Rails alternative to including an active record call in a view

I have a partial form that looks like this:

<%= form_for(@pool) do |f| %>
  <div class="field">
    <%= f.label :name %><br />
    <%= f.text_field :name %>
  </div>
  <div class="field">
    <%= f.label :tournament %><br />
    <%= f.collection_select :tournament_id, Tournament.active, :id, :name, :prompt => true %>
  </div>

  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

This is like code smell because the view should not be responsible for knowing how to get the data for the tag <select>. An alternative to assigning a controller to an instance variable is problematic, because I have to replicate this code in several steps depending on whether this form has been rendered.

In ASP.NET MVC, I simply pulled this field into a partial view and displayed it with a call RenderActionthat would evaluate the overall action of the controller. However, in Rails render :action => '/view', it seems that only duplicate views are allowed. I'm new to Rails, so I'm not sure what the best practices are.

+3
2

, coder_tim, , , .

, , before_filter, , :

before_filter :get_active_tournaments, :only => [:new, :edit]

.

, .

+2

:) . = = .

, , , , . .

0

All Articles