access controller's object attributes in view page

Hi,

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".. Please help.. Please find my code below

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))      end end

In view page of index_admin

<%="Hi"%><%=params[:current_admin.name]%>

Hi,

See my comments inline: Regards, Seeni Rafiyullah Khan A, In Every moment, thank God.

Rafi A wrote in post #1076789:

Hi,

See my comments inline:

Regards, Seeni Rafiyullah Khan A, <srkhan@apigee.com>*In Every moment, thank God.*

You are trying to get the admin name from the symbol :frowning: and hence you are getting the issue.

In the controller, assign the resultant admin record to the instance variable as below:

*@admin=Admin.find_by_email(params[:session][:email].downcase)*

In your view page, use as below:

*<%="Hi"%><%= @admin.name%> * * *

HI,

I tried with the the below code. But still getting the same result in view page as "undefined method `name' for nil:NilClass"

def create    @admin=Admin.find_by_email(params[:session][:email].downcase)        user=User.find_by_email(params[:session][:email].downcase)      if user && user.authenticate(params[:session][:password])       redirect_to(dashboard_path(:user=>user))     else       redirect_to(admins_index_path(:current_admin=>@admin))     end   end

Regards,

Seeni Rafiyullah Khan A,

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