RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

@house9 if you like this shortcut, you can always try to use alt + left or alt + right, it should works on most browsers, anyway focus could be alt+s or just "s" like on the github

Avatar

Seems that instead of using

ruby
format.json { render :json => @authors.map(&:attributes) }

we can set

ruby
self.include_root_in_json = false

in the needed model.

Avatar

I am really unhappy with coffee script. At least they left the opportunity to write JavaScript manually as is.

Avatar

I was wondering: to load all the "controller specific" javascripts in the app.js file is really a good idea? I mean, if you have a large application you'll be probably overloading your page with useless traversing, events or conditionals to check wether a script must be executed on this page. I think this is a high price to pay, don't you? You can cache JS files, but you can't cache the execution.

Usually I keep all my libs and global scripts in the app.js file, and if I need any extra JS for a specific request I load a custom file containing just the action's JS. This last file is usually really small, simple and as a side-effect my code gets less prone to conflicts because this script is somewhat isolated from the rest of the application.

I think a "per action" js loading approach would be welcome!

Avatar

I'm having the same problem as @gaaady where you make an AJAX call (click on Comments), then hit browsers' back then hit forward (or vice versa), it just shows the JS. I have the exact same problem with my AJAX-heavy site, and I'm clueless, it can't differ between XHR and HTTP requests. Doesn't appear to happen in browsers that don't support history pushstate

So if you do find a fix for this.. it would be awesome to put this in a railscast or a gist! Thanks for all you do Ryan!

Avatar

Hmm I'm not noticing this on Chrome 11 OSX?

Avatar

Same here, I had a similar problem with my AJAX-heavy Rails app. For some reason it doesn't think it's an XHR request, prrretty sure it has something to do with the Javascript History pushstate, as it doesn't appear to happen in browsers not supporting it, Opera for example

Avatar

Great rails cast!

Wanted to try it out for the deep nesting, but ran into some trouble with a lack of a JavaScript runtime (ExecJS::RuntimeError). Any recommendations on a runtime for Ubuntu Linux?

Avatar

I think I found a bug.
1. click on comments
2. click back in the browser
3. click forward

Instead of the page I see some javascript.

Avatar

I'm using the latest stable chrome.
it also happens with chrome angry birds btw

Avatar

I just installed latest version on my mac, but it seems that it doesn't work properly. No rspec output on console, and some file edits doesn't trigger rerun of the specs... For the moment I'll remain with autotest, at least it works...

Anyway the idea is pretty awesome for other tasks (livereload, passenger and some else)

Avatar

My fork works with ActsAsTaggableOn and allows NEW entries

https://github.com/joemsak/jquery-tokeninput

Avatar

i appreciate the reply but my problems haven't been that i have been unable to access images from css(or scss) files, but rather, using image_tag helpers in my views. for some reason, the image tag helpers don't seem to function properly on the beta apps i've been playing around with. but that could be because i am running off of windows. i have no idea why this is the case, to be honest.

Avatar

it's sort of a fascinating bug, actually. because it only seems to happen if you comment twice in a row, in which case, the second comment appears above the first, but when looking later, it seems that my later comments appear below my initial one, so it may be a javascript thing.

Avatar

Thank you so much!!!

I also had troubles with RMagick, but when I replaced

gem "rmagick"
with
gem "mini_magick"
in the Gemfile

and

include CarrierWave::RMagick
with
include CarrierWave::MiniMagick
in /uploaders/image_uploader.rb

everything worked great!

Avatar

hi Rayn the rvm you mentioned first for my windows command promt does not work for rails installer on windows. Checked your new railscast source code to see how you did your tree comment system via ajax and tried mine but my "link_to :remote => true" does not work via ajax and im using jquery-rails. pls any hint would be great

Avatar

no please don't auto focus on input boxes - for people who use the backspace/delete key to 'go back' this is a killer. I've got nothing against auto focus to a text box for a signup page or login page. maybe a short cut key alt+s or something for the search box?

the site does look great!

Avatar

how do find mutual friends as well as indifferent people?

https://gist.github.com/968648

this is my attempt as of now. i'm thinking of using a collect maybe to loop through one set first but there but be a better option.

Avatar

I don't know if this is solved. You can put the index.html.erb (last part of the video) inside lib/templates/erb/scaffold/

Avatar

Yeah the old look kind of grows on you. This new one will be much more engaging though and helpful. So many new formats to download the videos in, plus this excellent comment thread for helping one another without getting confused as to who is replying to who.

Avatar

Hi ryan, it would be nice if you set focus on the search input, on the main page.

Avatar

Yeah! design is good and all works pretty seems like a mantra (which is ok) but... The old one was much clearer! This new brand one looks like a huge-machine which may gobble you and all your code... :) But still thank you for your work. We rally appreciate that!

Avatar

Coming to this 12 months later, but did want to pitch in with having tried this, I found it better to store the current step in the form, not the session, to prevent refreshes behaving oddly.

However, I see Si Wilkins posted the same 9 months ago - what's more the code snippet he linked to showed me a couple of tidyups I hadn't thought of either !

Highly recommend adding these tweaks onto the end, for anyone else following this approach, as aside from a slightly invaded model object, you do get a nice wizard approach without needed to learn a new framework library addon (not that I've found one of them for Rails3 yet)

Avatar

I'm with Ryan on this one. Even though for..in is "unfashionable," it's more expressive and easier to type. That's a good combination.

The only reason I've heard for why people don't use it is because (other) people don't use it.

Avatar

This is what happened when I try to install it in Rails 3.0.7 and Ruby 1.9.1

$ rails g client_side_validations:install
/usr/local/lib/ruby/gems/1.9.1/gems/execjs-0.3.3/lib/execjs.rb:32:in runtime': Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeError)
from /usr/local/lib/ruby/gems/1.9.1/gems/execjs-0.3.3/lib/execjs.rb:44:in
module:ExecJS'
from /usr/local/lib/ruby/gems/1.9.1/gems/execjs-0.3.3/lib/execjs.rb:3:in <top (required)>'
from /usr/local/lib/ruby/gems/1.9.1/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in
require'
from /usr/local/lib/ruby/gems/1.9.1/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in <top (required)>'
from /usr/local/lib/ruby/gems/1.9.1/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in
require'
from /usr/local/lib/ruby/gems/1.9.1/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in <top (required)>'
from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/runtime.rb:68:in
require'
from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/runtime.rb:68:in block (2 levels) in require'
from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/runtime.rb:66:in
each'
from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/runtime.rb:66:in block in require'
from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/runtime.rb:55:in
each'
from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/runtime.rb:55:in require'
from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler.rb:120:in
require'
from /home/liboc/code-depot/qa-reg/TRAP/trunk/config/application.rb:7:in <top (required)>'
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/commands.rb:15:in
require'
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/commands.rb:15:in <top (required)>'
from script/rails:6:in
require'
from script/rails:6:in `'

Avatar

Thanks Ryan. Really brilliant and so very, very, very usable in every day life again as are all of your webcasts.

Sorcery is beautiful Noam. Thanks! Will use and fork asap.

Avatar

Thanks for the great screencast as usual, Ryan!

One question about 3.1, does anybody know how the new asset directory structure and workflow operates in a read-only environment like Heroku? I'm currently using jammit and jammit-s3 to package and minify all my assets and send them to S3 on deploy. Is there a better solution with 3.1?

Avatar

Great screencast, as usual! I'm considering A/Bingo for our own A/B testing purposes, and was just wondering if it's still people's preferred framework (after - possibly - Vanity), or have any other players entered the Rails A/B testing market in the 12 months since this railscast was first aired? Thanks!

Avatar

Thanks for compiling all the changelog info into one comprehensive list -- very helpful!

As for the new design:

  • I'll miss the old intro / music :) -- people already
    associate it with "RailsCasts" ... I wouldn't change that.

  • Everything is easily accessible -- great job!

Could you add the category tags for each episode into the "snippet" overview? Perhaps to the right of the "Watch Episode" button?

Avatar

How can I deploy it to heroku together with my rails app? Anyone did it?

Avatar

Thanks for reporting this. I'll look into fixing this problem.

Avatar

Thanks for the feedback guys. For the logo I went with an arcade style design to give it a techno and fun feel. I realize it's not everyone's kind of style but I encourage you to give it some time and it may grow on you.

I'm open to other design ideas throughout the site, so if you have specific suggestions on how the design can be improved please let me know.

Avatar

Very excited to try it out. Thanks for the great episode!

Avatar

Try this (note the quotes around the condition):
validates_presence_of :company_id, :if => "new_company_name.blank?"

Avatar

The 'images' folder is in the /app/assets directory. One thing to note though is that when Sprockets compiles, everything is then in a flat directory. From your stylesheets, you just need to call the url('image.jpg') and not url('../images/image.jpg'). If you have subdirectories in your images folder, you would do url('subdirectory/image.jpg') instead of url('../images/subdirectory/image.jpg').

Hope this helps anyone who is confused why their images aren't showing.

Avatar

You can still use transactional fixtures if you do the following in your spec helper file:

ruby
ActiveRecord::ConnectionAdapters::ConnectionPool.class_eval do
  def current_connection_id
    # Thread.current.object_id
    Thread.main.object_id
  end
end

As per:

http://blog.yakitara.com/2011/03/use-transactionalfixtures-with-capybara.html

Avatar

I think the new design is superior is terms of usability, navigation and a number of other ways.

On the purely aesthetic and artistic level, it's poorer than the previous one and could be so much better.

What would be needed is to keep the same organization and structure but have a pure designer changing the overall look, logo, etc.

BTW I'm also a huge fan of Ryan and his Railscasts so please take it as a constructive criticism.

Avatar

I must say, as much as I love the new design, I think I'm going to miss the old one :(

Anyway, I can't wait for Rails 3.1, and it looks like it might come out just in time for my next project!

Avatar

I got a big crash when I tried to resize to the thumbnail... I'm running RMagick 2.13.1 with ImageMagick 6.6.2-10:

~/.rvm/gems/ruby-1.9.2-p136/gems/carrierwave-0.5.3/lib/carrierwave/processing/rmagick.rb:248: [BUG] Segmentation fault
ruby 1.9.2p136 (2010-12-25 revision 30365) [x86_64-darwin10.7.0]

...

Will try MiniMagick

Avatar

Simple.

Tell Compass config file where your assets are, after copying your scss files to app/assets/stylesheets

Avatar

Yikes! Ryan I am a huge fan of RailsCasts, but I have to say the old design was SO much cleaner and beautiful. From the comments it looks like other people like the new design - I am really surprised. The new logo is just....wow.

Avatar

I am wondering how Compass framework will stack up with the new SASS.

The most handy thing about compass I use now is:
compass .

which compiles all the SCSS files and places them under public/stylesheets

Avatar

Fantastic site and episode! it's a pity that dreamhost doesn't support ruby 1.9.2 & c.
i suggest a topic for an episode handlebars-rails. a cool way to have html partials which work server and client side

Avatar

oh and, Ryan, like the new design, but i just realized that my newer comments appear above my older ones when i post to a comment twice which may be sort of confusing. may be worth looking into?

Avatar

you can also manually create an images folder in the public folder (which i've tried) but again, that seems to defeat the point.

Avatar

Ryan, love the casts. You are a stellar teacher.

Hadis, I'm a bit confused about this point as well. I can see that an images folder is generated in the assets folder, from which I inferred was now the default directory for images, but image_tag helpers don't seem to connect properly, though when I substitute image_path, the directory structure seems to work. It's a bit odd. Even more strange is the fact that when images are routed through css (or scss) files, they do seem to default to the 'assets/images' folder. Temporarily, I've fixed it by appending the entire path starting from root, but it is very un-rubylike and sorta annoying.

Avatar

Well, that makes sense but if you do that you should make a more obvious/additional link to this area. The title link isn't that obvious. Maybe place a second button to the right of the watch button to get to the show notes, comments etc... ?

On second thoughts, make the button to this area the first button and the watch button the second button. I think new visitors might take a long time to find this area if it were the other way round.

Avatar

@Ryan thanks for you amazing screencasts. I have some questions related to Rails 3.1:

1) Is the 'images' folder in rails 3.1 still in the 'public' folder or did this also change?

2) How can i convert my rails 3.0 apps to a rails 3.1 app? Do i need to do it manually (if yes, how?) or is there maybe an automatic conversation tool like we had for rails 2.x to 3.x?

Avatar

Confused - when adding the client_side_validation plugin and updating the 'sign-up' form, Devise already has a 'form_for' method installed on this page. How do you get them both to work together as it keeps throwing up errors? Is daisy-chaining an option?

Sign Up

<%= form_for @users, :validate => true do |f| %>

Devise Plugin
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>

<%= devise_error_messages! %>

<%= f.label :email %>
<%= f.text_field :email %>