RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

I wanted a more compact log file, with additional information (timestamp and log level, for instance), and more control over colorization. Since none of the existing logging plugins did quite what I wanted, I wrote one. It's here:

https://github.com/bmc/grizzled-rails-logger

It works with the existing ActiveSupport::BufferedLogger, instead of replacing it, so it should still work with new features like tagged logging.

Comments and criticisms are welcome. And, of course, feel free to adapt, hack, or otherwise steal.

Avatar

nice episode, but the problem that the last second or something gets cut off from the video is still there (all videos so far)

Avatar

Very nice episode. I bought the subscription just to watch it, and it didn't disappoint. Keep up the good work!

Avatar

Thanks for that information, Glenn. You said "should suffice" — did you have a chance to test that theory? Does it work?

Avatar

Just in case someone is interested to know, in Ubuntu versions 11.10 (Oneiric Ocelot) and onwards the "admin" group is not going to be provided by default. The power that be are favouring the "sudo" group instead of "admin" group. If you're upgrading from a lower version, your "admin" group will persist but on a fresh install "admin" group will be missing.

So if you get an error that "admin" group does not exist, simply replace it with "sudo".

adduser deployer --ingroup sudo

Avatar

After applying :primary => true, I am getting this error

console
ritesh-ranjans-MacBook-Pro:learnbooksignup riteshranjan$ cap deploy:setup
./config/deploy.rb:28:in `load': compile error (SyntaxError)
./config/deploy.rb:23: syntax error, unexpected ':', expecting kEND
    task command, roles: :app, except: {no_release: true} do
                        ^
./config/deploy.rb:23: odd number list for Hash
    task command, roles: :app, except: {no_release: true} do
                                                   ^
./config/deploy.rb:28: syntax error, unexpected ':', expecting $end
  task :setup_config, roles: :app do
                            ^
        from /Library/Ruby/Gems/1.8/gems/capistrano-2.12.0/lib/capistrano/configuration/loading.rb:172:in `load_from_file'
        from /Library/Ruby/Gems/1.8/gems/capistrano-2.12.0/lib/capistrano/configuration/loading.rb:89:in `load'
        from /Library/Ruby/Gems/1.8/gems/capistrano-2.12.0/lib/capistrano/configuration/loading.rb:86:in `load'
        from /Library/Ruby/Gems/1.8/gems/capistrano-2.12.0/lib/capistrano/configuration/loading.rb:86:in `each'
        from /Library/Ruby/Gems/1.8/gems/capistrano-2.12.0/lib/capistrano/configuration/loading.rb:86:in `load'
        from Capfile:5:in `load'
        from /Library/Ruby/Gems/1.8/gems/capistrano-2.12.0/lib/capistrano/configuration/loading.rb:172:in `load_from_file'
        from /Library/Ruby/Gems/1.8/gems/capistrano-2.12.0/lib/capistrano/configuration/loading.rb:89:in `load'
        from /Library/Ruby/Gems/1.8/gems/capistrano-2.12.0/lib/capistrano/configuration/loading.rb:86:in `load'
        from /Library/Ruby/Gems/1.8/gems/capistrano-2.12.0/lib/capistrano/configuration/loading.rb:86:in `each'
        from /Library/Ruby/Gems/1.8/gems/capistrano-2.12.0/lib/capistrano/configuration/loading.rb:86:in `load'
        from /Library/Ruby/Gems/1.8/gems/capistrano-2.12.0/lib/capistrano/cli/execute.rb:65:in `load_recipes'
        from /Library/Ruby/Gems/1.8/gems/capistrano-2.12.0/lib/capistrano/cli/execute.rb:65:in `each'
        from /Library/Ruby/Gems/1.8/gems/capistrano-2.12.0/lib/capistrano/cli/execute.rb:65:in `load_recipes'
        from /Library/Ruby/Gems/1.8/gems/capistrano-2.12.0/lib/capistrano/cli/execute.rb:31:in `execute!'
        from /Library/Ruby/Gems/1.8/gems/capistrano-2.12.0/lib/capistrano/cli/execute.rb:14:in `execute'
        from /Library/Ruby/Gems/1.8/gems/capistrano-2.12.0/bin/cap:4
        from /usr/bin/cap:19:in `load'
        from /usr/bin/cap:19
Avatar

would be useful to have the Gemfile in the user notes as well

Avatar

I am on windows and i am getting the following error when i tried to sign up

"NoMethodError in UsersController#new

undefined method `key?' for nil:NilClass"

I am using rails 3.2.3

Avatar

I've built a more colorful formatter. This code might be not optimized yet, since I didn't investigate the type of severity (nor did I for Logger::Severity::DEBUG and friends).

Maybe you'll find it useful, too ;-)

log_formatter.rb
class Logger::SimpleFormatter
  # from activesupport/lib/active_support/core_ext/logger.rb
  def call(severity, time, progname, msg)
    "#{severity_color severity} #{String === msg ? msg : msg.inspect}\n"
  end

private

  def severity_color(severity)
    case severity
    when "DEBUG"
      "\033[0;34;40m[DEBUG]\033[0m" # blue
    when "INFO"
      "\033[1;37;40m[INFO]\033[0m" # bold white
    when "WARN"
      "\033[1;33;40m[WARNING]\033[0m" # bold yellow
    when "ERROR"
      "\033[1;31;40m[ERROR]\033[0m" # bold red
    when "FATAL"
      "\033[7;31;40m[FATAL]\033[0m" # bold black, red bg
    else
      "[#{severity}]" # none
    end
  end
end
Avatar

Nice and concise - thank you Ryan!

Avatar

Anyone have any tips for testing this thing? If you test the ProductsDatatable class on it's own (rather than testing the results of the products/index controller action) how can you instantiate a view_context on initialization? Or is it best to just rely on mocking/stubbing everything that would normally exist in the context of a normal request?

Looking back to the Presenters from Scratch screencast looks like it might be something like this?

ruby
class ProductDatatableTest < ActionView::TestCase
  test "something or other" do
    datatable = ProductDatatable.new(view)
    # but, how to set the params for the view?
  end
end
Avatar

If I can get some attention or upvotes, you'll help stamp out ruby-debug19 from the Rails Gemfile template https://github.com/rails/rails/pull/5835

Avatar

Give this a try

ruby
:primary => true
Avatar

Sweet! Getting rid of assets requests is a priority for me. Short and sweet; thanks.

Avatar

The simplest method is to copy the app/views/active_admin/devise/sessions/new.html.erb file (you can find it here https://github.com/gregbell/active_admin/blob/master/app/views/active_admin/devise/sessions/new.html.erb) to your application directory, then just make any changes that you might need.

Internally, active admin uses devise, so you can go as far as just doing away with active admin's devise config, by replacing the following code in your routes.rb file.

ruby
  # devise_for :admin_users, ActiveAdmin::Devise.config
  devise_for :admin_users

And updating config/initializers/active_admin as you see fit.

Avatar

Yep your correct. I probably didn't word my question very well.

Since the root user doesn't have access to ssh you cant rsync the files to /var/chef so I have to figure out a work around for that. I don't think enabling the root user is a good option.

Avatar

Thanks man! Saved a lot of time for me.

Avatar

Wow, how have I never learned the t command on github before... Thanks for the tip Ryan!

Avatar

BTW, Ryan, whats up with the end of the video. You started to answer the question of whether or not this will move you off of rspec.

I did the switch awhile back from rspec to riotrb, and got so used to fast tests, I dumped rspec altogether. Then I dumped riotrb for minispec.

Havent looked back

Avatar

Don't test rails internals. Instead do something like

it "must have a products collection" do
  @topic.must_respond_to :products
  @topic.products.class.must_equal Array
  @topic.products.size.must_be :>=, 1
  @topic.products[0].class.must_equal Product
end

In these assertions you verify:

  • The @topic instance has access to the products collection
  • The collection is an array
  • The collection has elements
  • The collection's first element has a class of Product

Always test the expected result, and not the internal mechanisms. Test API and you will find that many of your testing issues vanish.

Avatar

I am using the mongoid data table gem that has a one stop search functionality https://github.com/potatosalad/mongoid-data_table

Avatar

Hello John. Sorry for the late reply, didn't notice your question until now. If it's still a problem, make sure you're actually installing the gem on Heroku. By default, Heroku does not install gems from the assets group in your Gemfile, as they're considered only for development and test. So, if your gem is in the assets group, try moving it out of there and see if the problem persists.

Good luck. :-)

Avatar

thank you but i have a loop :( don't know why

Avatar

Yeah, I've banged my head on it!
Let we know as soon as a fix for that will be available.

By now, I'm using the patch suggested here:
https://github.com/svenfuchs/globalize3/issues/128

Thank you!

Avatar

I know it is rather controversial but I found RubyMine IDE to be a great way to debug rails apps. It has very cool UI for debugger with breakpoints, visual stack and so forth.

Avatar

Hello,

Just a remark on the screencast.

Apparently, you need to use
config.include FactoryGirl::Syntax::Methods
rahter than
config.include Factory::Syntax::Methods

Avatar

Here is the solution, which allows avoid rendering partial into markup. templates become available directly in javascript SMT (shared mustache template) global object.
https://github.com/railsware/smt_rails

Avatar

It would be great if you could show how to use the asset pipeline, but use s3 or rackspace to serve the assets

Avatar

I've just set up a site using the pipeline and SSL - you've got to make sure you use the image_tag helper and protocol relative paths:

http://collectiveidea.com/blog/archives/2010/11/29/ssl-with-rails/

Avatar

Nice 'cast...

Can anyone share an Apache2 config block that directs Apache to serve the static gzipped assets like nginx? The Rails guide is short on the topic...and my skills with setting up Apache config files are not good.

Oh, and there is a good writeup on SO that shows how to package up your assets to serve on a conditional basis (e.g., to specific versions of ie, etc.)

http://stackoverflow.com/questions/7134034/using-rails-3-1-assets-pipeline-to-conditionally-use-certain-css

Thanks!

Avatar

I am also getting the same error. please someone help...

Avatar

After two days of trying to figure out why my app suddenly broke (it used to work before), I found your reply here and I have the exact same issue!

Before this worked:

haml
- for project in @projects.models
  %a{ href: "/project/#{project.get('slug')}" }= project.get('name')

But after some more working on the app, and updating gems (which I suspect broke things), I had to replace it with this to continue working:

haml
- for project in @projects.models
  %a{ href: "/project/#{project.get('project').slug}" }= project.get('project').name

I suspect something changed in a recent Backbone.js update or it has something to do with Rails' include_root_in_json options (but I tried both false and true, no dice).

Avatar

I just released a ruby gem to integrate normalize.css with the asset pipeline.

https://github.com/markmcconachie/normalize-rails

Avatar

Too complicated for a simple app :(

Avatar

A decent number of large users are not using chef-solo and there are definitely approaches that you can take to resiliency with the chef-server infrastructure.

Obviously Engine Yard is one of the poster children of chef-solo but last time I spoke to anyone from over there, they are also still on 0.6.x whereas the rest of the world has largely moved onto much newer releases. They're probably not the best example of a "large scale" user unless your needs marry closely with what they wanted.

Speaking personally, the benefits provided by Search are more than worth any hassle involved in making sure the API calls always get answered!

Avatar

I think Ryan mentioned that you can do that to keep the controller clean. I implemented this a couple of weeks ago, and I wish the screencast came out earlier; I would have followed his suggestion.

Avatar

I'm having a bunch of trouble trying to make this work beyond what has been said on both screencasts.

I'm simply trying to make a full CRUD, like Rails scaffold, just work. But I'm getting bite by loading times and page rendering.

Anybody else having such problems?

Avatar

Got Rails 3.2 here and no problems at all. Maybe this?

Avatar

Asset Pipeline can be a little annoying if additional js/css other than application.{js,css} is required.

For example, with active_admin enabled, config/environments/production.rb needs a little change:

ruby
config.assets.precompile += %w( active_admin.js active_admin.css )

I would like to have this precompile array automatically set, but no good solution yet.

Avatar

Why do you create a Class when you can create the json in the respond_to block? For example:

ruby
respond_to do |format|
  format.html
  format.json do
  render :json=>{
    "iTotalRecords"=>@products.count,
    "iTotalDisplayRecords"=>@products.count,
    "aaData"=>@users.as_json(
      :only=>[:name, :category, :released_on, :price]
    )
  }
  end
end
Avatar

I made a gem to do this a while back -- cuts out most of the heavy lifting: https://github.com/jasondew/data_table

Avatar

THere is a a way to get ruby-debug working on ruby 1.9.3
put this in your gemfile

ruby
source 'http://rubydebug19.s3.amazonaws.com'
gem 'ruby-debug19', :group => :development

I found this at Stackoverflow

Avatar

Great
I have trouble with assets and ssl in production . Anybody knows if is it a known issue?
Nnz

Avatar

Did you figure this out? I'm having the same problem...

Avatar

A note to the readers: If you try to run the sample app using the episode code from github, you will get an error when you click on the "product name" link. This is because the show view is referencing the category model but there is none in the current code base. So just delete the offending lines of code that references the @product.category.name field.

Avatar

In my AWS server I need to use "ubuntu" server instead as the root user is disabled.