ruby on rails syntax- when does : come before v. after the variable? -


Perhaps obvious; I am very new to rail.

My question: Is there a rule or a simple way of remembering when a colon comes before or after a variable? An example of what I'm talking about with my application_controller .

  with protection_from_forgery :: exception   

I with : v. the : exceptions .

Is there a way to remember when the colon arrives at the end, and when it comes in the beginning, or is it something that you miss on a variable-to-variable basis? Besides, why have both been found here in a row?

I really want to understand this :) Thanks!

with: exception: syntax is only for : Together = & gt; : Exception

There is no real benefit other than the feature and less typing. If you need to continue supporting Ruby 1.8, then logic can be argued. You should continue to use the old syntax.

You must feel in the example provided

  protect_from_forgery:   

This is a method that passed single variable It is being done, which is going to be a hash. So are the following. with protection_from_forgery :: exception protection_from_forgery (with :: exception) protection_from_forgery (: with =>: exception) protection_from_forgery ({: with =>: exception})

As I have made progress in the line notice, this is a bit more typing, but they are all doing the same thing. Each passes through protection_from_forgery with the same key / price combination.

Going back to your original question of left vs right, just keep in mind that on the left is your key and this symbol is

The following examples are all valid hashes. Foo = {time: "baz"} foo = {time: 1} foo = {time :: baz} foo = {bar: some_object} < p> Then it is being felt that it is a shortcut for the symbol key to something, symbol, number, string, object, etc. ... it can change the old syntax {: bar = & gt; Some_thing}

If your key is something other than a symbol then you will need to use the old syntax.

  foo = {1 = & gt; : Bar} foo = {"string" = & gt; Some_object}    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -