RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

Is there a way to reload the environment like
reload! from IRB ?

Avatar

Thanks for the the great RailsCast, Ryan - as always.

Has anyone figured out if it's possible to use 'binding.pry' for debugging if you're using Apache/Passenger rather than the built-in server?

Avatar

Yes, here is how to replace the rails console with pry

For those that don't like to click links:

ruby
#config/environments/development.rb

MyApp::Application.configure do
  silence_warnings do
    begin
      require 'pry'
      IRB = Pry
      rescue LoadError
    end
  end
end
Avatar

Thanks a lot! I know, I'm a digger, but it's still working! Saved my life. :)

Avatar

Couldn't be more getting Pry right away: am running win764 bit, for some reason, I never can get color highlighting to work ANYWHERE; not even with a freshly installed system following every guide to the dot. If anyone here knows, please please enlighten.

Avatar

Any way to replace the console with pry in 2.3.8 when you run

ruby
ruby script/console

???

Avatar

Hello Ken,
Haven't tried yet. Thanks for letting me know. I will install it now.

Avatar

Great Tip! THX!
It is also worth noting that for this to work gem 'pry' must be in your Gemfile.

Avatar

i get an undefined method:

undefined method page for #<Array:0x109881fa8>

@images = @search.results.page(params[:page]).per(24)

Avatar

WOW !!!!! been using this the whole day.....this is freaking awesome. Just tested it with RC6 rails and Sinatra...I think this is the best day of this month !

Avatar

I have to admit I was disappointed when I saw the topic for this week's railscast. The name and description just weren't what I was hoping for. Each week I look forward to learning a new way to use ruby/rails to solve problems by writing code. Pry was just a replacement for irb "UGH".

THEN . . . I watched it.

Wow. Thank you, Ryan. I'm betting that in less than a week, Pry will have saved me hours worth of time.

Lesson learned: Never judge Ryan's screencasts before watching them.

Avatar

I just set it up using RC6, it seems to be working just fine, is that not the case for you?

Avatar

I have this working with Kaminari, what is the problem you are having?

Avatar

Try:

gem "sunspot_matchers"
gem "sunspot-rails-tester"

Avatar

Is anyone using Pry with Rails 3.1 RC5/RC6?
Thanks.
Bharat

Avatar

thank you Ryan!

finally a tool to see the source code of a method definition!
That was really a feature I missed from Lisp..

Avatar

Joshua Cheek's screeencast is also worth seeing, and includes a neater way to use Pry as IRB replacement for the rails console:

Simply add the following lines at the end of your config/environments/development.rb file, after the YourAppName::Application.configure block:

ruby
silence_warnings do
  require 'pry'
  IRB = Pry
end

And no more need to use the longer pry -r config/environment to start the console: simply use the usual rails console/rails c command.

Avatar

Another great discovery Ryan! Do you know if Pry works with Ruby 1.8.7 or is it just for Ruby 1.9?

Avatar

Anyone else experiencing problems with reloads for 'edit-method' and command line vim ?

It doesn't seem to reload the code after editing (:wq), only after another edit-method (so it looks like vim is handing back control to pry immediately after loading the file, and pry loads the unchanged module, rather than the changed one after save/quit).

Works with nano, though.

Avatar

This is certainly my favorite code excerpt:

```ruby

Avatar

Hi Ryan,

Great cast!
I have a question for you: with 3.1stable coming, do you think that the trick of using an id for a specific controller will be necessary anymore?

thanks and cheers

Avatar

How on earth did you get this gem installed? I'm running into all sort of trouble on OSX Lion. I keep getting stuck on this nokogiri dependency where it complains about missing libiconv. I've followed the directions on the nokogiri site and this guy http://pinds.com/2011/08/06/rails-tip-of-the-day-rails-os-x-lion-rvm-nokogiri/comment-page-1/ but no such luck

Avatar

I would also like to see the tdd in every episode. i also miss in every book and many aricles the tdd style to show also the test style. It looks for me like everybody claim to do testing but nobody show how he do this. For a beginner with rails and testing this would be a good starting point to digg into the secrets of testing.

As you write the test everybody see the what code you write next.

The argument the episode becomes too long is not accepted ;-).

You can speed up things if you not switch always to the test results and not explain what to do next because of the test fail. You should only give a litte space of the screen to the test green dots or error dots (and maybe the importent part of the test fail message). Then you just do write test and implememt code. The log from the specs are shown in the same time at a split screen and do not need explaination.

Avatar

@nathan le Ray you can pull from my github a modified version of albino that allows you to pass options to pygments. https://github.com/austinbv/albino. To use this version of albion in your gemfile just add

ruby
gem albino, :git => git://github.com/austinbv/albino.git
Avatar

Thanks Ryan, for such a great episode. But I have come with a question..?

I would like to have a default check_box button so that all the fields are selected and the ids, are sent through post request. could you guide through...

cheers

Avatar

Great episode Ryan. Routing has been a pet peeve of mine for a long time now.

Hopefully with this episode and some more reading, it will never come back to haunt me in the future.

Avatar

Hello,

I would like to know if there is a way to show the line numbers for the code blocks generated through Albino.

Thanks.

Avatar

Just incase anyone else has my problems, I managed to fix this by removing all previous paperclip plugins and reinstall the gem

Avatar

Hi Matenia,

I think I'm having the same problem as you, how did you fix this? (I know it's ages ago, sorry)

Avatar

I'm following this and it all goes well, image seems to process etc, but when I view the file it has just cropped from the center of the image and not the cropping area :(

Anybody had this? Does anyone have any ideas?

Thanks in advance!

Avatar

Anybody have got this working with rails 3.1? I'm curious because it isn't working in my 3.1 project, it was okay in 3.0.* . The problem is that when I want to type in something in this input area I've got "Searching..." message and no results listed at all, only when text doesn't match database entries I've got "no results" message. I've tried to add some pre data into the database manually, unfortunately in the result i have pre-populated input with "undefinded x" instead of name I wrote to join table. Maybe somebody had similar problem?

Avatar

Anyone faced with this problem?
When I do like this:

ruby
text :comments do
    comments.map(&:content)
end

And then try to destroy article in model of which has line:

ruby
   has_many :comments, :dependent => :destroy

Comments are not deleted!

Avatar

Just FYI, in my 3.1 rc6 app I'm getting
DEPRECATION WARNING: stream class method is deprecated. Please give the :stream option to render instead.

Avatar

I guess what you mean is: "how do I include /admin.js alongside my general CSS stylesheet in the admin view in a single file ?"

Your JS files aren't supposed to be regenerated every request, and won't in production - so I would discourage using Donnie's solution.

The only solution is to include your 'screen' stylesheet in your admin stylesheet and include only the 'admin' stylesheet in your layout like Dmytrii suggested.

Avatar

Use the rails-dev-tweaks gem and you have your speed back. ;-)

Avatar

Heroku precompiles assets for you during push, in the cedar stack. However, it is broken for 3.1 rc6, They are working on fixing it.

About the read only file system:

"Cedar offers an ephemeral writeable filesystem. You can write out to disk anywhere you would like. Your changes will be lost on dyno restart and spin-up."

From: http://devcenter.heroku.com/articles/read-only-filesystem#cedar

Avatar

Hi!

Great screencast! You should probably link to the current asset pipeline docs on github. There have been a lot of changes to the docs since Ryan posted that page!

Avatar

Ryan,
Thanks for this. I am running into some problems with my functional tests

1) Failure:
test_should_create_user(UsersControllerTest) [/test/functional/users_controller_test.rb:20]:
"User.count" didn't change by 1.
expected but was
.

2) Failure:
test_should_update_user(UsersControllerTest) [/test/functional/users_controller_test.rb:39]:
Expected response to be a <:success>, but was

Avatar

Hey...Anyone else having problems with validations?
Ny solutions?

Avatar

Always a new stuff, thanks Ryan.

Simple Timecop.freeze doesn't work with Oracle db, because:

ORA-01841: (full) year must be between -4713 and +9999, and not be 0

A time must be specified for example Timecop.freeze(DateTime.now)

Avatar

Yeh I'm trying to figure out the same thing

Avatar

I'm not getting the port number in the url when firefox launches (only 127.0.0.1). Do I have to specify the port somewhere?

Avatar

Don't know where in the rails stack this logic is executed, but if there is access to instance variables per request then you could:

  1. Add .erb onto the end of your application.js file => application.js.erb

  2. Do something like:

ruby
<% if @current_user.is_admin? %>
//= require_tree ./admin
<% end %>
Avatar

I just set this up using CanCan for authorization. Works great!

I also added a check in the session controller to make sure the user isn't already logged in when visiting the login path:

ruby
  def new
    redirect_to root_path, :notice => 'You are already logged in.' if session[:user_id]
  end 
Avatar

WOOT! I am very very glad to see my Railscast request was featured! +1 So very useful thanks Ryan!

Also I may have missed it but how does one handle naming conflicts? I'll re-watch...

Avatar

You may want get wildcard to localhost working by

http://hints.macworld.com/article.php?story=2005110220352084&query=launchd+named+localhost

so, it's possible to localhost

my.dev.box.localhost, foo.localhost, so on

thanks for this episode

Avatar

I'm getting the same error, in production. Did you figure it out?