Search code examples
ruby-on-railsdatabasecontrollerrails-activerecordseeding

Show page failing to pass seed data along (rails)


I have a seed database that renders Admin user information and links to individual member profile pages. The database renders images and data fine in the main page, but comes up nil <p>, with id </p> *== $0* when I try to call the individual objects on the show page.

routes.rb:

get '/team', to: 'pages#team'
get '/team/:id', to: 'pages#show', as: 'agent'

pages_controller.rb:

 def team
    @admins = Admin.where(role: :staff)
  end

  def show
    @admin = Admin.find(params[:id])
  end

views/pages/team.html.erb:

 <%= link_to agent_path(agent.id), class:"team-link" do %>
  .....
 <% end %> (all working, routes stable)

views/pages/show.html.erb:

<p><% @admin.name %>, with id <% @admin.id %></p>  
#rendering == $0

Where's the data connection breaking down? I've been working at this for a day or so now and this is a fairly solid wall for me.


Solution

  • Ah, your ERB statements are a bit off. You need to use the <%= %> format for the output of your ruby code to be shown (note the =).

    So <% @admin.name %> should be <%= @admin.name %>, etc.