Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

ActionController::RoutingError

I'm actually doing the 'one months rails' tutorial. It's an app very similar to Pinterest. You can sign up, login, then create pins which appear on the screen. The pins are images (from your hard drive) with a user-created description.

For reasons I can't fathom, the images are appearing as 'broken images'.

I know I can't give you much to go on here, but I think it might have something to do with this, which is taken from my local server output, when trying to display the /pins page on localhost:3000 :

Started GET "/system/pins/images/000/000/007/medium/10422527_10152801962321280_6218855364325609012_n.jpg%3F1417534282" for 127.0.0.1 at 2014-12-02 19:26:26 +0100

ActionController::RoutingError (No route matches [GET] "/system/pins/images/000/000/007/medium/10422527_10152801962321280_6218855364325609012_n.jpg%3F1417534282"): actionpack (4.1.8) lib/action_dispatch/middleware/debug_exceptions.rb:21:in call' actionpack (4.1.8) lib/action_dispatch/middleware/show_exceptions.rb:30:incall' railties (4.1.8) lib/rails/rack/logger.rb:38:in call_app' railties (4.1.8) lib/rails/rack/logger.rb:20:inblock in call' activesupport (4.1.8) lib/active_support/tagged_logging.rb:68:in block in tagged' activesupport (4.1.8) lib/active_support/tagged_logging.rb:26:intagged' activesupport (4.1.8) lib/active_support/tagged_logging.rb:68:in tagged' railties (4.1.8) lib/rails/rack/logger.rb:20:incall' actionpack (4.1.8) lib/action_dispatch/middleware/request_id.rb:21:in call' rack (1.5.2) lib/rack/methodoverride.rb:21:incall' rack (1.5.2) lib/rack/runtime.rb:17:in call' activesupport (4.1.8) lib/active_support/cache/strategy/local_cache_middleware.rb:26:incall' rack (1.5.2) lib/rack/lock.rb:17:in call' actionpack (4.1.8) lib/action_dispatch/middleware/static.rb:84:incall' rack (1.5.2) lib/rack/sendfile.rb:112:in call' railties (4.1.8) lib/rails/engine.rb:514:incall' railties (4.1.8) lib/rails/application.rb:144:in call' rack (1.5.2) lib/rack/lock.rb:17:incall' rack (1.5.2) lib/rack/content_length.rb:14:in call' rack (1.5.2) lib/rack/handler/webrick.rb:60:inservice' /home/ubuntu/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/httpserver.rb:138:in service' /home/ubuntu/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/httpserver.rb:94:inrun' /home/ubuntu/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'

Here's a link to the repository: https://github.com/Yorkshireman/pinteresting

A bit of a long shot, I know, but if anyone can give me some pointers about how to check whether the image exists and how to check the routes are setup properly for it, it would be much appreciated.

I originally posted my answer as a comment. Please see below for the answer.

Thanks

2 Answers

Hi Andrew,

The problem is being caused by a recent bug in Paperclip.

In your Gemfile, you are using the newest version of Paperclip. I would recommend you use a stable release.

Gemfile.rb

gem 'paperclip', github: 'thoughtbot/paperclip'

Becomes

gem "paperclip", "~> 4.2"

Then run bundle install and restart your server. Everything should work.


If you want to continue using the latest version of Paperclip, the easiest fix seems to be the following:

Create a file at config/initializers/paperclip.rb

Paperclip::Attachment.default_options[:use_timestamp] = false

Source: http://stackoverflow.com/a/27159036/1369730

The bug is causing the timestamp parameter to be encoded. In other words, the image URLs should have a question mark instead of %3F

/system/pins/images/000/000/007/medium/10422527_10152801962321280_6218855364325609012_n.jpg?1417534282

Thanks so much, Jesse! It worked!

I kept the recent version of paperclip and used that fix. I'm not sure it's the best plan, but it works. The other fix works too - I tried both.

When I try to get this part working on Heroku, I suspect I might end up using the other fix (reverting to an older version of paperclip).

Neither fix worked to make the existing pins work, but both fixes work with new pins, so I just destroyed the old pins.

Now I have a screen full of Scarlett Johansson photo pins to brighten up the darker coding moments. Thanks again!

(tried to mark it as best answer, but the option hasn't appeared yet - I will when I can)