Ruby on Rails
Tuesday October 28, 2008 at 9:38pm
Here are the steps I took to install restful_authentication with acts_as_state_machine (using the new aasm gem) as plugins.
Started in the rails home directory of the app.
Installed aasm gem as a plugin:
| script/plugin install git://github.com/rubyist/aasm.git |
|
(thanks to Erik on Rails for the above)
Installed restful authentication:
| git submodule add \ |
git://github.com/technoweenie/restful-authentication.git \ |
vendor/plugins/restful_authentication |
|
I use capistrano so I also added the following to my config/deploy.rb file
| set :git_enable_submodules, 1 |
|
Created a lib directory in the app home directory:
Called the restful authentication generator. Fyi, instead of user, I use person as the name of my model for people:
| ./script/generate authenticated person sessions --include-activation --aasm |
|
Then I did the post-generate steps, following some of the instructions at github. Some of the steps enumerated in the docs seem to be taken care of as part of the generate call now.
In config/routes.rb, I did a find/replace on peoples (incorrect plural) replacing all with people (correct plural) and added the activate route. In the end my routes.rb looked like this:
| map.logout '/logout', :controller => 'sessions', :action => 'destroy' |
map.login '/login', :controller => 'sessions', :action => 'new' |
map.register '/register', :controller => 'people', :action => 'create' |
map.signup '/signup', :controller => 'people', :action => 'new' |
map.activate '/activate/:activation_code', :controller => 'people', |
:action => 'activate', :activation_code => nil |
map.resources :people, :member => { :suspend => :put, |
:unsuspend => :put, |
:purge => :delete } |
|
In config/environment.rb, I added:
| config.active_record.observers = :person_observer |
|
So I can use before filters in my controllers, I modified app/controllers/application.rb to include AuthenticatedSystem:
| class ApplicationController < ActionController::Base |
helper :all |
include AuthenticatedSystem |
end |
|
I adjusted the language in app/models/person_mailer.rb, especially replacing the YOURSITE references to be the URL of my site:
| @body[:url] = |
"http://www.landlessness.net/activate/#{person.activation_code}" |
|
Reader Discussion
pisterty
Thursday June 11, 2009 at 2:01am
My refusal to use Windows is what makes me learn to do everything using only Linux, even though it usually requires long times in front of the computer researching and tweaking the hints google.com/linux gives me. But, at least I can say that at the end the results are satisfying, I end up learning more about Linux (recommend start from this ebook http://www.ebook-search-queen.com/ebook/Linu/Linux+Filesystem+Management.all.html ) and how powerful a command line application can be compared to a most GUI application. I must admit that I do prefer GUI in the majority of the cases, is just that from time to time I am amazed by the power of the CLI.
Xcapee
Friday October 30, 2009 at 7:00pm
G’day. Thanks for your post, but I am tearing my hair out trying to install restful authentication.
git submodule add… fails with
fatal: Not a git repository (or any of the parent directories): .git
What have I missed?
Comment on this post
Related posts
strftime without leading zeros (0s)
In Rails I wanted to display times like 2:30 am without having a leading zero like 02:30 am.
The view code that gave leading zeros looked like this:
| <%= foo.updated_at.strftime("%I:%M %p") %> |
|
The code that will trim leading zeros looks like this:
| <%= foo.updated_at.to_datetime.strftime("%-1I:%M %p") %> |
|
The trick is to convert the time object from ActiveSupport::TimeWithZone to DateTime, which supports prefix modifiers like ‘-1’ in the format expression.
read more
Validate One ActiveRecord Attribute
I am using restful_authentication and want to extend it with functionality to invite a person using only his email. So, I wanted the ability to validate just one attribute of a model. Expressia::Blog described the same problem here and had built the plugin I wanted. Only all the links to the plugin pointed back to the original post. I eventually found the plugin install and usage documentation here at RailsLodge.
| ruby script/plugin install svn://vinsol.com/plugins/sur/validate_attributes |
|
Now, my relevant code looks like this:
| @person.validate_attributes(:only => ['email']) |
|
read more
Passing optional local variables to a partial
In verbose_index.html.erb i want to pass some additional parameters to the _thing.html.erb partial:
| <% @things.each do |thing| %> |
<%= render :partial => thing, |
:locals => {:some_extra_stuff => some_extra_stuff} %> |
<% end %> |
|
in index.html.erb i do not want to pass any additional parameters to the _thing.html.erb partial:
| <%= render :partial => things %> |
|
when I hit verbose_index everything will work fine. but when I hit index, I’ll see this error:
| undefined local variable or method 'some_extra_stuff' |
for #<ActionView::Base:0x22e6948> |
|
to fix, in _thing.html.erb I add a check to see if the local variable is assigned:
| <% unless local_assigns[:some_extra_stuff].nil? %> |
<%= some_extra_stuff %> |
<% end %> |
|
read more