Re: [Rails] access controller's object attributes in view page
On Thu, Sep 20, 2012 at 3:45 AM, ruby rails <lists@ruby-forum.com> wrote:
> I am new to ROR and learning it. In my controller I have an admins
> record and I am passing that admin object to the admin's view page to
> get the name of the admin. But when I try to access the name it is
> showing error as "undefined method `name' for :current_admin:Symbol"..
> Sessions Controller
>
> def create
> admin=Admin.find_by_email(params[:session][:email].downcase)
> if admin && admin.authenticate(params[:session][:password])
> redirect_to(admins_index_path(:current_admin=>admin))
Side note --
you probably want to pass that as (:current_admin_id=>admin.id)
You're doing a redirect, which means the request will be sent to the
controller and method associated with "admins_index_path".
In *that* controller and method, you must set the variables you need,
e.g. @admin = Admin.find(params[:current_admin_id]
Then your view can use attributes e.g. @admin.name
--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
http://about.me/hassanschroeder
twitter: @hassan
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home