I've been trying to build my first rails app and have gotten stuck on the issue of user authentication. I've found a number of tutorials for using various plug-ins to do this, but so far every single one of them is out-dated, and as a result, broken!
From what I've read, I think Authlogic may be the best fit for me, and I've tried two things:
1) Going through Railscast, episode #160 (which is a tutorial for setting it up)
2) Using Ryan B's nifty_authentication gem with the --authlogic tag
In both cases, I get the following error as soon as I try to do anything with a user:
undefined local variable or method `acts_as_authentic' for #
I believe this is from the User model:
class User < ActiveRecord::Base
acts_as_authentic
end
I'm sure I've installed the authlogic gem, and I've added
config.gem "authlogic"
to my environment.rb
Any ideas about what's wrong? Anybody know of a complete and up to date tutorial for adding user authentication?
Edit:
I'm running Ruby v. 1.8.6 and rails v. 2.3.5
There is one thing that Ryan Bates in the RailsCasts episode doesn't talk about is about creating sessions table in your database. Type rake db:sessions:create in the console and run the migration rake db:migrate. Also like ghoppe says run rake gems:install after installing the gem. That is a requisite.
Here's an example app with a step-by-step guide - it's from last year but should still be mostly if not entirely accurate:
authlogic_example
Since you added that line to your environment.rb, have you tried rake gems:install to ensure the gem is installed and working correctly?
Also, what version of Ruby? What version of Rails? Have you tried running gem environment and gem list to make sure they're installed and running from the right place?
Another option is to use authlogic as a plugin, with:
script/plugin install git://github.com/binarylogic/authlogic.git
It also helps to look at a projects that uses authlogic as authentication module, like the fat_free_crm project, have a look at user.rb there
Last but not least, there is an active mailing list:
authlogic mailing list
Becoming popular is also the devise gem. Here you can add authentication with script/generate devise and you will have some views for login as well.
I forked that authlogic_example and added activity_tracker, authlogic, paperclip for user profile images, declarative_authorization, and user to user messages.
http://github.com/jspooner/authlogic_cucumber_rspec_example
Related
I have a Rails 4 app with Thoughtbot Administrate for the admin part.
Recently I tried to upgrade from version 0.1.2 to 0.1.4, but I got this error: cannot load such file -- administrate/fields/base.
It was triggered from a custom field file, so I tried to run rails g administrate:install, which asked me to overwrite all my administrate controllers and dashboards.
Now, I have made customizations to those files, so I opted not to overwrite them, but then I ended up with the same error as before.
Next, I made another branch to test and let administrate to overwrite my controllers and dashboards, and this time it worked!
So, I think the question is, what is the process to upgrade the gem without losing my customizations?
Is there any task I can run in order to "register" the updated gem, like rake administrate:upgrade or so?
Thanks!
Found out the error.
Seems that administrate/fields/base is now administrate/field/base, so this subtle update in the Administrate gem code is breaking my custom field.
Anyway, I think a potentially breaking update to the gem's code should be advertised and maybe even change the mayor version number, so I'll rise an issue in github for this one.
I am in the process of using the rails upgrade plugin (https://github.com/rails/rails_upgrade) to bring the application from 2.3.14 to 3.2. The plugin identified "restful_authentication" as something that needed to be replaced. After some research I decided to try to migrate to Devise.
I started looking at https://github.com/plataformatec/devise/wiki/How-To:-Migrate-from-restful_authentication-to-Devise, the issue I ran into is that these instructions are not meant for Rails 2.3.14.
I can figure out how to make most of it work for 2.3.14, but the biggest block I have ran into is that I am not sure which versions of Devise, Devise-encryptable and other gems to use. Is there an simple way to check?
Alliteratively am I making a mistake in trying to migrate to devise before I upgrade, should it be done the other way around?
Re: Is there a simple way to check? The short answer is no.
To know what Devise gems to use, just follow the directions in the devise wiki - you just need devise and devise-encryptable according to the wiki.
Re: Which one to do first: Whatever you decide to do, its a good idea to have a stable branch before attempting an upgrade. So either you a) upgrade Rails + get restful_auth working, or b) use Devise + upgrade Rails - just avoid trying to do both at the same time.
a) seems possible if you use https://github.com/Satish/restful-authentication . It's a fork of the original project, and neither are as active as Devise ( https://www.ruby-toolbox.com/categories/rails_authentication ). You may choose to upgrade your authentication system to devise anyway, which leads us to...
b) probably the road-more-travelled. You should be able to find plenty of (Rails 2.3) upgrade instructions for restful_authentication->Devise. Get your specs green, then attempt the Rails 3 upgrade.
Mac OS X 10.7.3 Lion,
Ruby 1.9.2,
Rails 3.2.2,
Sass 3.2.3
Following this tutorial:
http://activeadmin.info/documentation.html
Following this video tutorial
http://www.youtube.com/watch?v=tAxlrHcEg9U
I add the activeadmin gem, run bundle install, then run
rails generate active_admin:install
rails generate active_admin:resource POST
Only after creating the app/admin/posts.rb and trying to run either
db migrate
rails server
fails with the error
uninitialized constant Post NameError
with out that posts.rb file i am able to run the admin interface error free.
I tried moving the sass-rails gem out side of the :assets in my gem file and re-running bundle install as suggested in another question, but to no avail I still have the error
according to the getting started active admin tutorial "Post" is suppose to be a module name so i assume the code above is calling a class method (ActiveAdmin as the class, register as the method) and sending the module as a parameter and the block do end
Regardless the error is implying that RoR doesn't know what Post is. As if it does not exist. Being new to rails i do not know how to navigate well, meaning i do not even know where this ActiveAdmin source file is in order to dig through it for a method Post
Thank you for the consideration and your time, I appreciate it.
The linked tutorial assumes that you have already created a model named Post (and have run rake db:migrate to link it to the database). The purpose of the rails generate active_admin:resource Post command is to tell ActiveAdmin that you want it to consider the Post model in part of what it does.
Historically, you'll see models like Post and User in Rails a lot -- these are the commonly used examples of creating a blogging application (a user can create blog posts).
So, whatever models you have in your application can be registered with ActiveAdmin by replacing Post with the name of your model.
Another note: while generators like this tend to be forgiving, a Post is a model that is defined in post.rb and is linked to a SQL table called posts. Be careful with things like upper- and lower-case, and singular and plurals. In Rails they all fit together in a special way.
After I install devise and create a user model. I rake db:migrate and then I rake routes. I then get a error with "undefined method `devise_for' for #". What could be causing this error?
Remember to restart your rails server after installing and configuring devise.
If you have the Devise gem specified in the Gemfile, just make sure you have the following in your routes.rb file:
devise_for :users
Also, here's a trick to make sure Devise is mapped properly, run: rails c, (the Rails app console) in your app's folder and then the following command line:
Devise.mappings.keys
You should see:
=> [:user]
Cheers!
Honestly, I would recommend following these two Railscasts (Episode 209 and Episode 210). The first is a simple and very easy walkthrough for installing Devise and the second is about customizing it to fit your application.
I've watched both episodes and they drastically helped me with Devise, particularly with the customization.
Your best bet is to start from scratch - you'll learn a heck of a lot and have Devise fully installed and functional.
Hope this helps! Good luck.
You may need to do a bundle install
i've been using rails 2 for a project and restful_authentication with it. Recently, i changed that project to rails 3 and i found out about devise, that to my eyes seems a much better solution that restful_authentication.
Therefore, i decided that it would be a good idea to migrate to devise, but it seems that the procedure is pretty tedious and error prone. I would like to ask you if you know of any good resource that describes the procedure, because doing it from scratch is a bit of a hassle.
rails generate devise:install
rails generate devise User
rake db:migrate
That's all there is for now, you get routes and functionality like /users/sign_(in|out|up) from start.
Resources:
Railscasts "Introducing Devise"
Devise Readme
Example application
You can try Migrating from Restful Authentication to Devise, but so far nothing for me. :(