RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

I'm just stoked about learning about defaults on namespaces in the routes...

Ruby
     namespace :api, defaults: {format: 'json'} do

that's a great tip.

Avatar

Hi Ryan,
thanks for this Railscast, loving zsh.

But I would certainly add a note regarding Railscast #66 Custom Rakes. You need to add this in the .zshrc file:

alias rake="noglob rake"

I was using zsh for a while when I first needed to use a custom rake command with parameters I had built. I couldn't figure what was wrong and it took me a while to see that it was not an error in the rake file.

Thanks
Fred

Avatar

And the solution is download and install the 64 bit version binary Python installer from Python.org website. Here is the direct download link

Avatar

Hi Ryan,

I tried the sample source code but it gives me this error. I hope you mentioned it in the notes or comments to other users to benefit.

bash
Could not open library '/Library/Frameworks/Python.framework/Versions/2.7/lib/libPython2.7.dylib': dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/libPython2.7.dylib, 9): no suitable image found.  Did find:
        /Library/Frameworks/Python.framework/Versions/2.7/lib/libPython2.7.dylib: no matching architecture in universal wrapper
  (in /Users/pnhoang/Developer/rails_casts/railscasts-episodes/episode-207/revised/highlighter-after/app/assets/stylesheets/pygments.css.erb)
Extracted source (around line #5):

2: <html>
3:   <head>
4:     <title>Code Highlighter</title>
5:     <%= stylesheet_link_tag    "application", media: "all" %>
6:     <%= javascript_include_tag "application" %>
7:     <%= csrf_meta_tag %>
8:   </head>
Rails.root: /Users/pnhoang/Developer/rails_casts/railscasts-episodes/episode-207/revised/highlighter-after


Application Trace | Framework Trace | Full Trace
app/assets/stylesheets/pygments.css.erb:1:in `evaluate_source'
app/views/layouts/application.html.erb:5:in `_app_views_layouts_application_html_erb__1083987171434567478_2162751440'
Avatar

+1. Would like to see an introduction to emberjs using rails.

Avatar

1st look at meteor - awesome! Second look, forget it. sass does not seem to work at all, you can't customize twitter bootstrap as there is no way to customize what files are loaded in what order, ... I try it again in some years... screencast great as always!

Avatar

Not being a Rails Expert, why did you wrap the different API Versions in a Module rather than just using a controller?

Avatar

If I'm not mistaken this allows a blank password (and confirmation) to be submitted when resetting the password, because in this case the validates_presence_of :password is only called on creation of a user.

Avatar

have you tried using
validates_presence_of :password, on: :create

Avatar

Check your request's headers. You might see this, for example, if you're sending Accept headers to set the version but your API is routing based on path.

Avatar

Meteor looks awesome! I would love to see another screencast on meteor, perhaps with more advanced concepts

Avatar

For those of you having problems with mini_magic, this worked for me:

ruby
  def crop
    if model.crop_x.present?
      resize_to_limit(600, 600)
      manipulate! do |img|
        x = model.crop_x
        y = model.crop_y
        w = model.crop_w
        h = model.crop_h
        img.crop "#{w}x#{h}+#{x}+#{y}"
        img
      end
    end
  end
Avatar

The problem with the default is it will accept any mime type, as it will only check the boolean and not the string:

@default || req.headers['Accept'].include?("application/vnd.example.v#{@version}")

I mean, if we're expecting "application/vnd.github.v1", it will also accept "application/vnd.twitter.v1"

Avatar

I think the later is what we are talking about. the former is abandoned.

Avatar

Thanks Ryan for the examples. Some clients will use multiple Accept header values when they expect to live in mixed environments, so it would be good to put the default version higher in the routes (in the version I read just now, it looks like a client sending v1 and v2 in the Accept header will get v1).

Not sure how you would efficiently use the q parameter (i.e. Accept: application/vnd.myapp+json;v=2;q=1.0,application/vnd.myapp+json;v=1;q=0.9), as ideally the server would select the most-preferred client version that it also supports, but that seems like a lot of overhead just to get strict correctness.

Avatar

The video always cuts off at the last moment.

Avatar

great! how soon do you think this could happen? we are currently thinking in doing it and I wonder if we should wait for your cast...

thanks a lot for all the great videos!

-cristobal

Avatar

Can anyone tell me how this kind of frameworks handle file uploads, since ajax upload is not standardized?

Avatar

I enjoyed the introduction to Meteor.

I think Opa, http://www.opalang.org is another option to look at that is equally mind-blowing and perhaps more mature than Meteor.

Avatar

Great video. I got a subscription just to see it.

One big question: How can I pass extraParams? I need to pass another id with the term and can't seem to get it to work.

Avatar

pg_ctl start before running your rake task.

Avatar

I have a problem when running my tests.
Everytime I try to
rake db:test:prepare I get
PG::Error: ERROR: type "hstore" does not exist

I'm not able to run my tests now :(

Avatar

Do you have any recommendations for handling errors using the correct content type within an API namespace? For example if you 404 by POSTing to /api/products/1 instead of using a PUT, you get the Rails HTML 404 page in the response because the route does not match. Same goes for 500 errors if they ever happen.

Would be nice to get a JSON response for all requests in the namespace.

Avatar

It's really up to you. But we handle the single master, multiple slave setup out of the box for both PostgreSQL and MySQL. All you need to do is add a machine with the appropriate slave role (e.g., postgresql_slave) and it'll auto-configure it for async streaming replication from your master. The config is all generated in your project though, so if you want to change to streaming replication, for instance, just modify the generated file and you're good to go.

Avatar

No, Meteor is still in very early development. It's API changes frequently and also I believe the whole DB is exposed to the client. I'm not 100% sure about the last one though.

Avatar

Was just looking for a solution while testing a portion of an application which uses google's geocoding service. We're limited to the number of geocoding requests we can make, so I turned to VCR.

I'd swear my reading comprehension is good until I attempt to read a README (no offense intended, Myron).

This screencast had me up and running moments after watching. Thanks much, Ryan and Myron!

Avatar

Ryan, thanks so much for recording this episode. Last week I worked in something similar. Just one thing, I would pass the version as a mime type parameter. Something like:

curl -H "Accept: vnd.myapp+json; version=2"

Here's my implementation.

Avatar

This worked for me as well, thanks! :)

Avatar

I'm keen to understad which of these rich application frameworks would be best suited for developing HTML5 mobile apps. How well do they work with offline storage and automatic synchronisation?

Avatar

I love that you expose me to new technologies that I may never have checked out in my frenzy to get my work done. I'm a far more well rounded developer thanks to you.

Avatar

I am hoping to cover authenticating/authorizing an API soon. Thanks for the suggestion.

Avatar

Does anyone know a good technique for auto-generating API documentation?

Avatar

Fixed, thanks for bringing this to my attention.