I all comes down to the context where the code is executed. Rails console context (self) is the "main" object, while, in the view, the context is the view class which includes a lot of helpers.
The main object on the console has an "app" method, a "helpers" methods, etc, but the view class does not (it includes some methods on itself). That's why you can't call "app.something" on the view, there's no "app".
The case of the object as an argument is similar, link_to, under th hoods, uses "url_for", if you do app.url_for(@z) on the console you'll get the url but link_to is running on a different context (you are calling "helper.link_to", not just "link_to").
They are just different context with different available methods (check self.methods on both the console and when rendering a view an you'll see it's really diferent)
El mar., 16 abr. 2019 a las 0:22, Robert Phillips (<[hidden email]>) escribió:
I have a question about using link_to in template and in console
Say I do rails new blah, I make a model called User, I make a table users, each user has a field called 'name'. I have resources :users, in config/routes.rb And I add some users.
in template, I can do
<% @z=User.find_by(name:"bob") %>
<%= link_to 'aaa',@z %>
I understand that it will take that variable @z which is a reference to a user, and will convert it to user_path(@z.id)