RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

no need to worry, he told via twitter, that "this week's episode will be a bit late". We can "expect it on monday afternoon PST".

http://twitter.com/rbates

I'm so excited about this episode ;)

Avatar

It is unusual though. Does anyone here know Ryan personally? Is everything OK with him, his family etc?

Avatar

@John Doe: yep, I think we should burn Ryan at the stake so the next guy learns the lesson.

Seriously...

Avatar

Why isn't there one for today? It's Monday!!

-Railscasts has failed me.

Avatar

Hi there,

when I added the first line in the config/environment.rb I got an error message saying

/config/environment.rb:6: undefined local variable or method `config' for main:Object (NameError)

not sure why????

Avatar

doesn't work with 11720 records, why?

Avatar

If you don't want to use the middleware for rendering (this might be the case if you want add a custom filename to the send_data method), you can do something like this:

      format.pdf {
        html = render_to_string(:action => "show.html.erb")
        kit = PDFKit.new(html)
        kit.stylesheets << "#{Rails.root}/public/stylesheets/print.css"
        send_data kit.to_pdf, :filename => "Your-custom-filename.pdf", :type => 'application/pdf'
      }

Avatar

why am i getting the following error...

Error: This transaction cannot be processed due to an invalid merchant configuration.

Avatar

To 53:@Batzooh

Thanks for your comment, finally I can let it run on Rails 3.0.0.rc.

But I also notice that you're using raw helper method, which I think is dangerous because any script in the article content will run. It's better to use sanitize helper method.

<%=sanitize coderay(@article.content) %>

Avatar

Yeah, getting Twitter oauth working on Devise is becoming a total pain. Nothing I can find seems to work. Keeping my fingers crossed someone at least updates the documentation for something other than GitHub oauth.

Avatar

Nice gem, Ryan. Simple to use and allows plain ol' Ruby in the access rules. Reminds me a lot of the Aegis gem from Makandra.

Sometimes I prefer to return the proper 403 HTTP code instead of redirecting to the homepage. Here's how, if others want to:

1. Create a public/403.html file
2. Replace the rescue_from statement in ApplicationController with:

rescue_from CanCan::AccessDenied do |exception|
  render :file => "#{RAILS_ROOT}/public/403.html", :status => 403
end

Avatar

In case anyone else is having problems getting this to work with gmail apps, there is a little error in Ryan's demo code. In mail_setup.rb, user_name must be fully qualified, as in user@domain.tld, not just user. In the example, Ryan has
:user_name => "railscasts"
...where it should be...
:user_name => "railscasts@railscasts.com".

Avatar

To have the correct output with Rails 3.0.0.rc replace the following line :

content_tag("notextile", CodeRay.scan($3, $2).div(:css => :class))

by :

content_tag('notextile', CodeRay.scan($3, $2).div(:css => :class).html_safe)
(simply add html_safe)

<%=raw textilize(coderay(@article.content)) %>
(simply add raw)

Avatar

I'd appreciate if you can connect devise to your episode #217 for the signup process.. i need it badly because i've spent much time trying to connect it together

Avatar

Is there any way to define a callback method when for instance each answer is saved?

Avatar

Hate to clog up your comments thread, but there is a small mistake in the code I just posted, the Time.zone methods need to include the .now so it accounts for daylight savings. So, in the previous two posts, always use:

Time.zone.now.formatted_offset & Time.zone.now.utc_offset

Avatar

One last thing I wanted to tell you about the time zone issue I was having. This isn't a major issue, but if you want your highcharts' dates to line up properly, you should do this for the pointStart variable.

pointStart: <%= (3.weeks.ago.beginning_of_day + Time.zone.utc_offset).to_i * 1000 %>

Please let me know if these suggestions are incorrect. Thanks!

Avatar

Love the railscasts, watch them every week. I implemented highcharts over the past few days and wanted to let you (and anyone else interested) know of a snag that I hit with the "orders_chart_series" method. Where you group and select the orders table for the variable "orders_by_day", I had to change :group => "date(purchased_at)" to :group => "DATE(CONVERT_TZ(purchased_at, '+00:00', '#{Time.zone.formatted_offset}'))". Same thing with the :select value. Without this, the records were falling in all utc dates.

FYI, this was all on rails 2.3.8, so maybe rails three does this automatically before executing the mysql statement.

Avatar

Good post.

But
<%= render :partial => 'shared/error_messages', :target => @user %> does not work for me.
I have "undefined local variable or method `target'" error

So I use
<%= render :partial => 'shared/error_messages', :locals => {:target => @user} %>

Avatar

Thanks for infos i hope my Webmaster fix it to my websites

Avatar

Hello its me again

I wanted to tell everyone what went on and how I believe the issue was fixed.
There must have been a dependency I missed and I went back to the video and paused it on the part where you installed the list of packages which I though were more or less optional because I didn't see any thing on the RVM install instructions requiring Rake,Thor,tzinfo,erubies,builder etc. So if anyone else has this problem this is why, pay close attention to all the packages installed in the video. There may be less needed but I felt it was safe to follow word for word to make sure if I had an issue elsewhere.

Thanks anyway

Avatar

Hey guys
I didn't see this specific issue discussed in the comments but I wanted to see if anyone may have experienced what I have.
I get Ruby1.9.2 and Rails 3 installed in separate gemsets and everything goes as expected. But when I run the Webrick server for some reason it segfaults. In the error message the version of Rails is 1.8.7 which is the version I'm running on my system. I also have a dual environment setup under RVM but I suppose since all my versions read correctly at the commandline when running ruby -v, and rails -v. It just seems to be grabbing the wrong Webrick server when running for some odd reason. By the way I'm running Ubuntu 10.04. Again mysetup is Ruby 1.8.7 on my system, then a dual configuration ran under RVM. My understanding from the RVM site is that is the recommended configuration. I tryed the IRC but I think it is saying Wayne is on vacation.
Thanks

Avatar

A followup Devise customisation cast showing how to build your own custom authorisation strategy would be great.

Avatar

@niber: same question.. I was trying f.options[:child_index]

Avatar

@Rolando, zul

add the validate to the user model
app/models/user.rb:

validates_uniqueness_of :username

Best Regards

Avatar

Your railscasts are great !

I still have a problem :
parent model, child model
How can I set automatically some values in child fields il
parent and child objects are new ?

Avatar

@songrit, @Jeremy, @Dominik and other VLC users: you can use the alternate download link for iPod/AppleTV that uses a format VLC seems to render better than the one from the main download link.

@Ryan: maybe can you drop a line to the VLC developers telling them the parameters/codec version you use to encode your latest videos (and the former, if you remember :-) so they can improve their decoder?

Avatar

Suppose you have to assign a "correct" answer through a radio box beside each answer string.

For instance (_answer_fiels.html.erb):

<%= f_question.radio_button :answer_id, f.options[:child_index], :checked => false %>

<%= f.text_field :content %>

--
I can't get the id of the new answer ! Can anyone help me???

Avatar

i think the dom:loaded doesn't work, but i don't know, i'm new in rails, can anybody help me?

Avatar

doesn't work, i have rails 3. javascript file doesn't load.

Avatar

rvm seems to be the future of ruby binary version management. Not sure about the windows users...

Avatar

wow,maybe i should update my rails now

Avatar

ActiveResource Basics is exact what we are looking thanks for the infos

Avatar

If you are using the ruby-debug gem, one of it's dependencies is linecache, a different version of which is required for use with with ruby 1.9.x

using this line in your gem file:
http://gist.github.com/507624

will give you flexibility when you run bundle install, as I found here:
http://isitruby19.com/linecache

Also, this worked for me for 1.9.1, but i still get linecache fail for 1.9.2

Avatar

Thanks Ryan for this geat episode - again :-)

Also thanks @m-ryan for pointing out the 1.9 encoding handling!

Avatar

Thanks for the article.

I am getting the following error when I a ts:index/reindex/config

undefined method 'descendants' for ActiveRecord::Base:Class

I am running OS X 10.5.7,
thinking-sphinx(2.0.0.rc1 5fe4a03), rails 3.0.0.beta4.

Has anyone else got this error? Is there an issue with TS gem working with the rails3.0 version on OS X?

Thanks, Sam

Avatar

@RJ You want to use flash.now instead of flash. Michael Hartl's Rails Tutorial at www.railstutorial.org (free to read online for rails 2.3 and 3, free to download for rails 2.3) talks about it. hope that helps.

Avatar

The juries is not giving point by the taste of the food, but this a competition of designing food. So they will look for a good looking one.

Avatar

Another note about encoding problems related to MYSQL, the current version of the mysql gem driver (2.8.1) sets the encoding of the attributes of your records by default (even if they are in UTF-8)

you can try the mysql2 gem at http://github.com/brianmario/mysql2

or use the fix suggested here :

http://snaprails.tumblr.com/post/556378216/porting-an-application-to-ruby-1-9

I recommend everyone not to overlook this one as it may crash your app when users try to submit non-ascii characters in a form.

Avatar

A quick note about encoding for french / german / russian / japanses, etc... developpers.

By default, ruby 1.9 assumes that all your source files are encoded in ASCII(even if they are in UTF-8) so when you write this in a controller :

  flash.now[:info] = "succès"

you get this error message : invalid multibyte char (US-ASCII)

To fix this you have to tell ruby 1.9 that the encoding is UTF-8 by using a magic comment at the first line of your ruby source files.

I have written a little tool to add magic comments on top of all your ".rb" files easily

gem install magic_encoding

then call "magic_encoding" in the console from your app's directory.

Cheers

You can specify the encoding used as a parameter like so : "magic_encoding Shift-JIS" (for japanese)

Avatar

Might have been useful to show that you can use the "authorize_resource" filter instead of "load_and_auth..". For my particular app I needed to be in control of the loading and it was only after monkey-patching it that I browsed the gem code and saw that I could use the other filter. Lovely gem, made my life easy.

Avatar

Continue from previous comment: Oh, and by the way. In my eyes, the output of rake routes looks good:

http://pastebin.com/LEA2LXpV

Avatar

I have rails Rails 2.3.8 and Devise 1.0.8. I have followed the installation instruction, but when trying to access /users/sign_in for the first time after modified routes.rb, I get

Internal Server Error
undefined method `[]' for :users:Symbol

When I reload, I get

Routing Error
No route matches "/users/sign_up" with {:method=>:get}

If putting map.devise_for :users above other map.s, I get the same kind of routing errors when trying to access for example /artists or /songs.

Am I missing something?

Avatar

Chris C wrote:"Hopefully this will save someone some heartache."

Sure cured it though, let me tell you.
I was doing apt-get install libprawn, but needed gem install prawn, nearly drove me out of my mind!!@#$%^

You da man!

Avatar

@Alexander, Thank you. Totem indeed works fine on Ubuntu.

Avatar

Please either use a different codec or move back to a coded that has been used in previous (pre 190) screencasts. The video has very poor playback on Windows with VLC 1.x

Avatar

@Christian
the #{} is a ruby way to return the content of the code into a string
so
" 1+1=#{1+1} " retorna " 1+1=2 "

the %w[shipping billing confirmation] is another ruby way to define an array of strings. Is the same of ["shipping" , "billing" , "confirmation"]
Hope it helped