Note that there are some explanatory texts on larger screens.

plurals
  1. PORuby - Difference between :variable and @variable
    primarykey
    data
    text
    <p>As a Ruby on Rails newbie, I understand that the "@" and ":" references have different meanings. I saw <a href="https://stackoverflow.com/questions/3538575/whats-the-difference-between-and-variable-variable-and-vari">this post</a> in SO, which described some of the differences.</p> <ol> <li><strong>@</strong> indicates a instance variable (e.g., @my_selection)</li> <li><strong>:</strong> indicates an alias (e.g., :my_selection)</li> </ol> <p>I ran into a situation where I had a standard MVC page, similar to all of the other forms/pages in my webapp.</p> <p><em>html.erb snippet</em></p> <pre><code>&lt;%= form_for @my_selection do |f| %&gt; </code></pre> <p><em>route.rb snippet</em></p> <pre><code>resources :my_selections </code></pre> <p>When I attempt to access this page, I get this error:</p> <pre><code>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 #&lt;#&lt;Class:0x1197e5676&gt;:0x25439c3b&gt; </code></pre> <p>Line 16 is the form snippet shown above.</p> <p>All of my other forms/pages in the same web app are set up in exactly the same way and are working fine. However, once I changed the erb form reference to <strong>:my_selection</strong>, this error went away and my page behaved normally.</p> <p><strong>Questions:</strong> </p> <ol> <li>Is my understanding of the difference between :my_selections and @my_selections correct?</li> <li>Why would switching to :my_selection resolve my original error?</li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload