开发者

Rails 3: Problem with Devise

I am a Ruby beginner and I'm looking for some help about Devise.

My problem is with the form for a new user.

I created a user with the Devise view "sign_up" and then I'm redirected to the index of my user class.

If I click on the link "New User" I get the form but without fields for email and password. So I add these 2 fields but then my new user does not exist, it doesn't been added to the database.

Does anyone have a solution to this problem?

UPDATE:

Yes I read the tutorial on github.

I've make:

rails g devise:install
rails g devise User

and I've migrated one table User with original and Devise attributs

#user_controller.rb
class UsersController < ApplicationController
before_filter :authenticate_user!

# GET /users
# GET /users.xml
def index
  @users = User.all

  respond_to do |format|
    format.html # index.html.erb
    format.xml  { render :xml => @users }
  end
end

# GET /users/1
# GET /users/1.xml
def show
  @user = User.find(params[:id])

  respond_to do |format|
    format.html # show.html.erb
    format.xml  { render :xml => @user }
  end
end

# GET /users/new
# GET /users/new.xml
def new
  @user = User.new

  respond_to do |format|
    format.html # new.html.erb
    format.xml  { render :xml => @user }
  end
end

and my form:

 <%= form_for(@user) do |f| %>
      <% if @user.errors.any? %>
        <div id="error_explanation">
          <h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>

          <ul>
          <% @user.errors.full_messages.each do |msg| %>
            <li><%= msg %></li>
          <% end %>
          </ul>
        </div>
      <% end %>

  <div class="field">
    <%= f.label :email %><br />
    <%= f.email_field :email %>  
  </div>
  <div class="field">
    <%= f.label :password %><br />
    <%= f.password_field :password %>
  </div>
  <div class="field">
    <%= f.label :password_confirmation %><br />
    <%= f.password_field :password_confirmation %>
  </div>
  <div class="field">
    <%= f.label :nom %><br />
    <%= f.text_field :nom %>
  </div>
  <div class="field">
    <%= f.label :prenom %><br />
    <%= f.text_field :prenom %>
  </div>
  <div class="field">
    <%= f.label :role %><br />
    <%= f.text_field :role %>
  </div>
  <div class="field">
    <%= f.label :date_embauche %><br />
    <%= f.date_select :date_embauche %>
  </div>
  <div class="field">
    <%= f.label :domaine %><br />
    <%= f.text_field :domaine %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

my model:

class User < ActiveRecord::Base
  devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable
  attr_accessible :email, :passw开发者_开发问答ord, :password_confirmation, :remember_me, :nom, :prenom, :role, :date_embauche, :domaine
end


If you use Devise, you should use it views and controllers to create users.
Your "New User" link on the users index page should look like:
<%= link_to 'New User', new_user_registration_path %>

And to customize Devise views you can run:
rails generate devise:views

and then edit rails_root/app/views/devise/registrations/new view

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜