Topic: deployment with rest routes

Hi all hope someone can help me out here as i am nearing the final straw.

The story so far.

I finished my app on local machine (mac os x) then dived into the thick waters of deployment. I am hosed on http://www.hostingrails.com/ shared hosting and i went thought there tutorial and uploaded everything. Now only one page worked which was my links page, which was www.site.com/links so :controller index.

Then i relised i had not uploaded my routes file so i did that and everything went to application error rails did not start up. I then did script/about on my local machine and i was using rails 1.2.2 so i froze that version on the server using this command (just incase anyone need it as well)

[~/railsapp]# rake rails:freeze:edge TAG=rel_1-2-2

Then I did script/about on the server and checked everything was the same and it was (just to note you can only get script/about to work if you have a development db written in the database file)

so now all but two of my pages work and guess what one is the only page that worked the first time, my links page.

So using the log files i have narrowed it down to this link

<img src="<%= url_for( :action => 'code_image', :id => link.id) %>" />

and the method is in there (i got this from a very helpfull tutorial on this forum)

def code_image
    @image_data = Link.find(params[:id])
    @image = @image_data.data
      send_data (@image,  :type     => @image_data.content_type,
                          :filename => @image_data.name,
                          :disposition => 'inline')
  end

Now there is another few links on another page that crash which are also un RESTfull url links.

Log error

Processing LinksController#index (for 62.37.150.167 at 2007-04-30 14:53:28) [GET]
  Session ID: 2f4cee9d21cfaca9d5049fc6383a9a9a
  Parameters: {"action"=>"index", "controller"=>"links"}
Rendering content_typetext/htmllayoutfalseactionindex within layouts/default
Rendering links/index


ActionView::TemplateError (No route matches {:id=>"1", :action=>"code_image"}) on line #5 of app/views/links/index.rhtml:
2: <p>We are here to help and you can contact us about anything at any time however sometimes we cant answer questions like "whats the weather going to be like tomorrow" so we thought of some of the most useful websites that can answer them.</p>
3: <% for link in @links  %>
4: <div class="link_item">
5: <a href="<%= link.url %>" title="<%= link.title %>"><img src="<%= url_for( :action => 'code_image', :id => link.id) %>" /></a>
6: <h3><%= link.title %></h3>
7: <p><%=h link.description %><br />
8: <%= link_to 'Go to ' + link.title, link.url %>

    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/routing.rb:1266:in `generate'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/url_rewriter.rb:104:in `rewrite_path'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/url_rewriter.rb:69:in `rewrite'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/base.rb:522:in `url_for'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/helpers/url_helper.rb:27:in `send'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/helpers/url_helper.rb:27:in `url_for'
    #{RAILS_ROOT}/app/views/links/index.rhtml:5:in `_run_rhtml_47app47views47links47index46rhtml'
    #{RAILS_ROOT}/app/views/links/index.rhtml:3:in `each'
    #{RAILS_ROOT}/app/views/links/index.rhtml:3:in `_run_rhtml_47app47views47links47index46rhtml'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:326:in `send'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:326:in `compile_and_render_template'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:301:in `render_template'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:260:in `render_file'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/base.rb:806:in `render_file'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/base.rb:738:in `render_with_no_layout'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/base.rb:863:in `render_without_layout'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/base.rb:798:in `render_action'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/base.rb:748:in `render_with_no_layout'
    #{RAILS_ROOT}/vendor/rails/activesupport/lib/active_support/deprecation.rb:43:in `silence'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/base.rb:747:in `render_with_no_layout'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/layout.rb:244:in `render_without_benchmark'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:50:in `render'
    /usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:50:in `render'
    #{RAILS_ROOT}/app/controllers/links_controller.rb:7:in `index'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/mime_responds.rb:167:in `call'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/mime_responds.rb:167:in `respond'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/mime_responds.rb:161:in `each'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/mime_responds.rb:161:in `respond'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/mime_responds.rb:105:in `respond_to'
    #{RAILS_ROOT}/app/controllers/links_controller.rb:7:in `index'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/base.rb:1095:in `send'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/base.rb:1095:in `perform_action_without_filters'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/filters.rb:632:in `call_filter'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/filters.rb:638:in `call_filter'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/filters.rb:438:in `call'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/filters.rb:637:in `call_filter'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/filters.rb:619:in `perform_action_without_benchmark'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:66:in `perform_action_without_rescue'
    /usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:66:in `perform_action_without_rescue'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/rescue.rb:83:in `perform_action'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/base.rb:430:in `send'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/base.rb:430:in `process_without_filters'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/filters.rb:624:in `process_without_session_management_support'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/session_management.rb:114:in `process'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/base.rb:330:in `process'
    #{RAILS_ROOT}/vendor/rails/railties/lib/dispatcher.rb:41:in `dispatch'
    #{RAILS_ROOT}/vendor/rails/railties/lib/fcgi_handler.rb:168:in `process_request'
    #{RAILS_ROOT}/vendor/rails/railties/lib/fcgi_handler.rb:143:in `process_each_request!'
    #{RAILS_ROOT}/vendor/rails/railties/lib/fcgi_handler.rb:109:in `with_signal_handler'
    #{RAILS_ROOT}/vendor/rails/railties/lib/fcgi_handler.rb:142:in `process_each_request!'
    /usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.7/lib/fcgi.rb:612:in `each_cgi'
    /usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.7/lib/fcgi.rb:609:in `each'
    /usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.7/lib/fcgi.rb:609:in `each_cgi'
    #{RAILS_ROOT}/vendor/rails/railties/lib/fcgi_handler.rb:141:in `process_each_request!'
    #{RAILS_ROOT}/vendor/rails/railties/lib/fcgi_handler.rb:55:in `process!'
    #{RAILS_ROOT}/vendor/rails/railties/lib/fcgi_handler.rb:25:in `process!'
    dispatch.fcgi:24


Is there anyone out there that can shed some light on this or has had the same problem. I am thinking its something to do with the routes i have

map.resources :links

in there.

anyway thanks in advance.

Re: deployment with rest routes

You need to mention any custom actions in the routes file. Try this:

map.resources :links, :member => { :code_image => :get }

Then you would link to it like this:

<img src="<%= code_image_link_path(link) %>" />

Railscasts - Free Ruby on Rails Screencasts

Re: deployment with rest routes

Hay thanks very much I seem to be getting somewhere.

One question though why does it work on my machine?

Re: deployment with rest routes

Just to reply to my own question i had un commented the last route of

map.connect ':controller/:action/:id'