RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

 Hi Ryan,
Great screencast for rails 2.3.Take care of commenter Melvin Ram above,he also explains extras.

Please let me know the command/tool to watch the runtime changes to the file.

Avatar

Thanks Ryan for the screencast. I am glad to find an RA alternative.

Avatar

Any plans for authorize.net processing ryan? I'm trying to get it work but just can't was hoping you might give some insight.

Avatar

It is nice screencast for Rails 2.3. What about Rails 2.1? How do I use Rack in Rails 2.1? Any screencast for that?

Avatar

Installing Authlogic as a gem is plain stupid, plugins are much better than gems to work with a Rails app. Everybody wants gems and then they go through the pain of vendoring them...

I don't really see the benefit of Authlogic over Restful_auth which isn't that intrusive.

Avatar

Cucumber testing with Authlogic would be great for RC#161!

Avatar

I would love a screencast on Roles. This is a great screencast as usual Ryan. Thanks for all your work.

Avatar

@mark, @jose, @ryan check out acl9 on github, it works great with Authlogic.

Avatar

Nice as always, thanks, another cast with advanced use of Authlogic would be great.

Something like reset\change password, or a basic role system :)

Avatar

Just one remark:

it is not a good idea to show a user in the login validation that only the password is wrong. would be better if "username or password" is wrong is displayed.

But this can be easily added and I think this was just a "to less time to secure all things"-thing for this small but good example of authlogic.

Avatar

Great cast Ryan. I started using authlogic last week and love it.

One problem I keep coming across in my apps is how to keep normal users viewing their own records and the various administration levels viewing what is available to them. It would be great if you could share your thoughts on keeping authorization systems clean and simple. Maybe by re-factoring much of the code to a gem/plugin?

Something like this everywhere gets tedious and dirty:

if admin?
  @post=Post.find(params[:id])
elsif moderator?
  @post=...
else
  @post=...
end

Avatar

Great Video! Congrats, Ryan. It would be marvelous if you show some authorization techniques. I was just enthusiastically waiting for your Authlogic video and I'm waiting now for the authorization rules :) Thank you very much!

Avatar

@jared, @andy: The :current is just a arbitrary symbol. Instead of passing an id the string "current" is used in the url. This does not make a difference since params[:user_id] is not used in the controller. Still it makes for a nice urls, since you can tell that you are editing the current user.

Hope that helps.

Avatar

Seriously what's up with the :current thing?

Avatar

Thanks Ryan! Authlogic is really excelent! For those who need to build account confirmation or reset password on top of Authlogic, check out the AuthHelpers plugin (http://github.com/josevalim/auth_helpers)!

The idea of the plugin is to hold modules that are not handled by Authlogic by default. So those who wants an authorization system, would consider building it on top of AuthHelpers, so you will have to do it just once!

Avatar

I can't say enough good things about Authlogic. I never liked RA and dreaded having to unearth it for nearly every project. For me, Authlogic brought back the joy in starting a new rails app.

Why, you ask. Simply... it walks, talks, and smells like rails. RA is more like you multi-challenged uncle sporting the latest hair replacement product.

Avatar

@Mark, @Jose, Authlogic only handles authentication, not authorization. It is important to draw the line there because there are *many* authorization techniques. You may need just an "admin" column in the user model, or a full blown role based complex permission system. Authorization usually has little overlap with authentication logic.

I do plan to cover some more authorization techniques in future episodes. The beauty is that it will work with pretty much whichever authentication scheme you are using.

Avatar

Authlogic is the shit. Before I found it I used restfull_authentication (as probably almost everyone did).. but authlogic is just a better, cleaner sollution. As an extra bonus the coder BinaryLogic seems superpicky about his code.

Ppl should also check out:

http://www.binarylogic.com/2009/03/30/authlogic-2-0-with-some-openid-goodness/

.. and..

http://www.binarylogic.com/2009/02/25/the-future-of-authlogic-add-ons/

.. just think about it, soon you might be able to offer facebook connect authentication in your apps without alot of extra code.. cause of authlogics awesomeness :)

Avatar

Ryan, would you mind explaining the edit_user_path(:current) syntax? I've never seen :current passed into a restful route helper before and I didn't see anything in the Rails docs.

Avatar

I second @Mark on the roles

Avatar

How do you do authorization from AuthLogic, if possible? If not, is there a good role-based authorization solution that works with AuthLogic?

Avatar

Authlogic rocks. Thanks for the tutorial, it will be helpful to explain why we chose authlogic to our users. I would also suggest that you consider a screencast on Ben's very awesome searchlogic.

Avatar

@Pierre : I agree. BinaryLogic's code is very clean and well thought out. I've learned a lot looking through it.

Authlogic has been my go-to plugin for authentication for the past few months. The only thing it was missing were some examples on the web to help ease the learning curve, especially for those who don't usually dive into the source. Thanks Ryan for the screencast.

Avatar

@Vidmantas : thanks for the tip!
BinaryLogic's plugin are awesome ;)

Avatar

Is there is any update on the comment number 48, even I want to change the mail configuration at runtime.

Avatar

Authlogic is pure awesomeness - using it in few projects already and I'm very satisfied. Also check other very elegant plugin from BinaryLogic - searchlogic

Avatar

Hey guys,

I got this to work with only one issue.

My development environment runs but its not reading my css file. I saw a comment about this issue earlier but I didn't see that a resolution had been posted. This was just after getting my development environment to work by chmoding my apps to 711.

Anyone have any ideas on how to fix?

Avatar

Hey Samo,
The syntax highlighting is the same as ruby highlighting since you are essentially using ruby to write pdfs in the prawn files. To get the syntax highlighting just click at the bottom where it says "Plain Text" and switch it to Ruby.

Avatar

snowgiraffe - if you need to make such significant changes to the models, etc in the plugin, you probably shouldn't build it as an engine in the first place; I don't know of any reasonable way to 'remove' an association from an existing class, for example. Perhaps there's a lowel level of abstraction that's more suited to the specific case you have in mind? Alternatively, you can provide modules/classes that your application can compose together, as required.

Avatar

Hi Ryan,

Any Idea on how to implement the same kind of test using machinist & nifty_auth?

Avatar

@korben dallas: this may help

http://nerbie69.blogspot.com/2008/12/solved-applicationcontroller-has-been.html

Avatar

hi ryan,
thx for answer. I found the bug couple of seconds ago: the prawnto-plugin wasn't installed correctly. I had an empty folder, instead of the plugin-sources. So I downloaded a zip version of prawnto, copied into my plugin-folder and restarted the server. now it's working ... ;)

Avatar

The Rails Generators Source Link doesn't work anymore...

Avatar

That checkbox problem was a bear to get working for me. check_box_tag wouldn't work for updating and check_box wouldn't work for new tasks.

Here was my solution:

# in the partial
<% if @prefix == "new" %>
   <%= check_box_tag("project[# {@prefix}_task_attributes][][some_value]", "1") %>
<% else %>
   <%= sf_form.check_box 'some_value', {}, "1", "0" %>
<% end %>

# in the helper change prefix to @prefix

Avatar

you forgot to mention to include the javascript libraries in the header or else you get an RJS error.

<%= javascript_include_tag :defaults %>

Avatar

hi!
This example was clear !
But how can I pack a generator in order to make it a dist and publish it. I want some way to make distributable, like gems or plugins. How can I do this?
Thank you

Avatar

Great episode as usual.

I'm a little foggy on why it_should_require_admin_for_actions needs to be a class method. Is it because you're using it to generate it-blocks?

Avatar

Thanks for the screencasts. great one again.

@ryan
maybe you want to add my Netbeans Plugin for Cucumber to your show notes, since i've added the support for 0.3.0 today ;)

Plugin @ my webpage
http://members.chello.at/server/modules.html

Plugin @ Netbeans
http://plugins.netbeans.org/PluginPortal/faces/PluginDetailPage.jsp?pluginid=17939

It will help Windows users who are using Netbeans (there is a ruby/rails edition) to write their Features.

Avatar

At 3:07 on line 5 in the block 'action' changes to 'actual' - don't really see this as a problem, was just weird - thought I was seeing things till I wound it back.

Avatar

World class screencast! Many thanks.

Avatar

Thanks so much Ryan, Scenario Outlines... who knew?

Avatar

Ryan, do you have any experience or advice on working with counter_caches that also have conditions on them?

For instance, what is the best way, or a very good way to go about handling a situation where you want to count only unread messages and also count the total number of messages with a counter_cache? for the total number of messages it's easy. but the unread have some conditions that would obviously need to be checked.

Avatar

In the line

if current_user && current_user.admin? || current_user == @user

you should parenthesize the ||, else if there is no current_user and @user is nil, then the viewer could edit the profile. Probably @user could never be nil, of course.

Avatar

If you're using Windows and you're getting the "not recognized by the 'identify' command." error, here's a solution: http://blog.jonathanhinson.com/2009/04/27/getting-paperclip-working-in-windows/

Avatar

Thanks once again for your railscasts, Ryan!

I'm now learning cucumber and found your explanations very concise and helpful. :)

Avatar

Johannes:

I have it working fine in latest version.

Avatar

@ryan - thanks for your response!

does anyone have any guidelines on when to use factories vs mocks?

i am planning to use factories for unit tests, and mocks for controllers, and 'composite objects'. does that sound like a good strategy?

Avatar

Hi Ryan -
Great stuff, but be careful.
Its lucky all your passwords are 'secret'.
You set up a table in the Outline, but you use literal text in the steps!