A
A
Anton2016-11-16 00:14:19
Ruby on Rails
Anton, 2016-11-16 00:14:19

Am I creating custom routes correctly?

In general, there are many lines of this kind:

get 'home/section1'
get 'home/section2'

There are a lot of them and they all have a controller - Home, so I thought about optimization. Or is everything right?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anna Buyanova, 2016-11-16
@LightAlloy

It is possible like this:

%w(section1 section2).each do |action_name|
   get "/home/#{action_name}"
end

T
TyzhSysAdmin, 2016-11-16
@POS_troi

If you have "section1" ... "sectionN" functions in your controller, then yes.
I personally prefer to write it like this:
get 'home/section1' => 'home#FuncName'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question