i have a problem with a form to create a user… this is my code of “new”
<%= form_for @user do |f| %>
<% if @user.errors.any? %>
<% for message in @user.errors.full_messages %>
<div class="alert">
<button type="button" class="close" data-dismiss="alert">×</button>
<%= message %>
</div>
<% end %>
<% end %>
<div class="field">
<%= f.label :username %>
<%= f.text_field :username %>
</div>
<div class="field">
<%= f.label :email %>
<%= f.text_field :email %>
</div>
<div class="field">
<%= f.label :password %>
<%= f.password_field :password %>
</div>
<div class="field">
<%= f.label :password_confirmation %>
<%= f.password_field :password_confirmation %>
</div>
<div class="actions"><%= f.submit "Registrarse" %></div>
<% end %>
and “create” in controller
def create
@user = User.new(params[user])
if @user.save
redirect_back_or_to root_url, :notice => "Usuario Registrado Satisfactoriamente!"
else
render :new, :notice => "No se ha podido registrar"
end
end
when i create the user, this go to login form, and a receive a message empty, because i have an “if” if i have message, this show me a div with some css, so i can see that an error ocurred, but this come empty, what i have wrong? i dont see anything… and of course, the user is not created.!
thanks for the help, i am a newbie in ruby. and sorry for my bad english xd
The problem is that you most likely are referencing
password_confirmationwhich is usually an input tag. You most likely do not have this field in your database as it would just be horrible practice. Are you salting your passwords?Check out sorcery on github and the Railscasts. It does a nice job on covering authentication.
Also, you need to use
:userin theparams=>User.new(params[:user])