Problem with restful_authentication

Hi,

(newbie here)

I’m having a problem with the restful_authentication plugin.

When I fill out my information on this page:

http://localhost:3000/users/new

I’m routed to “users/index” which isn’t defined.

Here’s what’s happening in the log: (I’ve replaced my actual values with
XXX below – and I did use a valid email address)

Processing UsersController#index (for 127.0.0.1 at 2007-07-23 22:00:19)
[POST]
Session ID:
BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo%0ASGFzaHsABjoKQHVzZWR7AA%3D%3D–1a2fe1a336d66f48d7cd0578ecc051d598f4cf5a
Parameters: {“user”=>{“password_confirmation”=>“XXX”, “login”=>“XXX”,
“password”=>“XXX”, “email”=>“XXX”}, “commit”=>“Sign up”,
“action”=>“index”, “controller”=>“users”}
Rendering users/index
Completed in 0.03610 (27 reqs/sec) | Rendering: 0.02607 (72%) | DB:
0.00000 (0%) | 200 OK [http://localhost/users]

I’ve tried creating a views/index.rhtml file, which prevents the

"Unknown action

No action responded to index"

error from occuring, but when I look at my database, no new user has
been created. Reading some pages on the web I tried again with edge
rails and getting the active record plugin, but the problem persists.

Is the ‘index’ action really the one that is supposed to be invoked? If
not what is? Is email supposed to be sent to the email address I
submitted with password confirmation? I see this file:

app/views/user_notifier/signup_notification.rhtml

But I never get there.

Any help appreaciated. Thanks in advance!

I reloaded the restful_authentication today, but I’m not sure how to
check the version number.

Ruby version 1.8.6 (powerpc-darwin8.9.0)
RubyGems version 0.9.2
Rails version 1.2.3
Active Record version 1.15.3
Action Pack version 1.13.3
Action Mailer version 1.3.3
Active Support version 1.4.2
Edge Rails revision 7216
Environment development
Database adapter mysql
Database schema version 1

Durant S. wrote:

I’ve tried creating a views/index.rhtml file, which prevents the

"Unknown action

No action responded to index"

error from occuring, but when I look at my database, no new user has
been created. Reading some pages on the web I tried again with edge
rails and getting the active record plugin, but the problem persists.

Oops, this should read:

I’ve treid creating an app/views/users/index.rhtml file, …

this page does load, but no user is added to the database.

Durant S. wrote:

Hi,

(newbie here)

I’m having a problem with the restful_authentication plugin.
[…]

Edge Rails revision 7216
Environment development
Database adapter mysql
Database schema version 1

You might have to get an older version of restful_authentication as the
newest only works with edge Rails AFAIK. If you run the test suite it
should show lots of errors if you’re on an incompatible version.

Try downgrading to r2563 and see if it helps.


Cheers,

  • Jacob A.

Jacob A. wrote:

You might have to get an older version of restful_authentication as the
newest only works with edge Rails AFAIK. If you run the test suite it
should show lots of errors if you’re on an incompatible version.

Try downgrading to r2563 and see if it helps.


Cheers,

  • Jacob A.

Hi Jacob,

Thanks for replying.

I’m not sure how to download an older version of the plugin (I didn’t
see anything after running and reading this: script/plugin --help).

Since I’m over my head with using edge rails, I’ll probably try
acts_as_authenticated instead. Thanks!

PS -

Here’s what I tried:

test 1

cd ~/Programming/ruby/rails/
\rm -rf restfulauthentication/*
rails restfulauthentication
cd restfulauthentication/
rake rails:freeze:edge REVISION=2563
script/plugin install restful_authentication
#ERROR
#script/plugin:3:in ‘require’: no such file to load – commands/plugin
(LoadError)

from script/plugin:3

test 2

cd ~/Programming/ruby/rails/
\rm -rf restfulauthentication/*
rails restfulauthentication
cd restfulauthentication/
script/plugin install restful_authentication
rake rails:freeze:edge REVISION=2563

update config/database.yml

mysql -u MYUSERNAME -p -e "create database

restfulauthentication_development"
#!
rake db:migrate
#ERROR
#(in ~/Programming/ruby/rails/restfulauthentication)
#rake aborted!
#Don’t know how to build task ‘db:migrate’
#!
rake migrate
#ERROR
#(in ~/Programming/ruby/rails/restfulauthentication)
#rake aborted!
#undefined method `cache_template_extensions=’ for
ActionView::Base:Class

test 3

cd ~/Programming/ruby/rails/
\rm -rf restfulauthentication/*
rails restfulauthentication
cd restfulauthentication/
script/plugin install restful_authentication
./script/generate authenticated user sessions --include-activation

update config/database.yml

rake db:migrate
rake rails:freeze:edge REVISION=2563
script/server
#ERROR
#./script/…/config/…/vendor/rails/railties/lib/initializer.rb:159:in
send': undefined methodcache_template_extensions=’ for
ActionView::Base:Class (NoMethodError)

Jacob A. wrote:

cd [into/rails-root]

svn export -r 2563
http://svn.techno-weenie.net/projects/plugins/restful_authentication/
vendor/plugins/restful_authentication

This version of the plugin should work with Rails 1.2.3.

I tried this but when I attempt to log in, I get an error trying to
re-route me to an index action in the user controller, but one doesn’t
exist.

In the meantime, I tried acts_as_authenticated and it seems to work
right out of the box, so I’m going to play around with that instead, but
thanks for all your help, maybe I’ll come back to this later.

Durant

Durant S. wrote:

PS -
rake rails:freeze:edge REVISION=2563
\rm -rf restfulauthentication/*
#(in ~/Programming/ruby/rails/restfulauthentication)

rake rails:freeze:edge REVISION=2563
script/server
#ERROR
#./script/…/config/…/vendor/rails/railties/lib/initializer.rb:159:in
send': undefined method cache_template_extensions=’ for
ActionView::Base:Class (NoMethodError)

Oh no, I’m not saying you should freeze Rails to revision 2563, it was
the plugin I was talking about. With plain svn that would be:

cd [into/rails-root]

svn export -r 2563
http://svn.techno-weenie.net/projects/plugins/restful_authentication/
vendor/plugins/restful_authentication

This version of the plugin should work with Rails 1.2.3.


Cheers,

  • Jacob A.

Rick O. wrote:

You’ll have to look in the logs and see why it’s sending you from /new
to #index.

Jacob’s suggestion of using revision 2563 of the plugin did allow the
“rake test” to pass with rails 1.2.3, but I’m back to my original
problem.

I go to http://localhost:3000/users/new and fill out the form to sign up
as a new user with a new email address. I get redirected to “index”
which is confirmed by the logs with “action”=>“index”,
“controller”=>“users”.

This is the only thing in the log, really (some info XXX’ed out):

Processing UsersController#index (for 127.0.0.1 at 2007-07-31 00:52:53)
[POST]
Session ID: 04638569bb27f6f60ee366333899223b
Parameters: {“user”=>{“password_confirmation”=>“XXX”,
“login”=>“durant”, “password”=>“XXX”, “email”=>“XXX”}, “commit”=>“Sign
up”, “action”=>“index”, “controller”=>“users”}
User Columns (0.011967) SHOW FIELDS FROM users
User Load (0.216032) SELECT * FROM users WHERE
(users.remember_token = ‘c9a8988c930fc6bb8c1df1fb17bd9d6406469f1c’)
LIMIT 1

I’m too new to rails to understand what is happening under the hood when
the ‘Sign up’ button is pressed.

app/views/users/new.rhtml

contains a form with the ‘Sign up’ button.

I’m guessing a models/user.rb user is supposed to be created and
controllers/user_controller.rb is supposed to be called with “create”.

Then I would supposedly get email sent to me (via
app/modlels/user_observer.rb UserObserver#after_create) with an
activation URL and I can activate my account through a page that calls
user_controller#activate.

But that user model creation never happens. I confirm that by checking
my database and there’s no new user entry. The “index” error occurs
before any new entry is added to the database in the logs

Check your routes too.

I added these which were recommended:

restful_authentication

map.resources :users, :sessions
map.signup ‘/signup’, :controller => ‘users’, :action => ‘new’
map.login ‘/login’, :controller => ‘sessions’, :action => ‘new’
map.logout ‘/logout’, :controller => ‘sessions’, :action => ‘destroy’

I’m not sure I understand
map.resources :users, :sessions

which is supposed to make this RESTful, I think.

The readme should help you out.

Yeah, I looked at this:

vendor/plugins/restful_authentication/README

which made three suggestions (all of which I followed)

./script/generate authenticated user sessions --include-activation

config/routes.rb
map.resources :users, :sessions

config/environment.rb
config.active_record.observers = :user_observer

Any edge rails issues are just limited to tests, they don’t affect the
actual plugin. All you’d have to do is add assert_difference methods
and tests should pass.

Yeah, I’m not using edge anymore for this test (now that I know I can
use revision 2563 of the plugin with rails 1.2.3).

On 7/31/07, Durant S. [email protected] wrote:

as a new user with a new email address. I get redirected to “index”

“login”=>“durant”, “password”=>“XXX”, “email”=>“XXX”}, “commit”=>“Sign
up”, “action”=>“index”, “controller”=>“users”}
User Columns (0.011967) SHOW FIELDS FROM users
User Load (0.216032) SELECT * FROM users WHERE
(users.remember_token = ‘c9a8988c930fc6bb8c1df1fb17bd9d6406469f1c’)
LIMIT 1

I think you’re just unfamiliar with the restful routing stuff and
should probably stick with acts_as_authenticated until you’re more
comfortable with it. If you look at the form, it should be posting to
/users, which should invoke the create action, not index. If
something is redirecting you, you have some other underlying problem.
I’ve seen this happen with faulty apache configs changing POST /users
to GET /users/, for example.


Rick O.
http://lighthouseapp.com
http://weblog.techno-weenie.net
http://mephistoblog.com

Ok,

I finally know what was happening and I think this will be helpful for
other rails newbies:

in config/routes.rb

I needed to have the restful routes:

restful_authentication

map.resources :users, :sessions

map.signup ‘/signup’, :controller => ‘users’, :action => ‘new’
map.login ‘/login’, :controller => ‘sessions’, :action => ‘new’
map.logout ‘/logout’, :controller => ‘sessions’, :action => ‘destroy’

map.activate ‘/activate/:activation_code’, :controller => ‘users’,
:action => ‘activate’

listed BEFORE the default routes:

Install the default route as the lowest priority.

map.connect ‘:controller/:action/:id.:format’
map.connect ‘:controller/:action/:id’

Once I placed the new routes above the defaults, I could go back and use
users_path, instead of explicitly calling :create.

It all makes sense now. Obvious in retrospect. Hindsight is 20/20.
Hopefully, if someone else makes the same mistake they’ll find this
page.

Thanks all,

On 7/30/07, Durant S. [email protected] wrote:

I tried this but when I attempt to log in, I get an error trying to
re-route me to an index action in the user controller, but one doesn’t
exist.

In the meantime, I tried acts_as_authenticated and it seems to work
right out of the box, so I’m going to play around with that instead, but
thanks for all your help, maybe I’ll come back to this later.

You’ll have to look in the logs and see why it’s sending you from /new
to #index. Check your routes too. The readme should help you out.
Any edge rails issues are just limited to tests, they don’t affect the
actual plugin. All you’d have to do is add assert_difference methods
and tests should pass.


Rick O.
http://lighthouseapp.com
http://weblog.techno-weenie.net
http://mephistoblog.com

Durant S. wrote:

It all makes sense now. Obvious in retrospect. Hindsight is 20/20.
Hopefully, if someone else makes the same mistake they’ll find this
page.

Thanks all,

No no, thank you! That’d been driving me crazy for quite long enough
before I stumbled upon your persistence. Thanks so much for taking the
time! :slight_smile:

(partial) SUCCESS!

So, thinking about all this I wondered what would happen if I forced the
form to call #create:

in app/views/users/new.rhtml I changed this:

<% form_for :user, :url => users_path do |f| -%>

to this:

<% form_for :user, :url => {:action => :create} do |f| -%>

which DID create the user in the database and the logs show that email
was created and sent (though I haven’t received it).

So that’s some progress – I’ll try to read more about REST and routing
to understand why index was invoked, when it really shouldn’t have been.
Acts_As_Authenticated is probably simpler for me to use now, but this is
interesting and I might get it working.

thanks,

Rick O. wrote:

On 7/31/07, Durant S. [email protected] wrote:

as a new user with a new email address. I get redirected to “index”

“login”=>“durant”, “password”=>“XXX”, “email”=>“XXX”}, “commit”=>“Sign
up”, “action”=>“index”, “controller”=>“users”}
User Columns (0.011967) SHOW FIELDS FROM users
User Load (0.216032) SELECT * FROM users WHERE
(users.remember_token = ‘c9a8988c930fc6bb8c1df1fb17bd9d6406469f1c’)
LIMIT 1

I think you’re just unfamiliar with the restful routing stuff and
should probably stick with acts_as_authenticated until you’re more
comfortable with it. If you look at the form, it should be posting to
/users, which should invoke the create action, not index. If
something is redirecting you, you have some other underlying problem.
I’ve seen this happen with faulty apache configs changing POST /users
to GET /users/, for example.


Rick O.
http://lighthouseapp.com
http://weblog.techno-weenie.net
http://mephistoblog.com