I am trying to set up a show page for a list of people in Rails 5, but having trouble getting the routes to sync.
config.route:
get '/team', to: 'pages#team'
get '/team/:id', to: 'pages#show', as: 'agent' #to get agent_path from rails routes
page_controller:
def team
@admins = Admin.where(role: :staff)
end
def show
@admins = Admin.find(params[:id])
end
views/pages/team.html.erb:
<% @admins.each do |staff| %>
<div class="team-link__inner">
<div class="agent-image-team">
<%= link_to (image_tag(staff.url, class: "team_link") agent_path(staff.id), class: "team-link") %>
</div>
<div class="hover-team-info">
<p><%= staff.name %></p>
</div>
</div>
<% end %>
views/pages/show.html.erb: (sample to confirm routes)
<h1>Admin show page</h1>
<%@admins.each do |staff| %>
<p><% staff.name %></p>
<% end %>
I've tried connecting my show pages up in a number of different ways, but keep getting errors when I try to set up my link in the index (team) view. What am I doing wrong?
errors are:
.../app/views/pages/team.html.erb:26: syntax error, unexpected tIDENTIFIER, expecting ')' class: "team_link") agent_path(staff.id), class: "team-link" ^
.../app/views/pages/team.html.erb:26: syntax error, unexpected ',', expecting ')' m_link") agent_path(staff.id), class: "team-link") );@output ^
.../app/views/pages/team.html.erb:26: syntax error, unexpected ')', expecting keyword_end aff.id), class: "team-link") );@output_buffer.safe_append=' ^
.../app/views/pages/team.html.erb:60: syntax error, unexpected keyword_ensure, expecting end-of-input ensure ^
You declaration of link_to is the problem. Try:
<%= link_to agent_path(staff.id), class: "team-link" do %>
<%= image_tag staff.url, class: "team_link" %>
# or
<img src="#{staff.url}" class="team_link" />
<% end %>
Hope it'll solve the errors!