RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

Hi everyone:

If you want to detect if mobile or not, an easier way to do that is define this method in your controller:
Thereafter, you have to call this method with :

before_filter :check_mobile

def check_mobile
if request.user_agent =~ /Android/i
session[:mobile] = true
elsif request.user_agent =~ /BlackBerry/i
session[:mobile] = true
elsif request.user_agent =~ /iPhone|iPad|iPod/i
session[:mobile] = true
elsif request.user_agent =~ /IEMobile/i
session[:mobile] = true
else
session[:mobile] = false
end
end

thereafter your session[:mobile] will have true if you are in mobile and false if you not.

I hope its helpful for you.

Avatar

Monit is cool, but Ubuntu already provide similar monitor features via UpStart and other Linux distro are switching to systemd.

What do you think about the foreman approch, that can be used on heroku and standalone? http://grigio.org/dns_setup_and_procfile_local_development_and_deployment?rc
Foreman already export the ""keep-alive script" towards monit or upstart http://ddollar.github.com/foreman/#UPSTART-EXPORT

Avatar

@ac74394 http://www.youtube.com/watch?v=FkLVl3gpJP4#t=80m12s
DHH goes into Russian doll caching at a recent meetup he teleconferenced in at.

Would be interesting to see Ryan cover it as well but he does a pretty good job explaining how it works.

Avatar

Thanks for these links !
I've experienced big memory leaks with RMagick...

Avatar

Very handy episode! How about one on caching techniques using Memcached, etc? Russian Doll caching seems to be something interesting as well...

Avatar

What is the purpose ||= in ruby?

@current_user ||= User.find(session[:user_id]) if session[:user_id]

Avatar

This isn't valid bundler syntax:

ruby
gem 'jquery-datatables-rails', github: 'rweng/jquery-datatables-rails'

.. but this is:

ruby
gem 'jquery-datatables-rails', :github=> 'rweng/jquery-datatables-rails'

:github is a new-ish feature in bundler.

source

Avatar

You don't have to set them in your app. Do it in your .bashrc or .zshrc file.

Avatar

Is anyone else getting odd behaviour?

For example, when I search 'police' I don't get any results, but when I search 'polic' I do! (Police exists in the content I am searching). It is also not returning some results at all - yet I know the word exists, whether the word is large or small.

When I start rails dbconsole it says I am using 9.1.4, so that seems ok, and the rest of the site seems to be functioning as usual too.

Do I need to rebuild indexes or something? Can anyone suggest anything else?

Avatar

Ryan, this is not my thumbnail from github, in fact I don't know who this is... could my thumbnail be refreshed?

Avatar

A good alternative to RMagick if your needs are just resizing: https://github.com/seattlerb/image_science

Avatar

Pushing off processing to a background task using DelayedJob seems like a worthy experience!

Avatar

Thanks -- I am aware of the episode's show notes. I was referring to the code that Ryan submitted to Rails Rumble. That's not included in the show notes!

Avatar

Thanks Roland - they look like good options!

Avatar

It would be interesting to see other options covered in the future.
Maybe:

https://github.com/jcupitt/ruby-vips
https://github.com/eltiare/carrierwave-vips

can finally help to replace ImageMagick…

Avatar

David,

Excellent, thank you for that.

Avatar

Henk,

One think I learned, from watching a nodejs presentation actually (http://tv.adobe.com/watch/max-2011-develop/nodejs-and-you/) is that nginx is non-blocking whereas Apache is. The presenter covers this with a slide and illustration pretty early on, but nginx accepts the browser request, hands it to unicorn, then takes the next one whereas (he explains) Apache waits until the request is finished.

Avatar

Out of curiosity, how are you compiling your coffeescript from text mate? The rails gem doesn't include a coffee command line utility as far asI can tell, so I get an error when trying to run the coffee command from TM (not a path issue, as "which coffee" results in a blank). Did you install this separately? Any conflicts?

Avatar

+1. nice alternative. Still prefer the endless scrolling feature for image heavy sites. So much easier to handle.

Avatar

Static footers...if you really want it.

Avatar

Some people use pop-ups rather than going to another page. That seems to work fine. But if you really need to go to another page, then I'm not sure. I'll try this tonight.

Avatar

Does anyone know how to use Geocoder with Ransack?

Searching within a certain area, etc?

Avatar

Sometimes I am having with asset pipeline not get reloaded and the code itself.
It happend when I use this zero-downtime restart also regular restart.

To solve it I need to: cap unicorn:stop; sleep 10; cap unicorn:start

Has onyone encountered this?

Avatar

I used the method below to generate page previews of uploaded pdf files.

system "convert -verbose -density 150 #{file_path}[#{from_page}-#{to_page}] -quality 100 #{output_file_path}.png"

HIH

Avatar

Can we have subsheets under worksheet in axlsx? Let me know.

Avatar

Hmm. This worked, but the image came out with severe decrease in quality. But thanks very much for sending me in the right direction.

Avatar

I will definitely look into it. I seem to remember prawn was more of a pdf generator than converter, but I'll take a second look. :)

Avatar

There's a link to the show notes to the left of the 'Comments' button.

Avatar

This is great, Ryan! Your stamp project looks really neat! Is the code available? If so, can you link to the show notes?

Avatar

great episode Ryan! It's good to see the powerful features of imagemagick used in a real world situation as opposed to just being listed.

Avatar

I made a Heroku Buildpack for Monit: https://github.com/k33l0r/monit-buildpack

Of course Heroku limits what you can do with it, but at the very least you can use it to monitor your sites and external services…

Avatar

Is it really a good practice to have a default version? There seems to be a big risk in not forcing clients to make a conscious decision on which API version to support since changing the default version will invalidate all clients accessing the API via the default route.

Avatar

I'm using Mini Magick, partly because of reported problems with Rmagick and because Rmagick didn't play nicely on my set-up.

Avatar

yes, thanks, and if you want to use it with pagination, for me it works like this:

ruby
def self.search(search)
    if search
      where('label LIKE ?', "%#{search}%")
    else
      where('label LIKE ?', "%#{}%")
    end
  end

but later I refactor it to scope

ruby
scope :search, lambda { |search| where("label LIKE ?", "%#{search}%")}
Avatar

Hello, also you can use such scope:
scope :search, lambda { |search| where("label LIKE ?", "%#{search}%")}

as the result query you will have objects which can be paginated also, and it will not crash even if "search" will be nil.

Avatar

Try this from the command line

convert -size 300x300 doc.pdf doc.jpg

Change the size and file names to suit.

Credit StackOverflow

Avatar

Thanks for this episode
(the link to your Dad's website doesn't work)

Avatar

Riding the wave of the subject, could talk, in a forthcoming episode, about progress bar upload. How about?

Avatar

Awesome stuff, Ryan, as usual. Btw, does anyone know of an easy way to manipulate pdfs, specifically to create a jpg of a pdf? I tried with minimagick with no success.

Avatar

How to use subsheets in a worksheet. Any idea?

Thanks

Avatar

Nice man that works a treat

This worked for postgre on Ubuntu 12.04

  task :install, roles: :db, only: {primary: true} do
    run "#{sudo} add-apt-repository ppa:pitti/postgresql",:pty => true do |ch, stream, data|
         if data =~ /Press.\[ENTER\].to.continue/
        #prompt, and then send the response to the remote process
        ch.send_data(Capistrano::CLI.password_prompt("Press enter to continue:") + "\n")
      else
        #use the default handler for all other text
        Capistrano::Configuration.default_io_proc.call(ch,stream,data)
      end
    end


    run "#{sudo} apt-get -y update"
    run "#{sudo} apt-get -y install postgresql libpq-dev"
  end
Avatar

Fullcalendar is very, very good. I've used it quite a bit.

Avatar

Hi! I started with the code from this screencast, switched it to ModestModel to remove the persistence, and then moved over to Mongoid. Just wanted to say thanks!

Avatar

No one mentioned it, but if you sent type="date" HTML5 compatible browsers will give you a datepicker without any need for javascript.

Avatar

Thank you very much for those suggestions, Nik and Luis. I really appreciate the pointers. I personally really don't find a slider to be a very effective input tool for time. I could live with 3 selects (12-hour, minute, am/pm) or just text entry (like Basecamp's current event entry interface), but integrated into the datepicker. I'll keep looking. The hint from the Kalendae developer that time is in the works is encouraging. I hadn't been aware of that project, so thanks for the link!

Avatar

What I like in this gem is ActionController::API which is a bit lighter than ActionController::Base.

What I don't like in this gem is everything else.

If you want to create an API application with some HTML admin panel, you either need to use "normal" Rails and rely on ActionController::Base, possibly stripping it somehow, or use "rails-api", but reenable nearly everything. Both approaches suck. Too bad spastorino haven't decided to include ActionController::API in Rails (or maybe that was impossible) and make "rails-api" nothing more than configuration generator.

I prefer to use Grape mounted in routes, so I get nice DSL behind decent Rails middleware.

Avatar

Hi Ryan. Has this changed at all in rails 3? My attr_accessor does not seem to be passing in the true/false value of the variable I set in the controller. I've tried everything and am beginning to think my problem might have to do with changes in Rails. Something is being blocked. Its such a simple thing...it driving me NUTS that its not just working!

THANKS!