Rails - Development - Creating a Registration Form

I hit my head against a wall trying to figure out how to get Devise to work with client registration ....

So, on my landing page, I want to show the registration form, so I added this to my opinion:

<%= render 'devise/registrations/new' %>

In this partial, I mean a form tag, for example:

<%= form_for(user_registration_path, :url => user_registration_path) do |f| %>
.
.

In my application layout I have:

<% flash.each do |key, value| %>
    <div class="flash <%= key %>"><%= value %></div>
<% end %>

The problem I am facing is when I submit a new registration form with invalid parameters, I don’t see an error message?

But if I submit valid information, the form says that it worked, and that I need to check my email address to confirm that it’s good.

Can you help me figure out how to get this working 2-end so that I can display errors:

Here is my full controller:

  # GET /users/new
  # GET /users/new.xml                                            
  # GET /users/new.json                                    HTML AND AJAX
  #-------------------------------------------------------------------
  def new
    respond_to do |format|
      format.json { render :json => @user }   
      format.xml  { render :xml => @user }
      format.html
    end
  end

  # GET /users/1/edit                                                      
  # GET /users/1/edit.xml                                                      
  # GET /users/1/edit.json                                HTML AND AJAX
  #-------------------------------------------------------------------
  def edit
    respond_to do |format|
      format.json { render :json => @user }   
      format.xml  { render :xml => @user }
      format.html
    end

  rescue ActiveRecord::RecordNotFound
    respond_to_not_found(:json, :xml, :html)
  end

  # POST /users
  # POST /users.xml         
  # POST /users.json                                      HTML AND AJAX
  #-----------------------------------------------------------------
  def create
    @user = User.new(params[:user])

    if @user.save
      respond_to do |format|
        format.json { render :json => @user.to_json, :status => 200 }
        format.xml  { head :ok }
        format.html { redirect_to :action => :index }
      end
    else
      respond_to do |format|
        format.json { render :text => "Could not create user", :status => :unprocessable_entity } # placeholder
        format.xml  { head :ok }
        format.html { render :action => :new, :status => :unprocessable_entity }
      end
    end
  end

Model:

  validates :fname, :presence => true, :length => { :minimum => 2 }
  validates :lname, :presence => true, :length => { :minimum => 2 }
  validates :password, :presence => true, :length => { :minimum => 6 }
  validates :email, :presence => true, :length => { :minimum => 6 }
+2
3

github readme: ", Devise -, , . Devise , " flash [: notice] "" flash [: alert] ", .

+1

<%= error_messages_for %>? .

, , :lname, :fname .. , .


Update

<%= f.error_messages_for :model %>

Rails 3 , , R3 , . .

0

, :

  <%= devise_error_messages! %>

, , , , . Btw, , , users#registrations_controller, , .

,

0

All Articles