Routing Discrepancy Between Development and Production Environments (Ruby on Rails) - ruby-on-rails

I'm writing an app in Rails (v3.0.5), which I'm deploying to Heroku.
When I visit http://localhost:3000/places/new in my development environment, I'm taken to the appropriate page (the form for creating a new place). Everything works as expected (I can create new places).
When I try to visit the corresponding page (http://example.heroku.com/places/new) in my Heroku production environment, I'm routed back to the home page for my app.
The contents of my routes.db file:
ExampleSite::Application.routes.draw do
resources :users
resources :sessions, :only => [:new, :create, :destroy]
resources :places
root :to => 'pages#home'
match '/contact', :to -> 'pages#contact'
match '/about', :to -> 'pages#about'
match '/signin', :to -> 'sessions#new'
match '/signout', :to -> 'sessions#destroy'
end
What might be a cause for the discrepancy between development and production?
Note: the only actions I've built out so far in my 'places' controller are 'new' and 'create' (both of which perform as expected in the development environment). Not sure that should be relevant, but keep it in mind. Also, all of the 'users' actions and routes seem to be working as expected in both development and production.
EDIT: As noted in the comment below, /places/new is an authentication-protected page, but in both cases I'm trying this while logged in. Also, when I do try to access /places/new in my production environment while not logged in, the appropriate redirect (to my /signin page) works as expected.
My Heroku log from an attempt at getting /place/new:
2011-05-12T23:37:30+00:00 app[web.1]: Started GET "/places/new" for 74.87.126.82 at Thu May 12 16:37:30 -0700 2011
2011-05-12T23:37:30+00:00 app[web.1]: Processing by PlacesController#new as HTML
2011-05-12T23:37:30+00:00 app[web.1]: Redirected to http://example.heroku.com/
2011-05-12T23:37:30+00:00 app[web.1]: Completed 302 Found in 4ms
2011-05-12T23:37:30+00:00 heroku[router]: GET example.heroku.com/places/new dyno=web.1 queue=0 wait=0ms service=9ms bytes=631
2011-05-12T23:37:30+00:00 app[web.1]:
2011-05-12T23:37:30+00:00 app[web.1]:
2011-05-12T23:37:30+00:00 app[web.1]: Started GET "/" for 74.87.126.82 at Thu May 12 16:37:30 -0700 2011
2011-05-12T23:37:30+00:00 app[web.1]: Processing by PagesController#home as HTML
2011-05-12T23:37:30+00:00 app[web.1]: Rendered layouts/_header.html.erb (4.3ms)
2011-05-12T23:37:30+00:00 app[web.1]: Rendered pages/home.html.erb within layouts/application (5.7ms)
2011-05-12T23:37:30+00:00 app[web.1]: Completed 200 OK in 7ms (Views: 3.5ms | ActiveRecord: 5.8ms)
2011-05-12T23:37:30+00:00 heroku[router]: GET example.heroku.com/ dyno=web.1 queue=0 wait=0ms service=14ms bytes=2357

As it turns out, I had a second (forgotten, since I changed the scope of 'users') authentication condition which checked for admin-level status. THAT condition redirected to the home page if the current user was not an admin.
The test user I created in my development environment IS an admin (since I created that user before switching the scope), while the test user I created in the production environment IS NOT an admin (hence the redirect).
Thanks all for your help! While this mistake was an oversight, your suggestions taught me about a few new diagnostic tools I hadn't thought to use.

Related

Heroku Twitter api app deployment with Rails

I am new to Ruby and Rails in general and am following this series
https://gorails.com/episodes/rails-for-beginners-part-38-deploying-to-heroku
I have this weird issue where is everything seems to work fine except connecting my app with
Twitter Api.
I did everything to connect successfully but nothing seems working!
I added the website link to Twitter developer callbacks urls which are
https://jadwlh.herokuapp.com/
along with
https://jadwlh.herokuapp.com/auth/twitter/callback
I added both
API_KEY
and
API_SECRET
to Config Vars.
I even changed SECRET_KEY_BASE in Config Vars
to the one provided in the credentials file in my app!
Even though tried everything, still got this message shown in the image below when I try to
connect my app with Twitter Api
routes.rb file
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
Rails.application.routes.draw do
#GET /about
get "about", to: "about#index"
get "password", to: "passwords#edit", as: :edit_password
patch "password", to: "passwords#update"
get "sign_up", to: "registrations#new"
post "sign_up", to: "registrations#create"
delete "logout", to: "sessions#destroy"
get "sign_in", to: "sessions#new"
post "sign_in", to: "sessions#create"
get "password/reset", to: "password_resets#new"
post "password/reset", to: "password_resets#create"
get "password/reset/edit", to: "password_resets#edit"
patch "password/reset/edit", to: "password_resets#update"
get "/auth/twitter/callback", to: "omniauth_callbacks#twitter"
resources :twitter_accounts
resources :tweets
# get "/", to: "main#index"
root to: "main#index"
end
Application logs
2021-05-31T06:15:04.415968+00:00 app[web.1]: [13f44544-8fd2-4348-8b08-1191ad53716b]
2021-05-31T06:15:04.418156+00:00 heroku[router]: at=info method=HEAD path="/auth/failure?message=session_expired&strategy=twitter" host=jadwlh.herokuapp.com request_id=13f44544-8fd2-4348-8b08-1191ad53716b fwd="217.182.175.162" dyno=web.1 connect=0ms service=3ms status=404 bytes=180 protocol=https
2021-05-31T06:15:31.243002+00:00 app[web.1]: I, [2021-05-31T06:15:31.242901 #4] INFO -- : [c5f8ff8c-58fa-439d-a9f3-e08047bc5aa8] Started POST "/auth/twitter" for 46.152.103.96 at 2021-05-31 06:15:31 +0000
2021-05-31T06:15:31.243645+00:00 app[web.1]: D, [2021-05-31T06:15:31.243583 #4] DEBUG -- omniauth: (twitter) Request phase initiated.
2021-05-31T06:15:31.388564+00:00 app[web.1]: E, [2021-05-31T06:15:31.388453 #4] ERROR -- omniauth: (twitter) Authentication failure! 400 Bad Request: OAuth::Unauthorized, 400 Bad Request
2021-05-31T06:15:31.390962+00:00 heroku[router]: at=info method=POST path="/auth/twitter" host=jadwlh.herokuapp.com request_id=c5f8ff8c-58fa-439d-a9f3-e08047bc5aa8 fwd="46.152.103.96" dyno=web.1 connect=1ms service=150ms status=302 bytes=834 protocol=https
2021-05-31T06:15:31.574904+00:00 heroku[router]: at=info method=GET path="/auth/failure?message=400+Bad+Request&strategy=twitter" host=jadwlh.herokuapp.com request_id=3adfd6f0-58b9-47c3-ab04-017161a56e18 fwd="46.152.103.96" dyno=web.1 connect=1ms service=6ms status=404 bytes=1902 protocol=https
2021-05-31T06:15:31.571195+00:00 app[web.1]: I, [2021-05-31T06:15:31.571067 #4] INFO -- : [3adfd6f0-58b9-47c3-ab04-017161a56e18] Started GET "/auth/failure?message=400+Bad+Request&strategy=twitter" for 46.152.103.96 at 2021-05-31 06:15:31 +0000
2021-05-31T06:15:31.572790+00:00 app[web.1]: F, [2021-05-31T06:15:31.572717 #4] FATAL -- : [3adfd6f0-58b9-47c3-ab04-017161a56e18]
2021-05-31T06:15:31.572791+00:00 app[web.1]: [3adfd6f0-58b9-47c3-ab04-017161a56e18] ActionController::RoutingError (No route matches [GET] "/auth/failure"):
2021-05-31T06:15:31.572792+00:00 app[web.1]: [3adfd6f0-58b9-47c3-ab04-017161a56e18]
Thank you: )
I found the solution.
It just was copying master.key and replace it as it says below!
heroku config:set RAILS_MASTER_KEY="copy and paste here config/master.key "
How to get rails master.key after upgrading to rails 5.2

Heroku throws OpenURI::HTTPError (403 Forbidden):

I have a Rails 4 Application serving up JSON data to a BackboneJS frontend client. The backend scrapes some content from Craigslist and serves it to the frontend as JSON. Locally, in development, it works just as expected.
On Heroku, the application layout does get served correctly and assets seem to load just fine. It isn't until backboneJS queries for data to fill the appropriate view, and there the app fails due to the OpenURI error.
More specifically, OpenURI keeps returning the
OpenURI::HTTPError (403 Forbidden)
when executing the following line in the Rails controller:
open( "#{clist.url}" )
I have spent several hours trying various 'solved' solutions I have found on Stack Overflow and Github and just trying to look through the Heroku logs for other errors, but the error remains no matter which suggested 'solutions' I try out.
As of now, I have tried the following suggested solutions, along with several other silly ones:
Required open-uri in my application controller
Added the 'User-Agent' key to my open method call
Changed the clist.url from "https" to "http" to avoid redirects
Also, the app is straight forward and doesn't require authentication at the moment either.
Apart from Stack Overflow and github, I couldn't find any suggested solutions elsewhere. Any help with any suggestions on other debugging tips to try or suggested solutions would be extremely appreciated. I am fairly new to Heroku, so still getting acquainted with debugging issues like this on a remote production engine.
Here is the relevant code that fetches from Craigslist (don't judge me too harshly. All/Most of this method is set to be refactored and put into it's own Class/Model, which is where it belongs ):
def index
#listings = []
#Retrieve job listings from Craigslist (see method sync_list below ... )
#raw_listings = sync_clist
# filters applied at this point ...
# and they transform #raw_listings to ...
# the array #listings
render json: #listings
end
def sync_clist
##search_items = SearchItem.all
#search_items = SearchItem.all[0..1]
site = #sites[0]
# in the Craigslist HTML, the second element in the returned job listing # is the better one to use
href_idx = 1
##### LINE 123 is the next one:
#search_items.each_with_index do |search_item, idx|
puts "#{search_item.url.upcase}"
##### LINE 125 ... FAILURE_HERE? *****************
html = open( "#{search_item.url}", 'User-Agent' => "Ruby/#{RUBY_VERSION}")
page = Nokogiri::HTML( html.read, nil, 'utf-8' )
category_idx = idx % 4
isNearby_listing = false #also capture 'nearby' jobs on Craigslist
page.css( site[:joblist_css] )[0..-2].each_with_index do |listing, i|
# convert the relative url in the list to a full-url
locale_idx = idx/#clist_locales.length
listing_url = listing.css('a')[href_idx]['href']
# Craigslist only lists the relative path of job urls - relative to the
# current search location. The 'More Local' items, however, return the
# full url.
if !isNearby_listing
posting_url = site[:protocol] + site[:locales][locale_idx] + "." + site[:host] + listing_url
else
posting_url = listing_url
end
# Once the appropriate heading is reached, the 'More Local' listings
# items begin appearing
if listing.next_sibling.node_name == 'h4'
isNearby_listing = true
end
posting_date = listing.css('time')[0]['datetime']
job_listing = { :source => site[:sitename].upcase,
:title => listing.css('a')[href_idx].text,
:url => posting_url,
:listing_id => listing["data-pid"],
:location => #clist_locales[locale_idx],
:content => "",
:telecommute => "",
:contract => "",
:pt_ft => "",
:favorite => false,
:posted_date => posting_date,
:category => #clist_categories[category_idx],
:apply_state => "new"
}
#new_listings << job_listing
end
end
#new_listings
end
Here is the output of my Heroku logs in case it helps:
```
2015-04-27T03:47:14.611278+00:00 app[web.1]: => Rails 4.0.8 application starting in production on http://0.0.0.0:43688
2015-04-27T03:47:14.611280+00:00 app[web.1]: => Run `rails server -h` for more startup options
2015-04-27T03:47:14.611310+00:00 app[web.1]: Started GET "/" for 24.5.106.52 at 2015-04-27 03:47:14 +0000
2015-04-27T03:47:14.611272+00:00 app[web.1]: => Booting WEBrick
2015-04-27T03:47:14.611281+00:00 app[web.1]: => Ctrl-C to shutdown server
2015-04-27T03:47:14.664777+00:00 app[web.1]: Rendered app/root.html.erb within layouts/application (0.5ms)
2015-04-27T03:47:14.661735+00:00 app[web.1]: Processing by AppController#root as HTML
2015-04-27T03:47:14.664783+00:00 app[web.1]: Rendered app/root.html.erb within layouts/application (0.5ms)
2015-04-27T03:47:14.674604+00:00 app[web.1]: Completed 200 OK in 13ms (Views: 12.3ms | ActiveRecord: 0.0ms)
2015-04-27T03:47:14.674612+00:00 app[web.1]: Completed 200 OK in 13ms (Views: 12.3ms | ActiveRecord: 0.0ms)
2015-04-27T03:47:14.611302+00:00 app[web.1]: Started GET "/" for 24.5.106.52 at 2015-04-27 03:47:14 +0000
2015-04-27T03:47:14.661749+00:00 app[web.1]: Processing by AppController#root as HTML
2015-04-27T03:47:15.943141+00:00 heroku[router]: at=info method=GET path="/assets/application-45c34fbd86efe641e061caa3b34737d7.css" host=APPNAME.herokuapp.com request_id=dbf8473e-2880-42f6-8ef4-11e0da7141b4 fwd="24.5.106.52" dyno=web.1 connect=2ms service=73ms status=200 bytes=569692
2015-04-27T03:47:15.944069+00:00 heroku[router]: at=info method=GET path="/assets/application-537f60efd0378faaddaea08875f25055.js" host=APPNAME.herokuapp.com request_id=5c7cf6db-393f-434e-a494-d3664d31a20f fwd="24.5.106.52" dyno=web.1 connect=2ms service=70ms status=200 bytes=965489
2015-04-27T03:47:17.631614+00:00 app[web.1]: Started GET "/posts" for 24.5.106.52 at 2015-04-27 03:47:17 +0000
2015-04-27T03:47:17.631624+00:00 app[web.1]: Started GET "/posts" for 24.5.106.52 at 2015-04-27 03:47:17 +0000
2015-04-27T03:47:17.636842+00:00 app[web.1]: Processing by PostsController#index as JSON
2015-04-27T03:47:17.636831+00:00 app[web.1]: Processing by PostsController#index as JSON
2015-04-27T03:47:17.665568+00:00 app[web.1]: HTTP://SFBAY.CRAIGSLIST.ORG/SEARCH/SOF?QUERY=RAILS
2015-04-27T03:47:18.048174+00:00 heroku[router]: at=info method=GET path="/posts" host=APPNAME.herokuapp.com request_id=a2724fb9-6872-4435-8dfc-0df1b73fb761 fwd="24.5.106.52" dyno=web.1 connect=2ms service=417ms status=500 bytes=330
2015-04-27T03:47:18.042116+00:00 app[web.1]: Completed 500 Internal Server Error in 405ms
2015-04-27T03:47:18.043586+00:00 app[web.1]: OpenURI::HTTPError (403 Forbidden):
2015-04-27T03:47:18.042129+00:00 app[web.1]: Completed 500 Internal Server Error in 405ms
2015-04-27T03:47:18.043590+00:00 app[web.1]: app/controllers/posts_controller.rb:123:in `each'
2015-04-27T03:47:18.043588+00:00 app[web.1]: app/controllers/posts_controller.rb:125:in `block in sync_clist'
2015-04-27T03:47:18.043593+00:00 app[web.1]: app/controllers/posts_controller.rb:123:in `sync_clist'
2015-04-27T03:47:18.043584+00:00 app[web.1]:
2015-04-27T03:47:18.043591+00:00 app[web.1]: app/controllers/posts_controller.rb:123:in `each_with_index'
2015-04-27T03:47:18.043596+00:00 app[web.1]:
2015-04-27T03:47:18.043594+00:00 app[web.1]: app/controllers/posts_controller.rb:53:in `index'
2015-04-27T03:47:18.043597+00:00 app[web.1]:
2015-04-27T03:47:18.043602+00:00 app[web.1]:
2015-04-27T03:47:18.043604+00:00 app[web.1]: app/controllers/posts_controller.rb:125:in `block in sync_clist'
2015-04-27T03:47:18.043603+00:00 app[web.1]: OpenURI::HTTPError (403 Forbidden):
2015-04-27T03:47:18.043606+00:00 app[web.1]: app/controllers/posts_controller.rb:123:in `each'
2015-04-27T03:47:18.043607+00:00 app[web.1]: app/controllers/posts_controller.rb:123:in `each_with_index'
2015-04-27T03:47:18.043610+00:00 app[web.1]: app/controllers/posts_controller.rb:53:in `index'
2015-04-27T03:47:18.043609+00:00 app[web.1]: app/controllers/posts_controller.rb:123:in `sync_clist'
2015-04-27T03:47:18.043613+00:00 app[web.1]:
2015-04-27T03:47:18.043611+00:00 app[web.1]:
```
Taking #TarynEast's suggestion and running app code in the Heroku console, I switched to using the 'net/http' library instead of 'open-uri' to retrieve the Craigslist webpage. The following message was returned by Craigslist when using 'net/http':
"This IP has been automatically blocked.\nIf you have questions, please email: blocks-b1402369961264436#craigslist.org\n"
So, apparently, either all of Heroku IPs have been blocked, or, more likely, it's just my app specifically that has been blocked even though my app only pings craigslist at most 8 times per site load. Maybe that was enough to block it since Craigslist is a very popular target of scraping apps. Anyways, mystery solved as to why the 403 Error. At least app still works locally.
[Update:] According to a quick Google search, Craigslist blocks the entirety of AWS and Heroku IPs, amongst others. See SO question here: Craigslist blocking Heroku/AWS
I had a similar issue when I had a Rails app hosted on Heroku opening a file held on S3. I got the same error because the URL was wrong.

Rails 3: Create a new record by URL

All:
What's the correct syntax for a new record to be created by passing all the parameters inside a URL, not from a Web form?
I'd like a different computer system to be able to concatenate a URL and create new records in my Rails app.
But, when I try to make a new record in "Scores", Rails won't add it.
http://myapp.heroku.com/scores?message_id=51&subscriber_id=167&amount=3&method=post
Where the desired attributes to add to a new scores record are message_id, subscriber_id, and amount.
Here's the Heroku log
2012-01-26T18:27:34+00:00 app[web.1]: Started GET "/scores?message_id=51&subscriber_id=167&amount=3&method=submit" for 122.17.234.171 at 2012-01-26 10:27:34 -0800
2012-01-26T18:27:34+00:00 app[web.1]: Processing by ScoresController#index as HTML
2012-01-26T18:27:34+00:00 app[web.1]: Parameters: {"message_id"=>"51", "subscriber_id"=>"167", "amount"=>"3", "method"=>"post"}
2012-01-26T18:27:34+00:00 app[web.1]: Rendered scores/index.html.erb within layouts/application (3.4ms)
2012-01-26T18:27:34+00:00 app[web.1]: Completed 200 OK in 16ms (Views: 4.2ms | ActiveRecord: 10.6ms)
2012-01-26T18:27:34+00:00 heroku[router]: GET postopmobile.heroku.com/scores dyno=web.1 queue=0 wait=0ms service=55ms status=200 bytes=7605
Here's my Scores model
class Score < ActiveRecord::Base
belongs_to :message
belongs_to :subscriber
end
Scores controller has all the standard Rails CRUD scaffolding, plus this (I'm running Devise):
before_filter :authenticate_user!, :except => [:new, :create]
Lastly, trying method=submit at the end of the above URL doesn't work either.
Any thoughts? I'm trying to figure out if it's just a syntax issue or a deeper Rails create issue.
Thanks.
New records by default in Ruby on Rails are created using POST. If you want to have them created using a GET request (which I would advise against) you need to create a custom route to your create action. For more info on the routes see: http://guides.rubyonrails.org/routing.html.
You need a POST request instead of GET. It will not work with passing 'method' at url.
If you really want to do that, you can add custom route, e.g.:
resources :scores do
get :make
end
Then add 'make' action at controller, which creates new record.
But it's extremely unsafely.

"This website temporarily unavailable" After First Sign-in with Devise

I'm developing a Rails App and am using Devise for authentication. For some odd reason, when my users sign up for the first time, it works perfectly fine, but after signing out and signing in again, the error "This website temporarily unavailable" pops up. This is really bizarre.
I am using the default Devise::SessionsController and the same create method for registration. Does anybody have any idea what's happening? Thanks so much for any help.
In my Application Controller I have the function
def after_sign_in_path_for(resource)
root_path
end
To redirect after sign-ins. Besides this I am using all the default Devise code.
UPDATE:
The error message "Website temporarily unavailable" shows up sometimes after following the link from the email.
Here's the code in the view:
<%= form_for(resource, :as => resource_name, :url => confirmation_path(resource_name), :html => { :method => :post }) do |f| %>
Could this be the source of the problem? Thanks a lot. Just as an aside I'm hosting on Heroku.
I checked the Heroku logs:
This is the result after registering:
Processing by RegistrationsController#create as HTML
2012-01-02T23:22:44+00:00 app[web.1]: Parameters: {"utf8"=>"✓", "authenticity_token"=>"brHjEOxwm4qhkuypmuIUohk0UVg+One8OUx6gsfvmgg=", "user {"email"=>"blah#blah.com", "name"=>"adsfasf", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "isartist"=>"0"}, "commit"=>"Sign up"}
2012-01-02T23:22:44+00:00 app[web.1]: Rendered devise/mailer/confirmation_instructions.html.erb (0.4ms)
2012-01-02T23:22:47+00:00 app[web.1]: Redirected to http://www.artinject.com/
2012-01-02T23:22:47+00:00 app[web.1]: Completed 302 Found in 2963ms
2012-01-02T23:22:47+00:00 app[web.1]: cache: [POST /users] invalidate, pass
And this is the result after sending the mail and clicking the confirmation link:
2012-01-02T23:22:47+00:00 app[web.1]: Sent mail to jw2896#barnard.edu (2755ms)
2012-01-02T23:22:47+00:00 app[web.1]: [paperclip] Saving attachments.
2012-01-02T23:22:47+00:00 heroku[router]: POST www.artinject.com/users dyno=web.1 queue=0 wait=0ms service=2982ms status=302 bytes=91
2012-01-02T23:22:47+00:00 app[web.1]:
2012-01-02T23:22:47+00:00 app[web.1]: Started GET "/" for 69.125.4.183 at 2012-01-02 23:22:47 +0000
Hopefully this helps. It doesn't look like heroku is throwing an error, although it says "Website temporarily unavailable"
I realize now why this was such a mystery. It turns out that GoDaddy was not forwarding my url consistently--sometimes it would properly forward my url and then other times it didn't. This explains why the Heroku logs were not throwing any errors.
Thanks for the responses everyone.

Rails routes with / at the end

Is it possible to change the routes for one resource (at least only show, index) to have / at the end?
For example:
test.heroku.com/books/1/ #the last / will produce an error
Using Rails 3.0.9. Server heroku.com
routes.rb:
resources :books
Error:
2011-08-06T21:41:35+00:00 app[web.1]: Started POST "/books/1/?ref=bookmarks" for 213.229.110.100 at 2011-08-06 14:41:35 -0700
2011-08-06T21:41:35+00:00 app[web.1]:
2011-08-06T21:41:35+00:00 app[web.1]: ActionController::RoutingError (No route matches "/books/1"):
But when I point my browser to
http://test.heroku.com/books/1
is working
http://test.heroku.com/books/1/
is working too.
But if I use:
http://test.heroku.com/books/1/
as a canvas url for a Facebook Application is not working.
Thanks
EDIT Complete ERROR LOG:
2011-08-06T22:07:53+00:00 heroku[web.1]: State changed from starting to up
2011-08-06T22:08:13+00:00 app[web.1]:
2011-08-06T22:08:13+00:00 app[web.1]:
2011-08-06T22:08:13+00:00 app[web.1]: Started POST "/books/1/?ref=bookmarks" for 213.229.110.100 at 2011-08-06 15:08:13 -0700
2011-08-06T22:08:13+00:00 app[web.1]:
2011-08-06T22:08:13+00:00 app[web.1]: ActionController::RoutingError (No route matches "/books/1"):
2011-08-06T22:08:13+00:00 app[web.1]:
2011-08-06T22:08:13+00:00 app[web.1]:
2011-08-06T22:08:13+00:00 app[web.1]:
2011-08-06T22:08:13+00:00 heroku[router]: POST test.heroku.com/books/1/ dyno=web.1 queue=0 wait=0ms service=136ms status=404 bytes=728
2011-08-06T22:08:13+00:00 heroku[nginx]: POST /books/1/?ref=bookmarks HTTP/1.1 | 213.229.110.100 | 904 | http | 404
That wont produce an error if you are making use of the built-in resourceful routing:
resources :books
If you have defined a custom route (perhaps in the process of upgrading a 2.3 app to Rails 3) without accounting for a trailing slash, then you might not be so lucky. If this is the case and you're not sure how to adjust, you should edit your question and add the relevant part of your routing file (config/routes.rb).
Update
Okay so after looking at the log output you posted I see what's happening. Facebook is requesting /books/1/?ref=bookmarks. This is NOT the same as /books/1/, which Rails interprets as actually being a request to the /books/1 resource. Why bother with the trailing slash in this case? It's inaccurate canonically speaking, and clearly it's causing problems.
Update 2
You can add POST /books/1 as a route to the resourceful routes like so:
resources :books do
post '/' => :show, :on => :member
end

Resources