Reputation: 669
I am a begginer in Rails, im following code from a book and i am trying stuff to see if it breaks/works, anyway heres my UserControllers classUserController
class UsersController < ApplicationController
def new
@user = User.new
end
def edit
@user = User.find(params[:id])
end
def show
@user = User.find(params[:id])
end
def create
@user = User.new(params[:user])
if @user.save
redirect_to @user, :notice => 'Cadastro realizado'
else
render :new
end
end
end
And heres my show.html.erb
<p id="notice"><%=notice%></p>
<h2>Perfil: <%[email protected]_name %></h2>
<ul>
<li>Localização: <%= @user.location %> </li>
<li>Bio: <%= @user.bio %></li>
</ul>
<%= link_to 'Editar Perfil', edit_user_path(@user) %>
<%= link_to 'Mostrar Perfil', show_user_path(@user) %>
My problem is in the last line, when i try to acess this page i get a NomethodError,i am trying to understand why, why can i just change that to @user and the page works?
Upvotes: 0
Views: 361
Reputation: 5767
Try:
<%= link_to 'Mostrar Perfil', user_path(@user) %>
or even just
<%= link_to 'Mostrar Perfil', @user %>
In order to see how to name the routes, open a console and run
rake routes
Upvotes: 3