RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

I have the same problem with Rails 3.1.3

Avatar

You don't need to remove the Gemfile.lock, just use bundle update. http://gembundler.com/man/bundle-update.1.html

Avatar

We'd probably see a more significant improvement in performance if your action wasn't shelling out. eg. if you just ran some ruby code or returned the contents of a file instead of starting a sub-shell to get the process list.

Thanks for the screencast!

Avatar

Hello every body,

this command line doesn't run any more

ruby
rails new . -d mysql

i have this error

Invalid application name rails, constant Rails is already in use. Please choose another application name.

what is the solution ?

Tx a lot

G

Avatar

Great idea and well presented as usual Ryan...

Title was a little misleading though :/

Avatar

Thanks Ryan. Your videos are amazing! I also published my first gem called API Key Maker. Check it out at RubyGems.org.

Avatar

Is the following change justifiable?

from:

faqs_controller.rb
def sort
  params[:faq].each_with_index do |id, index|
    Faq.update_all({position: index+1}, {id: id})
  end
  render nothing: true
end

to:

faqs_controller.rb
def sort
  Faq.transaction do
    Faq.connection.execute("SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE")
    params[:faq].each_with_index do |id, index|
      Faq.update_all({position: index+1}, {id: id})
    end
  end
  render nothing: true
end

Ref: http://rhnh.net/2010/06/30/acts-as-list-will-break-in-production

Avatar

Good episode!

Do you think you could explain how this might work with nested objects. My images belong to a subsidiary object and I can't figure out how to crop them.

Can you help?

Avatar

I never knew that you could use underscore (_) to retrieve the last returned value in the console. Nice trick! (See the video around 2:23).

http://rubyquicktips.com/post/342527837/console-tip-retrieve-the-last-return-value-with

Avatar

humm, not sure about default, what if just choose one!

Avatar

@Alexander Zubkov, thanks a lot for posting your module! I tried it out and it works! My preference though, is not for max+1 but max of a particular set +1. So I used your module as inspiration, but ended up doing this manually as follows.

edition_content.rb
class EditionContent < ActiveRecord::Base
  before_save :set_position

  protected

  def set_position
    self.position ||= 1 + (EditionContent.where('edition_id=?',edition_id).maximum(:position) || 0)
  end
end

This works just as I want, but I wonder if there's a way to make this into a module! You'd have to be able to tell the callback method (set_position) which column (in this case "edition_id") to use in the where clause. I'm too new to RoR to be able to figure this out. Any suggestions?

Avatar

Thanks for this.

small update, i dont think one needs to store the OpenID information anymore.

config/initializers/omniauth.rb
provider :google_apps, :domain_name => 'your_domain_name', :name=>'admin'

Mine just worked fine this way.

Avatar

You mentioned the config.log_tags .. Are these only params passed in via the 'params' hash? I wanted to include in there the method that is being used to output the data to the logger.

For example, if I had a model called 'Foo', I would want the logger to print out "[Foo] blah blah blah".

Is this possible, and if so, do you know where the docs are or how I can do this?

Thanks for the awesome screencast (as always).

Avatar

I recently released a gem which simplifies the whole process of creating site-wide announcement messages. It is called announcements, you can check it out at github:

https://github.com/svileng/announcements

I hope you'll find that useful.

Avatar

Ok so I have found that out:

application_controller.rb
class ApplicationController < ActionController::Base

  def authenticate!
    case request.format
    when Mime::XML, Mime::JSON
      # use http_basic_authentication
    else
      # use form_based_authentication
    end
  end

  #...
end
some_controller.rb
class SomeController < ApplicationController
  before_filter :authenticate!

  #...
end
Avatar

What if I`m using :uuid as POST parameter? Is it going to work?

Avatar

do you know if this works in rails 3.0.3?

Avatar

Had to add the psych gem to my gemfile to get rails 3.2 working with one of my apps for some reason...

Avatar

It's pretty important to note that HTTP streaming doesn't work with HAML: https://github.com/nex3/haml/issues/436

Avatar
ruby
ActionMailer::Base.smtp_settings = {
  :address              => "smtp.gmail.com",
  :port                 => 587,
  :domain               => "mail.gmail.com",
  :user_name            => "yourmail@gmail.com",
  :password             => "secret",
  :authentication       => "plain",
  :enable_starttls_auto => true
}
Avatar

ruby 1.9 thats why lol . Sorry, had to research it on my own :)

Avatar

I would also love to see a video on this.

Avatar

Nice screencast again @Ryan! Maybe I'm late on this but when did the ruby hash MyModel.new(:test => "test1") turn into MyModel.new(test: "test1") . Obviously the latter is more readable/user friendly :)

Avatar

Much thanks to those of you who found the imagemagick ruby 1.9.2 conflict and posted an answer here. Used:

brew install -f imagemagick --disable-openmp

and everything is happen again...

Avatar

This is fine actually. So you should not worry about it too much.

Avatar

I have tested this advanced search method for my application and it's working fine.

My question is how can i implement field calculation in that model?

Example for products models showing here, if i need to have "totals of products selected", "total product's cost" and "average cost", where can i put these calculation methods?

Avatar

I for one would be interested in learning how to handle inbound faxes. :-)

Avatar

Indeed, Rails 3.2 requires rubygems 1.8.15. But JDBC adapters are broken w/ Rails 3.2, see https://github.com/jruby/activerecord-jdbc-adapter/issues/132
If you use JRuby, you'd better keep Rails 3.1 for now

Avatar

It's worth noting that older versions of RubyGems will report an invalid gemspec for rails 3.2.0. You can upgrade RubyGems to address this (gem update --system) or you can wait for 3.2.1, which will fix this. Details here.

Avatar

awesome episode. one very minor nitpick..

When you did:
diff development-middleware.txt production-middleware.txt

you could have done:
diff <(rake middleware) <(RAILS_ENV=production rake middleware)

sub shells have all sorts of uses.

Avatar

It does work!

Just bundle update and make sure you use the git branch as your source:
gem 'mercury-rails', :git => 'git://github.com/jejacks0n/mercury.git'

If you have problems see this github issue:
https://github.com/jejacks0n/mercury/issues/114

Avatar

Publish_to from a controller doesn't seem to work ( States in manual this is possible ) or I misred or I did something wrong.

Say I have

IndexController#Index
PrivatePub.publish_to("/notification", "alert('blablabalabl');")

And in my /app/views/index.erb
<%= subscribe_to "/notification" %>

My understanding was this should publish to the /notifications and push the alert out, but that isn't the case. What am I missing here? Thx for the great gem

Avatar

it doesn't work with mercury-rails yet, any suggestions ?

Avatar

Very useful screencast about upgrading, actually I've tried to do that few days ago and got stuck on dependencies, but I will try again. Thanks a lot!

The solution I did, was removing Gemfile.lock and running bundle install again. But I don't think this is good approach to achieve new version of rails.

Avatar

Great Tutorial.

But I want to know how we can build relavant search engine?

Ex: If we are searching for keyword "beer" if there is not results for the keyword beer it should atleast return relavant results such as "Alcohol","Whisky".

Another Example would be Keyword "mobile phones" it should return results as "Nokia", "Samsung" and so on.

Avatar

Great Tutorial.

But I want to know how we can build relavant search engine?

Ex: If we are searching for keyword "beer" if there is not results for the keyword beer it should atleast return relavant results such as "Alcohol","Whisky".

Another Example would be Keyword "mobile phones" it should return results as "Nokia", "Samsung" and so on.

Avatar

This episode could sure use an update.

Avatar

See this page about performance impacts of adding attaching a handler to window scroll: http://ejohn.org/blog/learning-from-twitter/

Avatar

Thanks Ryan!

3.2 Tip. You should replace

if template.locals.include? :mustache

with

if template.locals.include? 'mustache'

Avatar

Thanks for the amazing material. At $10 a month this is the most valuable development resource I've come across.

If anyone is having trouble getting the checkboxes to save make sure you make your assocation_ids accessible.

Avatar

Can you actually explain what this does (are you copying or symlink?) and why (why separate directory since rails has a place for everything?)? From a beginner experience deploying rails app seems complex. Thanks.

Avatar

Thank you Ryan for this episode. Has anyone used jcrop and carrierwave to mimic how Facbook's does thumbnail . That would be a cool episode maybe a revision of this cast. ;)

Avatar

Hey,

Can I implement Devise in an existing model of an existing application.
I have a Attendee Model with a couple of fields: Name , Email.

Can I use devise for this existing Model ?

Avatar

Hi There!

Is it possible to forward a cookie from the user browsing my site, trough ActiveResource? So that the site in self.site receives the cookie from my user?

Regards,
Nadeem

Avatar

All good, just done what I should do before posting anything...google search.

Found that you can add the option :path => movie_movie_titles_path to the inputs

Thanks!

Avatar

Thanks for the awesome tutorial, just got a bit stuck though.

I am up to the stage of amending my show.html.erb, but when I try reloading the page I am getting...

undefined method `movie_title_path' for #<#Class:0xa16fea4:0xa434a2c>

I am using nested resources which gives me the url /movie/movie_titles/6.

Is there something I am missing?

Thanks!!!

Avatar

Would it be better if before running the migration you add an index for friend_id on the friendships table?