Ruby on Rails - where to write business logic while processing a request? (newbie)

Posted by Genadinik on Stack Overflow See other posts from Stack Overflow or by Genadinik
Published on 2012-04-12T23:16:18Z Indexed on 2012/04/12 23:29 UTC
Read the original article Hit count: 248

Filed under:
|

I am learning Ruby on Rails. I made a simple link like this:

<%= link_to "Alex Link", alexes_path(@alex) %>

then I routed it in routes.rb like this:

  resources :alexes

  get "home/index"

then I am a bit unclear, but I think it goes to this part of the controller:

  def index
    #@alexes = Alex.all

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @alexes }
    end
  end

Am I correct that it goes to this part of the controller?

Then nothing much happens and it goes to the next page which is index.html.rb under views\alexes

So what I am wondering is - if I needed to do some business logic, would I write that in the controller snippet? Where inside the snippet? An example would be nice to take a look.

Also, I would like to connect to a MongoDb database. Would I also write that in the middle of the controller?

Thanks!

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby