This is my code in
users_controller.rb
def index
@users = User.paginate(page: params[:page])
end
def show
@user = User.find_by id: params[:id]
return if @user
flash[:danger] = t("controllers.users_controller.failed")
redirect_to signup_path
end
def new
@user = User.new
end
def create
@user = User.new user_params
if @user.save
log_in @user
redirect_to @user
flash[:success] = I18n.t("controllers.users_controller.success")
else
render :new
end
end
And this ís my html: _form.html.erb
<%= form_for @user, url: yield(:url) do |f| %>
<%= render "shared/error_messages" %>
<%= f.label :name %>
<%= f.text_field :name, class: "form-control" %>
<%= f.label :email %>
<%= f.email_field :email, class: "form-control" %>
<%= f.label :password %>
<%= f.password_field :password, class: "form-control" %>
<%= f.label :password_confirmation, t(".confirm") %>
<%= f.password_field :password_confirmation, class: "form-control" %>
<%= f.submit yield(:button_text), class: "btn btn-primary" %>
<% end %>
And somebody help me know that why was the instance variable (@user) be in the form_for in html?
Aucun commentaire:
Enregistrer un commentaire