Ruby on Rails - where to write business logic while processing a request? (newbie)
- by Genadinik
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!