Rails Authentication Tutorial

Does anyone know a good authentication tutorial they can suggest? I've tried several restful authentication ones and an authlogic one on RailsCast. But with each one I try, something seems to be missing in the tutorial and I can't get it to work. I'm new to Rails so it's possible user error on my part.

I'm on Mac OS X 10.5 and I generate all my apps in the Sites directory. Is there a better place to create these applications?

thanks for any response.

Kevin M wrote:

Does anyone know a good authentication tutorial they can suggest? I've tried several restful authentication ones and an authlogic one on RailsCast. But with each one I try, something seems to be missing in the tutorial and I can't get it to work. I'm new to Rails so it's possible user error on my part.

And the problems you're having are...?

I'm on Mac OS X 10.5 and I generate all my apps in the Sites directory. Is there a better place to create these applications?

Yes -- almost anywhere else, unless you're using Passenger.

thanks for any response.

Best,

Hi, why don't you simply post a detail description of the issue(s)
that you're having with the gem/plugin?

-Conrad

Hello Kevin

For a simple authentication you can try nifty_authentication from gem nifty_generators. Just install it, generate a nifty_layout and after that a nifty_authentication. It will create two controllers, one named users which will be for creating users and the other named sessions which will control login and logout. Also be sure to create a map.root in the routes.rb and it will be fully functional. It hasn't got roles etc. though, if you need many roles then maybe it is better to use something else. But for most applications which you might need only an admin area it is ok.

Authlogic has a tutorial project on github (authlogic_example). Download and run that, and then compare that to what you are doing. There is a good tutorial on the authlogic site, but it can still help to look at and test a working example.

The things that stich everything together are the require_user method in the application controller and the “before_filter :require_user” filters in the controllers you want to control access to. Also make sure your user table has the necessary fields.

If you do the tutorial, and double check against the example project, you should be fine.

I started fresh and did the Restful_authentication with all the bells tutorial, (link to tutorial: http://railsforum.com/viewtopic.php?id=14216).

Below is the error I get when I create the database, I did a trace.

Thanks John,

I'm needing something more thanks for the advice, I will try that on a future project.

Kevin

I have Mamp installed so I tried setting the socket that location, Socket: /Applications/MAMP/tmp/mysql/mysql.sock

The rake seemed to go through without problems. However, when I run the server I get this message about a field missing from the database.

Message from browser-------------------------------------

ActiveRecord::StatementInvalid in Root#index

Showing app/views/root/index.html.erb where line #5 raised:

Mysql::Error: Table 'RATdev.invitations' doesn't exist: SHOW FIELDS FROM `invitations` Extracted source (around line #5):

2: <% unless logged_in? -%><% if_in_beta? do -%> 3: <%= error_messages_for :invitation %> 4: <p>We are currently in private beta. Please enter your email address below and we will let know when an invitation becomes available.</p> 5: <% uberform_for [:user, Invitation.new] do |f| -%> 6: <%= f.text_field :email, :label => "Your Email:" %> 7: <%= f.submit 'Submit' %> 8: <% end -%>

Hello--

I started fresh and did the Restful_authentication with all the bells tutorial, (link to tutorial: http://railsforum.com/viewtopic.php?id=14216 ).

Below is the error I get when I create the database, I did a trace.

--------------------------------------------- iMac:restful_authentication_tutorial Meyer$ rake db:create --trace (in /Users/Meyer/Rails/restful_authentication_tutorial) ** Invoke db:create (first_time) ** Invoke db:load_config (first_time) ** Invoke rails_env (first_time) ** Execute rails_env ** Execute db:load_config ** Execute db:create Couldn't create database for {"socket"=>"/var/run/mysqld/mysqld.sock", "reconnect"=>true, "encoding"=>"utf8", "username"=>"root", "adapter"=>"mysql", "password"=>"root", "database"=>"RATdev", "pool"=>5}, charset: utf8, collation: utf8_general_ci (if you set the charset manually, make sure you have a matching collation) ---------------------------------------------

I kept the default socket the example had: socket: /var/run/mysqld/ mysqld.sock

Thanks for everyone's suggestions.

Kevin

Let's take a step back. You have both the Apple version of MySQL and
MAMP installed? Are you actually using this successfully or could
there be a database connection problem? To factor this out, I
recommend you change your adapter to "sqlite3" (and install the Ruby
sqlite3 gem). Then change database.yml as:

development:    adapter: sqlite3    database: db/RATdev.sqlite3

test:    adapter: sqlite3    database: db/RATtest.sqlite3

Next, create the whole thing using Rake:

rake db:create

See if your problem persists.

In my experience, it is possible to run more than one version of MySQL
on one machine, but you have to take pains to separate the sockets and
ports between the instances. In other words, you will be working with
something other than an "out of the box" installation. That could
account for your difficulty.

Hey Kevin

use this restful authentication i have used it in my many projects and its working fine.

http://railsforum.com/viewtopic.php?pid=74245#p74245

@ruchika I'm trying the one you suggested, but I have problem when I get to the end where it says to create the database. I enter the follow in the terminal:

$ mysql -u

But I get this error

-bash: mysql: command not found

What am I doing wrong?

I tried this next based on a Google search:

sudo /usr/local/mysql/bin/mysql -u root

I get this error:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

My searching has not produced an answer.

Anyone with ideas?

Thanks, Kevin

?? Either that's not the location of the socket or your MySQL server isn't running.