RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

Any chance of adding a HTTP streaming webcast :) with something like orbited or APE?

Avatar

Include vs Joins is very great article ryan

Avatar

What is the "rail blog" command from the very first line of the code?

Avatar

Okay, so I just generated the migration manually, but after I edit the model and view pages, I always get "undefined method 'has_attached_file'".

Avatar

I'm also getting a "couldn't find 'paperclip' generator" error right after I install the plugin and try to run the generator. Anyone know how to fix this?

Avatar

Great tutorial! Is there any way to combine this with your complex form episodes. Basically I'm working on a multi-step, multi-modal app and am kinda stumpped on trying to get different modals in each step of the process.

Avatar

Hi guys,

I have a problem: if I register using facebook for instance, I am redirected to the page to choose a username and email. It works fine. But then, if I try to login via the standard method (email + password), I get the following error: "BCrypt::Errors::InvalidHash". Probably because the email is found, but their is no password associated with it (I dont get the error with a bad password for a user registered without omniauth).

What can I do about that?

Thanks for your help.

Avatar

Okay guys found the answer. When you register your ap with twitter you need to specify 'browser' client and add a callback such as this such as 'http:localhost.com/callback/login.php'

So the problem is to do with your registration

Avatar

@Tilo because current_user is not available in your model... at least it shouldn't ;)

Avatar

I am also getting the Unauthorized exception when trying to login via twitter. I have registered an application with twitter and am using omniauth 1.1.6.

Any idea?

Avatar

Thank you so much

Avatar

Olek, I had the same question as you: how do you lazy-load #all? I found the answer in Pratik's post (see link in the show notes): use #scoped:

@articles = Article.scoped

Seems to me the Rails 3 generators should start generating #scoped by default.

See also http://ilikestuffblog.com/2010/10/30/how-to-lazily-find-all-records-in-rails-3-with-arel/

Avatar

sorry, I meant:

def mass_assignment_authorizer
   current_user.admin? ? super + [:important] : super
end

Avatar

why not just overriding in the model like this:

def mass_assignment_authorizer
   super + [:important] if current_user.admin?

end

Avatar

Thank you for all (^_^). Railscasts.com is amazing!

Avatar

Not sure if this will help anyone but I spent a couple of hours figuring it out.

If you make a custom action like

can :assign_roles, User

then the :manage ability for User will also allow them to assign roles.

I had assumed that :manage was just an alias for :index, :show, :new, :create, :edit, :update, and :delete but after scratching my head for a couple of hours I realized that :manage causes the can? method to return true for any action.

I suppose if you could alias the crud actions in the ability initialize block like

alias_action :index, :show, :new, :create, :edit, :update, :delete, :to => :crud

then you could use

can :crud, User

and

can :assign_roles, User

separately.

I haven't tested it but I think it should work.

Avatar

Another similar plugin for Rails 2.x: http://github.com/SciMed/mass_assignment_fu

Avatar

How can i configure a facebook authentication in development, because i test in localhost and in the facebook´s configuration i configured this with localsite and it always return:

" "error": {
      "type": "OAuthException",
      "message": "Invalid redirect_uri "

Could someone give some insight into this problem??

Avatar

Oops. I read through the comments too quickly. My question was already answered.

Brad, thanks for the hint!

Avatar

As always - fantastic screencast!

Unfortunately, I am also getting "OAuth::Unauthorized" when I go to http://localhost:3000/auth/twitter

There are two others that have this same question on the comments.

Could someone please help give some insight into this problem?

Thanks

Avatar

Is there any solution not to modify (:large) style?

Avatar

@Andreas Lyngstad

I also use rails cast as a reference guide, and it worries me that i no longer see sponsors in the latest cast.

I panic when i dont see a rails cast as its usual time. :S

Avatar

I agree,

Ryan you make the best casts i have ever seen. They have the perfect balance of information and pacing.

I have no idea how you do it, it seems like it must be natural!

I wish you all the best in whatever you do.

Ben

Avatar

The video is really very useful,that's really what i need.It explains how Dynamic attr_accessible works.

Avatar

Nice video. I'd love to see a video on cells which are basically rails components and apotomo, a js framework built on top of it.

Avatar

One thing I don't get about this is how this is actually "authentication". I can trivially create a fake post and send it to `/auth/twitter/callback`, without ever having even visited Twitter, and the app will consider me to be "authenticated".

What am I missing here? What does "authentication" actually mean in this context?

Avatar

I completely agree with you Andreas
these casts are the best rails resource i know of!
And even if Ryan will charge subscription per month for them know I will still use them.
as an example there is the lynda.com site that charge 25$ per month.. this is a reasonably price, Railscasts can still be free for the once a week show, but charge money for the rest of the episodes in the other days.. I know for sure that i will use it. And with the right help from the sponsors i think it can be done.. if Ryan would agree of course :)

Avatar

Hi @all.

I'm working with Windows 7 and after trying rake rails:upgrade:check I get the message “rake aborted! fork() function is unimplemented on this machine”. Does it mean that I cannot use this plugin on Windows?

Thanks for a short response.
Marc

Avatar

People could use the Donate button in the meantime.

Has a Railscasts ever saved you some time? Expense it!

Avatar

I want to quote Ryan From the comments in another cast
" - However I hope to, at some point, have more time to dedicate to Railscasts and make it my full time job."
I think railscasts is very valuable. I use it all the time as a reference guide.

I think it would be a great thing for the rails community if Ryan can have railscasts a his full time job.

Does anybody agree?

Can we all pull together and come up with suggestions on how railscasts can be free and Ryan can get a full time job income?

Maybe big rails companies can, under a voluntary contract pay Ryan some money every month?
I guess they all benefit a great deal from these casts?

Avatar

"Me Too"…
I wish you had covered *nested* forms maybe in conjunction
- with :has_many :through (nested self join HABTM)
- Dynamically extending the form with multiple nested objects and a touch of UJS/JQuery after on.

King regards

Avatar

This is much better than my filter params method I was using.

The only problem I ran into was that delayed job stopped working. This was because it couldn't mass assign payload_object. The simple fix was to remove the attr_accessible call in the initializer.

Obviously this means that models aren't protected automatically, but I always put attr_accessible in all my models so its not a major problem.

Avatar

Thanks! I'm assuming that when we add :js as an argument to respond_to, respond with will render @object.to_json if no js.erb template is found?

Avatar

@Volker: I was hoping to see an answer to the same question. You may have to handle this situation manually. I haven't looked in rails.js, but my guess is that we're still generating a form and submitting it, the difference being that it is being generated unobtrusively. However, as you noted, the form is not being submitted via AJAX.

If you take a look at episode 136, you'll see a way to submit forms via AJAX. You may have to attach a click event to your delete links which generates a form and submits it with AJAX. One problem I ran into with this approach is that the javascript in the js.erb response does not get evaluated. I couldn't figure out how to make this work, so instead I have my controller returning a JSON response and my deleteWithAjax function takes a handler as an argument. The handler will take care of removing the representation of the record from the DOM.

You might find it painstaking to create this form with the necessary authorization token in javascript. I have been experimenting with creating a javascript form builder. One of your included js files can make a get request to a controller and pass in a resource name and an id. The controller will find an object from those parameters and send down a js.erb file. That js.erb file has a FormBuilder constructor which returns an object that can spit out rails form builder tags for the object. When I call builder.form, I get the html generated by <%= form_for @object do |f| %> <% end %>, and during the call, it also dynamically adds properties to the builder object which will return text_field, text_area, select, and checkbox tags for the attributes of the object (which field it returns depends on the type of the attribute).

This is still in the works. Once it's ready I will post a blog about it and perhaps attach a link to this thread. So far it just spits out a form and some text_fields, but it's working great! For your delete form, you would have to change the method to "delete" in one of the hidden inputs, but other than that, you have a pre-packaged form which is ready to submitOrDeleteWithAjax and use!

Avatar

sorry, everything's here:
http://github.com/plataformatec/devise/wiki/_pages

Avatar

Is it a good fit with other ORMs besides activerecord ?

Avatar

Hi,

Thanks for he screencast!
Just wondering how it's possible to update user's datas like email.
The devise method fails: salt error

Thoughts?

Avatar

It is realy nice.

Avatar

Thanks helmerj for the fix for rails3 .To remove the h() from the method in ApplicationHelper file.

Avatar

For the similar functionality on Rails 2 you can use plugin: http://github.com/dmitry/attr_accessible_block

You actually can use it on Rails 3, but I haven't tried it yet.

Avatar

great, thanks.
will really love to see how this can be done in rails 2 too..

Thanks for all your great work!

Avatar

Does this work for rails 2?

Avatar

(Rails 2.3.9, ActiveMerchant 1.9.0)

The code for the config/environment/development.rb didn't work for me because it would result in a 'wrong number of arguments' exception when my development environment was loading. It seems to have been caused by assigning the Base.mode to true directly.

The solution for me was to set the :test option directly in PayPalGateway.new like I did here:

http://gist.github.com/645751

Avatar

Awesome ryan you actually did an episode about it im sooo happy to see what great use you found for it.

Avatar

@artyomst, thanks for your comment. Now I got it working in Rails 3 :)

Avatar

Everything seems to work except counting conversions. With caching enabled, even though I've excplicitly NOT cahced the action, I only see this the first time, not subsequent calls:

Cache hit: Abingo::Experiment::body_background_white::alternatives ({})
  Abingo::Alternative Update (78.8ms) UPDATE `alternatives` SET conversions = conversions + 1 WHERE (`alternatives`.`lookup` = '5343424bdcd7cc178fb422651f97fb95')

...and the test results don't get updated. Do you know how to prevent that from happening?

Avatar

Note, you need to set config.action_mailer.delivery_method=:smtp
otherwise it will silently "work" in dev and test mode but never actually send email (as the default seems to be :test)