Created
November 7, 2012 11:57
-
-
Save RemiBa/4031079 to your computer and use it in GitHub Desktop.
Retrieve associated errors in form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= form_for @customer do |c| %> | |
<% if @customer.errors.any? %> | |
<div class="form_errors"> | |
<ul> | |
<% @customer.errors.full_messages.each do |msg| %> | |
<li> | |
<%= msg %> | |
</li> | |
<%end%> | |
</ul> | |
</div> | |
<% end %> | |
<% if :authentication %> | |
<%= fields_for @customer.authentication do |a| %> | |
<%= a.label :password %> | |
<%= a.password_field :password %> | |
<br /> | |
<%= a.label :password_confirmation%> | |
<%= a.password_field :password_confirmation %> | |
<% end %> | |
<br /> | |
<% end %> | |
<%= c.submit "Save your changes"%> | |
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dbCustomer = Customer.find_by_id(params[:id]) | |
if dbCustomer.authentication | |
if dbCustomer.authentication.login_count == nil | |
#This is the first time entering the website after signup | |
success = dbCustomer.authentication.update_password(params[:authentication][:password],params[:authentication][:password_confirmation]) | |
if success[0] | |
dbCustomer.authentication.increment!(:login_count) | |
flash[:notice] = success[0][:message] | |
#redirect_to root_path | |
else | |
@customer = dbCustomer | |
render :action => :edit, :notice => "success.to_s" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h2>Please submit your personal password:</h2> | |
<form accept-charset="UTF-8" action="/customers/2110001" class="edit_customer" id="edit_customer_2110001" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /><input name="_method" type="hidden" value="put" /><input name="authenticity_token" type="hidden" value="LiCv6shHTr8gXVk/fNPmhGk2pJ2uUM2WmQ0mm0OWeLs=" /></div> | |
<div class="field_with_errors"><label for="authentication_password">Password</label></div> | |
<div class="field_with_errors"><input id="authentication_password" name="authentication[password]" size="30" type="password" /></div> | |
<br /> | |
<label for="authentication_password_confirmation">Password confirmation</label> | |
<input id="authentication_password_confirmation" name="authentication[password_confirmation]" size="30" type="password" /> | |
<br /> | |
<input name="commit" type="submit" value="Save your changes" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Problem:
When updating the password, it should give the a message what the error is... but it doenst give anything...
How do I display the authentication error?