I'm trying to use the Sorcery gem for authenticating users, but after the registration form is filled out it redirects back to the registration page with an error. I'm able to create a user from the console, however.
log file:
Started POST "/users" for 127.0.0.1 at 2012-01-23 13:54:12 -0500
Processing by UsersController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"Rh6R5rwLu+XchOv3ki9iATgihU8hqr84y4AcQbyKFyI=", "user"=> {"username"=>"testusername", "email"=>"[email protected]", "password"=>"[FILTERED]"}, "commit"=>"Register"}
[1m[35m (0.1ms)[0m SELECT 1 FROM "users" WHERE "users"."username" = 'testusername' LIMIT 1
[1m[36m (0.1ms)[0m [1mSELECT 1 FROM "users" WHERE "users"."email" = '[email protected]' LIMIT 1[0m
Rendered users/new.html.erb within layouts/application (2.1ms)
Completed 200 OK in 29ms (Views: 17.1ms | ActiveRecord: 0.3ms)
users_controller.rb
class UsersController < ApplicationController
def new
@user = User.new
end
def create
@user = User.new(params[:user])
if @user.save
redirect_to 'Static#index', :notice => "Thanks for registering!"
else
render :new
end
end
end
models/user.rb:
class User < ActiveRecord::Base
authenticates_with_sorcery!
attr_accessible :username, :email, :password
validates_presence_of :username
validates_presence_of :password, :on => :create
validates_presence_of :email
validates_length_of :password, :minimum => 7
validates_length_of :username, :minimum => 10
validates_uniqueness_of :username
validates_uniqueness_of :email
end
config/initializers/sorcery.rb:
Rails.application.config.sorcery.submodules = []
Rails.application.config.sorcery.configure do |config|
config.user_config do |user|
end
config.user_class = "User"
end
sorcery migration:
class SorceryCore < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.string :username, :null => false
t.string :email, :default => nil
t.string :crypted_password, :default => nil
t.string :salt, :default => nil
t.timestamps
end
end
def self.down
drop_table :users
end
end
What you need to see in log file is more or less this:
If you can't see INSERT statement, this means that data didn't pass validations. Maybe you're trying to add another User with the same username/email? Otherwise it should work. Try to create User in rails console:
Does it return any messages?
EDIT: Sorry I've just noticed your update, where you wrote that you can create User in console. From log file it looks like parameters are ok. You said, that redirects to new page with error. What does this error say?