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
Post a Comment