SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    NC
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple app - problems w/ routes

    Hello,
    I'm trying to get the backbone of a rails project up and running on localhost and also on a rails playground hosted site.

    On localhost the app runs great and I can call my say/hello w/ either: http://localhost:3000/controller/say/hello or http://localhost:3000/say/hello,

    but when I try this on my rails playground site I get this when I call the say/hello like this: http://erichermann.com/say/hello:

    ActionView::MissingTemplate (Missing template say/hello.html.erb in view path /home/c73mr0ck/railsapp/app/views):
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/template.rb:85:in `raise_missing_template_exception'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/template.rb:78:in `set_extension_and_file_name'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/template.rb:15:in `initialize'

    And I get this when I call the say/hello like this: http://erichermann.com/controller/say/hello:

    ActionController::RoutingError (No route matches "/controller/say/hello" with {:method=>:get}):
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/routing/recognition_optimisation.rb:67:in `recognize_path'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/routing/route_set.rb:384:in `recognize'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/dispatcher.rb:148:in `handle_request'
    ect.


    My controller code looks like this

    Code:
    class SayController < ApplicationController
      def hello
      end
    end
    And my routes.rb code looks like this:
    Code:
    ActionController::Routing::Routes.draw do |map|
      map.connect ':controller/:action/:id'
      map.connect ':controller/:action/:id.:format'
    end
    One thing that could be causing a big problem is that on localhost, my rails version is: Rails 1.2.6

    and on the Rails Playground hosting the version is: Rails 2.1.1

    Any ideas how I can get this to work in both places?

    Thanks,
    Clem

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,269
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)
    My best advice is to develop in the same version you're deploying. If you can't do that, maybe you can "freeze" to the old version to force the online app to run with old files?

  3. #3
    SitePoint Wizard xyuri's Avatar
    Join Date
    Jul 2002
    Location
    Brisbane
    Posts
    1,487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Didnt the template files change their extension a few versions ago or something? Maybe it is looking for a template with the old extension.

    Sorry to be so vague, but I only remember reading something about this a few days ago Hope it is of some use

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,269
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)
    AFAIK, ver 2 still works OK with ".rhtml" files, but ver 3 will not.

    To summarize the problem:

    On "localhost" Rails ver 1.2.6
    http://localhost:3000/controller/say/hello
    http://localhost:3000/say/hello

    Both work, but:

    On "erichermann.com" Rails ver 2.1.1
    http://erichermann.com/controller/say/hello
    http://erichermann.com/say/hello

    There are errors. This "missing template" error suggests a missing file, which could be solved by checking it's spelling and existence. But I have a feeling the actual problem has to do with the routing of actionpack as suggested by the "no route matches" error.

  5. #5
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    NC
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's weird because the first link (http://erichermann.com/controller/say/hello) tries to find:

    say/hello.html.erb

    and my question is what is an .erb filetype?


    Also, I definitely have a routing problem but I thought the most basic routes would cover these standard calls:

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

    I also tried to make direct route to the say controller like this:

    map.connect 'say', :controller => 'say', :action => 'hello'

    but really, I shouldn't have to do this.

    Strange

  6. #6
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,269
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)
    The ".erb" files are "view" files. It is the new extension used in place of ".rhtml"
    AFAIK, there are some parsing differences, but Rails 2 provides backwards compatability, while Rails 3 will not.

    Just a thought, is the only difference between "localhost" and "erichermann.com" the Rails version? You aren't testing localhost in development and erichermann in production are you?

  7. #7
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    NC
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmm - I am definately testing in development locally and on production on the erichermann site. How do I switch between the 2?

  8. #8
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    NC
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Now after a bit of tech support I now get this when I go to: http://erichermann.com/say/hello

    Code:
    Expected /home/c73mr0ck/railsapp/app/controllers/say_controller.rb to define SayController
    /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:249:in `load_missing_constant'
    /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:452:in `const_missing'
    /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:464:in `const_missing'
    and I get this when I go to: http://erichermann.com/controller/say/hello

    Code:
    no route found to match "/controller/say/hello" with {:method=>:get}
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.6/lib/action_controller/routing.rb:1325:in `recognize_path'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.6/lib/action_controller/routing.rb:1315:in `recognize'
    /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.6/lib/dispatcher.rb:40:in `dispatch'
    /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.6/lib/fcgi_handler.rb:168:in `process_request'
    It all seemed so simple at first....

  9. #9
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,269
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)
    The different environments do some things a bit differently, i.e. error traces, caching, and they (should) use different databases. But I imagine your problem lies elsewhere.

    If all you have in your config/routes.rb file is
    Code Ruby:
    ActionController::Routing::Routes.draw do |map|
      map.connect ':controller/:action/:id'
      map.connect ':controller/:action/:id.:format'
    end
    these are the "default" routes.

    The Shovell application (i.e. SitePoint's "Simply Rails 2" http://www.sitepoint.com/article/rails-for-beginners/) has these files in the app/controllers/ folder
    • application.rb
    • sessions_controller.rb
    • stories_controller.rb
    • tags_controller.rb
    • users_controller.rb
    • votes_controller.rb

    and the config/routes.rb file has
    Code Ruby:
    ActionController::Routing::Routes.draw do |map|
    .....
      # Sample resource route (maps HTTP verbs to controller actions automatically):
      #   map.resources :products
      map.resource :session
      map.resources :users
      map.resources :tags
     
      # Sample resource route with options:
      #   map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get }
      map.resources :stories, :has_many => :votes, :collection => { :bin => :get }
    .....
      # Install the default routes as the lowest priority.
      map.connect ':controller/:action/:id'
      map.connect ':controller/:action/:id.:format'
    end
    so the ActionController handles the URL actions, such as ":method=>:get"

    Maybe if you add
    Code Ruby:
    map.resources :say
    ??

  10. #10
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    NC
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the help.

    I tried adding: map.resources :say

    And then got this error message:

    "No action responded to show"

    Very strange?

  11. #11
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,269
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)
    In the shovell app, the stories, tags, and users controllers have show methods defined. And there are corresponding view files.
    Does your say controller have a show method/view?

    There may be too many difference between vers. 1.2.6 and 2.1.1 to "patch" this (the 1 to 2 change indicates "major" changes), but I guess it's worth a try. It will definately provide knowledgeable insight if you have the time. But if you're anxious to get the app into production, you should probably update your localhost version.

    Do your tests pass OK?

  12. #12
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    NC
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Progress,
    I finally just updated my local copy of ruby to 2.1.1. This got me up and running both locally and remotely.

    Now I have a problem w/ my main project. In that project I have frozen rails and also, the environment.rb file sets the rails version to 1.2.6 with this:

    RAILS_GEM_VERSION = '1.2.6'

    The project works for the most part but I am experiencing problems w/ constants being defined and I'm getting errors like:

    Code:
     LoadError in Fan_reach#index
    
    Showing app/views/fan_reach/index.rhtml where line #79 raised:
    
    Expected /Users/zenogill/rubydev/workspace/trunk/app/controllers/fan_reach_controller.rb to define FAN_REACH_CONTROLLER
    Is there any way to check if this project is truly frozen to 1.2.6?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •