Topic: Dry or not Dry ...

I now try to put into practice the concept of Dry or not dry.

I have this is my controler :

  def new
   
    @clim = Clim.new
    @marees = Maree.find_all
    @meteos = Meteo.find_all
    @themodels = Themodel.find_all
   
   
  end

  def create
   
    @clim = Clim.new(params[:clim])
    @marees = Maree.find_all
    @meteos = Meteo.find_all
    @themodels = Themodel.find_all
   
    if @clim.save
      flash[:notice] = 'Clim was successfully created.'
      redirect_to :action => 'list'
    else
      render :action => 'new'
    end
  end


I feel that I could move all those find_all into my model, and this would make my application dryer. Am I correct ?

Re: Dry or not Dry ...

Since you are just doing find(:all) here, consider moving it into the view:

<% for mareo in Mareo.find(:all) %>
  ...
<% end %>

If the find gets anymoer complex, move it into the model and call that method in the view.

Alternatively you could move it into a before filter, but I think this is a better solution.

Railscasts - Free Ruby on Rails Screencasts

Re: Dry or not Dry ...

Thanks a lot.

For the poeple who are going to read this post and who are wondering how to move to Model, I should advertise one of your tutorials at this adresse :

http://www.tutorialized.com/view/tutori … odel/19056