2
I’m learning Rails, following a book that has the following code:
Usercontroller
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
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) %>
In fact the book only goes up to the code edit_user_path
, but I wanted to do some tests and I don’t understand why when I use thehow_user_path
it says that the method does not exist instead of returning the same user, when trading for only
<%= link_to 'Mostrar Perfil', @user %>
the code works, but I’d like to know why with the show_user_path
it returns an error and the method obviously exists in the controller, my goal would be to show the profile that was created.
What is the exact error message? (including the file and the line)
– Guilherme Bernal
But you want to show the profile from which view? You didn’t use scaffold?
– Jefferson Alison