ruby on rails - Why is a symbol used next to the word "to" in the code below? -
this question has answer here:
- ruby: colon before vs after [duplicate] 4 answers
coming php, not sure why symbol below used on right hand side of to.
get '/posts/new', to: 'posts#new'
is hash key , whats in quotes key?
been looking @ rails tutorials , never seen hash in kind of form wondering...
yes, correct, to:
hash key.
when hash last argument in list ruby allows forego use of curly braces.
perhaps clearer when add parentheses , curly braces:
get('/posts/new', { to: 'posts#new' })
that line calls get
method 2 arguments. first argument string '/posts/new'
. second 1 hash { to: 'posts#new' }
.
Comments
Post a Comment