Rails Devise broke on sqlite -> Mysql upgrade - ruby-on-rails-3

I have a rails 3.0.9 application that is using Devise for user authentication. It was previously using SQLite, but I changed my application's database to MySQL.
Upon switching to MySQL, the user registration function of Devise stopped working. I'm not getting an error in the rails log. When a new user tries to register, they are simply routed back to the signup page after clicking 'Submit.'
Are there any DB references in the Devise config files that I need to change in order to having Devise play nicely with MySQL?
I should also not that user login / logout is working correctly under MySQL.

I just realized that I had added a before_save :default_values filter on my user model. I originally did this to set default values for certain attributes on the model level. I instead ran a migration setting defaults at the DB level, deleted the before_save call from the model, and everything worked fine.
Silly mistake. Hopefully this helps someone else.

Related

rails 5 using devise

hi currently i am making a new project using rails 5, and devise , my problem is that i am trying to get the current user that is logged into my webapp, and then get the current users id and save it into the database.
currently getting a lot of error and having trouble doing so.
my database are the following for the sample
Note this is the default devise setup for the user
User
username
password
email address
blog
title.text
body.text
user_id.integer
now my problem is that how do i get the current user that is logged into my webapp, and then save it into the blog database that contains the user_id. i havent added the blog yet into one of my samples , but i am currently failing at the results that i need to be making and pushing forward into it.
is there a way to scaffold it , or do i need to go commando and hardcode it, if so how is it possible to do so?
get the current user so that it gets the current user id and save it to each blog.
2.how do i push it into the controller
how do i do it into the model as well
i am a bit confused as to how it should be made and done , with rails any help will be appreciated
In your user.rb model
define relationship with user in this way
has_many :blogs
in your bolg.rb model
belongs_to :user
now in your create method in your blog controller
#user = current_user
then
if #user.blogs.create(blog_params)
#your logic
end
This automatically save user_id to database.

Does rails impose any automatic rules for password fields?

Background:
User record creation in the application I'm working on is failing with errors "Password is too short (minimum is 4 characters)" and "Password confirmation is too short (minimum is 4 characters)".
Neither the User model nor any of its included models mentions passwords. The only places in the application where I can find them mentioned is in forms within the views and in the original database migrations. There is a crypted_password column, and a password_salt column in our users table. We are NOT using devise. The only security_related gems in our gemfile are attr_encrypted and encryptor, neither of which seem to mention any special treatment of passwords in their documentation.
So, since length validations and encryption are in fact happening, and I can't seem to track it down to a model or a gem, where might these rules be coming from? Is there a way I can disable them?
It turns out our application also makes use of the AuthLogic gem, which adds its own validations on login and password by default. As per this page of the documentation, the validations can be overridden in an application-wide configuration or in per-model configuration blocks.

Add Spree to rails app with devise

I'm new at RoR but I'm loving every bit of it :)
I have a small app that uses devise for authentication and it's working fine.
Now I want to add a ecommerce part nad I decided for spree. I installed spree and during installation it asked me if I wanted to use the default authentication, I said 'no'. Then it asked me for the user model which I stated 'User'.
Now I enter my app, I login it goes to the products page on spree. That's ok, but when I try to access the admin part, I get redirected to the products page.
My doubts are:
- Should I install anyway the spree_auth_devise gem?
- Should this be a problem with the database and the users role? Because on the "spree_users" table I don't have anything, only on the Users table...
How can I associate one of my existing users to an admin user on spree?
Should this be the problem or I'm missing something else?
Did you run this:
rails g spree:custom_user User
http://guides.spreecommerce.com/authentication.html in the Initial Setup block
To check is user is admin:
user = User.find_by_email("master#example.com")
user.spree_roles << Spree::Role.find_or_create_by_name("admin")
## To test that this has worked, use the has_spree_role? method, like this:
user.has_spree_role?("admin")

Devise user management

I'm creating a Rails app using Devise for user management (Rails 3.0.10, Devise 1.4.2). I've got the basics going - signup, login / logout - but I can't seem to find any facility (or even documentation surrounding) user management.
In other Rails apps I've created, I've had a UsersController with an index method that allows an administrator to list all the users of a system, & to subsequently modify them through edit and update actions on the same controller.
I can't see an obvious way of doing this with Devise. I've used the Rake tasks that come with Devise to generate editable views, which is great, but I can't figure out how to do the equivalent with the Controller.
I fear I'm missing something fundamental here. Could someone please point me in the right direction?
Devise doesn't come with any sort of Admin interface. If you are the only administrator and don't mind a little crudeness - there is always the console and/or scaffolding.
There are also a lot of good gems that make setting up admin interfaces a cinch: Active Admin, Rails Admin and I'm sure there are a bunch more out there.

Have CanCan use Active Admin user?

I'm using Devise and CanCan for authorization on the frontend of a Rails 3 app. I also have Active Admin as the interface for the backend. I'm trying to create different roles for admins in the backend. Both ends have a login form that uses different 'user' models & tables. The problem is that CanCan fetches the current user from the frontend (grabbing the current user object) and uses that to see if someone in the backend has the correct permissions.
So, how I can have CanCan correctly grab the admin user that's logged in?
If anyone needs more information, I'll be glad to supply it.
I have not used ActiveAdmin before, but have used Devise and Cancan in a couple of projects before.
Having looked at Active Admin Documentation,
Set the method that controllers should call to authenticate the current user with:
# config/initializers/active_admin.rb
config.authentication_method = :authenticate_admin_user!
Set the method to call within the view to access the current admin user
# config/initializers/active_admin.rb
config.current_user_method = :current_admin_user
You can override Cancan behaviour in your application, by looking at :current_admin_user instead of :current_user.
Refer here Cancan changing defaults.
If you still can't get it, post your problems, where you are stuck.