Purpose of %w in ruby on rails -


i see in routes.rb this

%w( mission path standard getting_started welcome infection instruction implementation ).each |page|     page, to: "pages##{page}" end 

and when see home controller , doesn't have nay actions list above. link works properly.

i want know these lines of codes do?

%w( mission path standard getting_started welcome infection instruction implementation ).each |page|     page, to: "pages##{page}" end 

the code works like: %w(foo bar)is shortcut array["foo", "bar"]

.each |page|  

it loops each element such in 1st loop value of page = "foo"

get page, to: "pages##{page}" 

this line become

get foo, to: "pages#foo" 

when user hits /foo redirected foo action of pages controller, same other elements too.

thus, makes easy define routes elements in %w( )


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -