RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

Someone know how can I set intersections?

Avatar

@Kevin you could solve the problem?! I thin that we have the same issue, because when i update the picture, i got a blank screen, it doesnt take me to crop.html.erb. When i refresh that blank screen i got the new updated picture. Could you help me please?

Thanks in advance!

Avatar

Here's another way to work with Google Maps: jquery-ui-map - a jQuery plugin.

http://code.google.com/p/jquery-ui-map/

Avatar

I was wondering the same thing. Both look like they are done well but GeoKit seems like its been around a lot longer than Geocoder, but I could be wrong.

Avatar

What's the difference between Geocoder and GeoKit? I've used GeoKit before and found it very good.

Avatar

Keep in mind that doing geocode server side is not a best practice.
Google API limit is 2500 req/day (and decrease every year :))
Should be done client side with plugin like this: https://github.com/sgruhier/jquery-addresspicker

Avatar

ah, ok, yes I see that now, thanks!

Avatar

Same here, any luck solving the issue?

Avatar

Not sure why, but I can't get this to work unless I accept an argument in the mass_assignment_authorizer method located in the initializer. If I do it like the below everything works.

def mass_assignment_authorizer(a=nil)

Perhaps this has changed in Rails 3.1.0.rc4..

irb(main):011:0> Rails.version
=> "3.1.0.rc4"

Thanks for this post Ryan.
Mark

Avatar

FAYE_TOKEN isn't in the source javascript. It's a token used on two backend servers which communicate between each other. The end user never sees, sends or intercepts that communication.

Avatar

Killer preso, as always. Beyond the obvious stellar info on Resque, the pointer to the pygments syntaxer was a great take-away for me. Thanks, Ryan.

Avatar

Anyone figure out what this problem is?

I'm running rails 3.0.9, ruby 1.8.7, with passenger.

Avatar

Kaminari is also SEO-friendly! Add a route like this:

resources :products do
  get 'page/:page', :action => :index, :on => :collection
end

And Rails will automatically rewrite your URLs to be SEO-friendly! Instead of /products?page=32, you'll have a nicer URL - /products/page/32. Because of this, you can also leverage on some page-caching techniques if your index isn't updated frequently.

Avatar

Awesome as usual! Thx. Have you tried deploying your app in production mode under RC4 ? Everything worked exactly the same for me under development but when I switched to production I got this error with web brick:

Processing by ProjectsController#index as HTML

Rendered projects/index.html.erb within layouts/application (24.4ms)
Compiled app/assets/stylesheets/application.css (1ms) (pid 45323)
...

Compiled app/assets/javascripts/projects.js.coffee (116ms) (pid 45323)
Completed 500 Internal Server Error in 377ms

and finally:

ActionView::Template::Error (uninitialized constant JSON::ParserError
(in /opt/nginx/apps/todo/app/assets/javascripts/application.js)):
3:
4: Todo
5: <%= stylesheet_link_tag "application" %>
6: <%= javascript_include_tag "application" %>
7: <%= csrf_meta_tags %>
8:
9:
app/views/layouts/application.html.erb:6:in _app_views_layouts_application_html_erb__2079688217135001494_17202399760'
app/controllers/projects_controller.rb:7:in
index'

Avatar

Fantastic intro, we just started using resque and I was going to have to learn it the hard way. But then you show up with a great screencast and now I get to take a long lunch. :)

Thanks Ryan!

Avatar

No need for lvh.me in development if you are using Pow. It handles subdomains automatically.

Avatar

Ryan has an example of setting the subdomain to false in the show notes. You can use it like this.

= link_to "terms", terms_path(:subdomain => false)`
Avatar

Is there a ruby alternative to pigments? Seems strange to use a python library.

Avatar

I too can verify this problem exists with the code Ryan. The outputted code looks like the following for me.

html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> 
<html><body> 
<p>This is a <strong>markdown</strong> enabled text</p> 
 
<div class="highlight"> 
<pre><span class="nb">puts</span> <span class="s2">"Hello World"</span> 
</pre> 
</div> 
</body></html>

Using Nokogiri 1.4.6

Avatar

I'm getting the same error. I hope u still remember how did u overcome with this problem...

Avatar
  1. Please who can i specify the path for scss files and the related css path for the compiled file ? in rails 3.0.7

  2. How can use sass manualy to generate css files when i was in for exemple in Appcontroller ? which steps should i have to follow to do this with sass (Rails 3.0.7)

Thanks a lot :)

Avatar

Again, Just awesome, and Just in time.???

Avatar

Wow! This rocks! I was getting tired of will_paginate, especially not knowing if at any point the rails3 branch was going to screw up on me. I definitely recommend Kaminari over will_paginate any day! And it's not any harder to implement either......

Avatar

If you are on Windows, the solution for the 'identity' issue its to create a paperclip.rb in the initializers folder and type:

require "paperclip"

Paperclip.options[:command_path] = 'C:\ImageMagick-6.7.0-Q16'
Paperclip.options[:swallow_stderr] = false

Obviously check for the path where you installed the ImgMagick and the version, mine its 6.7.0 and worked fine in a x64 system...

Avatar

@Paolo, Heroku can't use pygments.

Avatar

Hi Jeroen,

You can run your selenium tests on a server without a GUI in background by using a virtual frame buffer called Xvfb. There you will find usage information.
Hopefully I helped you. :)

Botond

Avatar

Thanks Ryan.

Is it possible to use pygments on Heroku?

Avatar

Last night I've done some testing on an Ubuntu installation with the same results. I've modified the Nokogiri part so it will (hopefully) work on both installations. I've used the DocumentFragment class of Nokogiri.

ruby
def syntax_highlighter(html)
  doc = Nokogiri::HTML::DocumentFragment.parse(html)
  doc.css("pre[@lang]").each do |pre|
    pre.replace Albino.colorize(pre.text.rstrip, pre[:lang])
  end
  doc.to_s
end 
Avatar

I am getting the following error in my log when i try and use ruby block...

ActionView::TemplateError (No such file or directory - posix_spawnp)

Any ideas why? or how to fix?

:D

Avatar

Thanks for your screen.

A Markdown TextEditor with markitup and redcarpet ,support rails 3

https://github.com/ZhangHanDong/rails_markitup

Avatar

Use BCrypt::Password.create() instead of BCrypt::Engine and the library takes care of the salt for you:

ruby
def create(secret, options = { :cost => BCrypt::Engine::DEFAULT_COST })
  Password.new(BCrypt::Engine.hash_secret(secret, BCrypt::Engine.generate_salt(options[:cost]), options[:cost]))
end

http://bcrypt-ruby.rubyforge.org/classes/BCrypt/Password.html#M000007

Avatar

Another great cast. You have an uncanny ability to cover topics as I need them. I got RedCloth going this morning, but upon seeing this cast I will be switching ASAP. Thanks Ryan!

Avatar

This last part starts redis in the foreground?

Maybe my Ubuntu config is disagreeable somewhere.

Avatar

It works fine here, the only difference is I'm using libxml version 2.7.8. Perhaps try updating libxml, I know nokogiri has had issues with some past versions

Avatar

If I use rails c with Nokogiri::HTML("<p>content</p>").to_s

it will output: "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">\n<html><body><p>content</p></body></html>\n"

I'm using Nokogiri version 1.4.6, maybe it's something with the libraries Nokogiri uses?

When I give the /Library/Ruby/Gems/1.8/bin/nokogiri -v command I get:

warnings: []
ruby:
engine: mri
version: 1.8.7
description: ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
platform: universal-darwin10.0
libxml:
loaded: 2.7.3
binding: extension
compiled: 2.7.3
nokogiri: 1.4.6

Avatar

That is very strange, it is not behaving this way for me. Maybe it's a different version of Nokogiri, what version are you using? I am using 1.4.6 in the screencast.

Avatar

I prefer not to add these kinds of abstractions until I need them. Usually if I need to customize the options it will be to add or remove one option which will cause a lot of duplication. I think this kind of abstraction would be better, but too much to show in the episode.

ruby
def markdown(text, options = {})
  options.reverse_merge!(
    :hard_wrap => true,
    :filter_html => true,
    :autolink => true,
    :no_intraemphasis => true,
    :fenced_code => true,
    :gh_blockcode => true,
  )
  options.reject! { |k, v| !v }
  syntax_highlighter(Redcarpet.new(text, *options.keys).to_html).html_safe
end

Then you pass true/false options hash to modify the defaults. But the point is there are different ways to abstract this out, and we can't tell the best way without seeing how it needs to be customized.

Avatar

Hello Ryan,

Thanks for the screencast! When I use your example or the source code Nokogiri inserts HTML headers to the output of the syntax_highlighter method. I've fixed it by modifying the last line of that method.

ruby
def syntax_highlighter(html)
  doc = Nokogiri::HTML(html)
  doc.search("//pre[@lang]").each do |pre|
    pre.replace Albino.colorize(pre.text.rstrip, pre[:lang])
  end
  doc.at_css("body").inner_html.to_s
end

Why is it that the output in the screencast is different?

Avatar

actually I needed to replace FolderRef.tiff, the old one is out of date, for those who use Snow Leopard... and @Ryan all your screencasts are great! :)

Avatar

@Ainars Same old icon? Not sure if you're referring to how Ryans drawer looks like, but he's using the TextMate MissingDrawer plugin.

Ryan, thanks for the plug. Create episode as always!

Avatar

Hi Ryan and all,
how can I get in my textmate to show up new folder icon, I've tried everything I still get the same old icon, I'm using TM 1.5.9

Avatar

I think Ryan just wanted to demonstrate a basic helper so he didn't do it the way you described. Of course, yours is much more flexible than Ryan's version.

Avatar

How come you didn't do something like this? Was there any reason?

ruby
def markdown(text, options = nil)
  options ||= [:hard_wrap, :filter_html, :autolink, :no_intraemphasis, :fenced_code, :gh_blockcode]
  syntax_highlighter(Redcarpet.new(text, *options).to_html).html_safe
end
Avatar

Hi, this was fantastic but when pasting the code to add a question, I get a missing partial error! Taking out the following gets rid of the error??

<%= link_to_add_fields "Add Item", f, :questions %>

Avatar

Hi Ryan, and thanks fpr the nice 'cast. As I used it everything went well..

But now, I am writing a server API call for the iPhone that will allow a user to log in via their email and password and return the auth_token, in the event that it gets "lost" (ie. new iPhone, app gets un-installed, etc) so that the app can store it in the device for authentication, where we normally pass

www.mydomain.com?auth_token=blah-blah

for all of the authentications on the calls we make

In rails remote API call:

user = User.where(:email => data['email'], :password =>
data['password']).firstuser = User.where(:email =>
data['email'], :password => data['password']).first

I need to "intercept" the Devise hidden controllers to be able to post the remote login call to my server and RETURN the authentication_token as the API response so that it can then be stored in the mobile device and used for subsequent
calls.

Does anybody have any ideas how I might do this?

Thanks,

Bill

Avatar

I get the layout, but intermittently. Some refreshes don't request the style.css file for some reason. Not sure what's going on--has that happened to you at all Ryan?