Hi Alfredo,
the error is that the `user` variable doesn't exist, maybe you mean `@user`?
You can try without the user variable and it should work:

    <%= button_to 'Add Photo' , home_add_path(user_id: 1) %>

About how to call a method from a view (which is a different question),
just call it:

<% method_name %>

The method must be in the right scope. As an example you can call methods
defined in the helper files.
If you define instance variables (variables starting with @) in the
controller, you can use them from the relative view (and call their public
methods):

class UsersController < ApplicationController
  def index
    @user = User.first
  end
end

# app/views/users/index.html.erb

User name: <%= @user.full_name %>

ok?


2014-04-10 6:38 GMT+02:00 Alfredo Barrero <[email protected]>:

> Any idea of the issues?.
>
> Thanks a lot.
>
>
>
> El martes, 4 de marzo de 2014 03:57:19 UTC+8, Alfredo Barrero escribió:
>>
>> Good night everyone,
>>
>> My name is Alfredo Barrero and I'm getting started with RoR. I have been
>> learning with "Agile Web Development".
>>
>> Now I'm trying to do my own web application. I have a problem and I don't
>> know what I'm doing wrong, could you please give me a hand?.
>>
>> This is what I'm trying to do:
>>
>> <%= button_to 'Add Photo' , home_add_path(user_id: user) %>
>>
>> I have this line on "routes.rb" => get '/home/add' => 'photos#add', but
>> the browser gives me this error
>>
>> undefined local variable or method `user' for 
>> #<#<Class:0x007fe075485dc0>:0x007fe0738e8d38>
>>
>> The question is, how can I call a method from a html.erb?.
>>
>>
>> Thank you so much, best regards.
>>
>> Alfredo.
>>
>>  --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rubyonrails-talk/b55b07ec-61e6-4b3c-95da-70ae99f22106%40googlegroups.com<https://groups.google.com/d/msgid/rubyonrails-talk/b55b07ec-61e6-4b3c-95da-70ae99f22106%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/CAK4fz2osXN7dC%2ByJABRU%2B_PDwHbucr9daPDxux2cUftG3560Kg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to