Ruby - Difference between: variable and @variable

As a newbie to Ruby on Rails, I understand that the "@" and ":" links have different meanings. I saw this post in SO, which describes some of the differences.

  • @ indicates an instance variable (e.g. @my_selection)
  • : indicates an alias (e.g.: my_selection)

I came across a situation where I had a standard MVC page, similar to all other forms / pages in my web application.

html.erb snippet

<%= form_for @my_selection do |f| %>

route.rb snippet

resources :my_selections

When I try to access this page, I get this error:

NoMethodError in selections#create
Showing C:/somedir/myapp/app/views/my_selections/index.html.erb where line #16 raised:
undefined method `my_selection_index_path' for #<#<Class:0x1197e5676>:0x25439c3b>

Line 16 is the fragment of the form shown above.

/ - . , erb : my_selection, , .

:

  • : my_selections @my_selections?
  • : my_selection ?
+5
1

: my_selections @my_selections ?

: (

: , - . , -.

, Rails api , :

self.instance_variable_get "@#{my_symbol}"

.

, , , , , API, . , , .

: my_selection ?

for_form(model_instance) , create, , , .

. , @my_selection, , , .

resources :my_selections

, :

my_selections_path

my_selection_index_path , .

, ivar, . , my_selections_path, , .

+13

All Articles