2012-04-01 8 views
0

現在、実稼働環境で実行しているRuby(1.8.7)on Rails(3.0.9)アプリケーションを取得しようとしています。しかし、実稼働環境に移行する際には、私のルートに大きな問題があります。たとえば、私のコードで私はProduction Rails 3 RouteがDevelopmentと同じに動作しない

user_path() 

呼ばしかし、生産で、私はそれが

users_path(user) 

どちらで使用されている場合を除き、動作しているようだ

users_path() 

にそれを変更しなければなりませんでしたURLを生成します。

http://whatwillworkforme.com/users?format=myuser 

開発は次のようになります。

http://whatwillworkforme.com/users/myuser 

私のルートは以下のとおりです。私はSmartrプロジェクト(https://github.com/dkd/smartr)のコードを使用していますので、Rails 3のルートに精通していないか、特定の決定がなされた理由はありません。

WhatWillWorkForMeCom::Application.routes.draw do 

    devise_for :users, :controllers => { :registrations => "registrations", 
            :passwords  => "passwords", 
            :sessions  => "sessions" } 
    namespace :admin do 
    resources :comments 
    resources :treatments 
    resources :conditions 
    resources :users 
    end 

    match "/conditions/page/:page", :to => "conditions#index" 
    match "/conditions/hot(/:page)", :to => "conditions#hot" 
    match "/conditions/active(/:page)", :to => "conditions#active" 
    match "/conditions/untreated(/:page)", :to => "conditions#untreated" 
    match "/conditions/tagged/:tag(/:page)", :to => "condition#index" 

    match "sitemap/" => "sitemap#index" 

    match 'contact_us' => 'site#contact_us_new', :as => 'contact_us', :via => :get 
    match 'contact_us' => 'site#contact_us_create', :as => 'contact_us', :via => :post 

    resources :conditions, :except => [:show, :edit] do 

    member do 
     put :update_for_toggle_acceptance 
     put :update_for_toggle_decline 
    end 

    collection do 
     get :hot 
     get :active 
     get :untreated 
     get :search 
    end 
    end 

    match "/conditions/:id(/:friendly_id)", :to => "conditions#show", :as => :condition 
    match "/conditions/:id/:friendly_id/edit", :to => "conditions#edit" 
    match "/site/terms_and_conditions", :to => "site#terms_and_conditions" 

    scope "/conditions/:condition_id/:friendly_id/" do 
    get "treatment/:id/edit", :to => "treatments#edit", :as => :edit_condition_treatment 
    put "treatment/:id", :to => "treatments#update", :as => :condition_treatment 
    post "treatments", :to => "treatments#create", :as => :condition_treatments 
    end 

    match "/admin", :to => "admin#index" 

    resources :comments 
    resources :tags, :only => [:index] 
    resources :votes, :only => [:create] 

    resources :users, :except => [:destroy] do 

    collection do 
     get :who_is_online 
     get :search 
    end 

    member do 
     get :reputation 
    end 

    resources :bookmarks, :only => [:index] 

    end 

    resources :bookmarks, :only => [:toggle] do 
    member do 
     post :toggle 
     get :toggle 
    end 
    end 

    match "errors/routing", :to => "errors#routing" 

    namespace :api do 
    namespace :v1 do 
     resources :conditions, :only => [:index] 
     resources :users, :only => [:index] 
    end 
    end 

    root :to => 'site#index' 
    match '*a', :to => 'errors#routing' 
end 

レーキルート(を求めたように)

 new_user_session GET /users/sign_in(.:format)   {:action=>"new", :controller=>"sessions"} 
      user_session POST /users/sign_in(.:format)   {:action=>"create", :controller=>"sessions"} 
    destroy_user_session GET /users/sign_out(.:format)  {:action=>"destroy", :controller=>"sessions"} 
      user_password POST /users/password(.:format)  {:action=>"create", :controller=>"passwords"} 
     new_user_password GET /users/password/new(.:format) {:action=>"new", :controller=>"passwords"} 
     edit_user_password GET /users/password/edit(.:format) {:action=>"edit", :controller=>"passwords"} 
         PUT /users/password(.:format)  {:action=>"update", :controller=>"passwords"} 
cancel_user_registration GET /users/cancel(.:format)   {:action=>"cancel", :controller=>"registrations"} 
     user_registration POST /users(.:format)     {:action=>"create", :controller=>"registrations"} 
    new_user_registration GET /users/sign_up(.:format)   {:action=>"new", :controller=>"registrations"} 
    edit_user_registration GET /users/edit(.:format)   {:action=>"edit", :controller=>"registrations"} 
         PUT /users(.:format)     {:action=>"update", :controller=>"registrations"} 
         DELETE /users(.:format)     {:action=>"destroy", :controller=>"registrations"} 
     user_confirmation POST /users/confirmation(.:format) {:action=>"create", :controller=>"devise/confirmations"} 
    new_user_confirmation GET /users/confirmation/new(.:format){:action=>"new", :controller=>"devise/confirmations"} 
         GET /users/confirmation(.:format) {:action=>"show", :controller=>"devise/confirmations"} 
who_is_online_users GET /users/who_is_online(.:format)  {:action=>"who_is_online", :controller=>"users"} 
     search_users GET /users/search(.:format)    {:action=>"search", :controller=>"users"} 
    reputation_user GET /users/:id/reputation(.:format)  {:action=>"reputation", :controller=>"users"} 
    user_bookmarks GET /users/:user_id/bookmarks(.:format) {:action=>"index", :controller=>"bookmarks"} 
       users GET /users(.:format)     {:action=>"index", :controller=>"users"} 
        POST /users(.:format)     {:action=>"create", :controller=>"users"} 
      new_user GET /users/new(.:format)    {:action=>"new", :controller=>"users"} 
      edit_user GET /users/:id/edit(.:format)   {:action=>"edit", :controller=>"users"} 
       user GET /users/:id(.:format)    {:action=>"show", :controller=>"users"} 
        PUT /users/:id(.:format)    {:action=>"update", :controller=>"users"} 
+0

'user_path'が動作するはずです。それじゃない? –

+0

開発中ですが、実稼働中ではありません。その私は神秘的になった:) – user1302719

+0

生産に誤りがありますか? –

答えて

0

で開発・生産行動が異なる理由は、私はわからないんだけど、http://whatwillworkforme.com/users?format=myuserは、実際users_path(myuser)上の正常な動作です。 rake routesを実行すると、これを検証できます。あなたはこれらの線に沿って何かを取得する必要があります:路線において出発コロンと

users GET /users(.:format)  users#index 
user GET /users/:id(.:format) users#show 

ものは、あなたが例えば、url_forまたはそれを使用して何に渡すことができる引数になります。 link_to

特定のユーザのルートを取得するには、user_path(user)を使用する必要があります(RailsはActiveRecordインスタンスをidに変換してからルートに渡します)。

逆に、複数のルートを使用してコレクション全体を参照しているので、引数なしでusers_pathを使用する必要があります。どんな引数もあなたのURLにフォーマットを与えるよう試みます(例えば、'xml'は、URLに末尾の.xmlを加えるべきです)。

特定のケースでは、重複したルートに気をつけてください:POST/usersへの呼び出しは、Deviseによって傍受され、コントローラcreateの操作には届きません。

+0

ありがとうございます。適切なuser_path、users_pathを設定しました。私はレーキルートを試していますが、レイクを走らせることに何らかの問題があります。それは、生産ではなく開発モードですべてをやろうとしているようです。ホスティング会社に連絡する必要があります。 – user1302719

+0

これを試してみてください: 'RAILS_ENV = production rake routes'、もしくはより良いのは、RAILS_ENV = productionをプロダクションマシンでエクスポートして、すべてのリクエストが本番環境で行われるようにすることです。 – amencarini

+0

アドバイスをいただきありがとうございます。私はRailsPlaygroundを使用しており、明示的に述べられていない限り、すべてが開発されていることが判明しています。あなたが指定したルートは、私が上記に含まれているレーキルートには存在しません。応答が遅れて申し訳ありませんが、仕事と子供は多くの時間を殺します:) – user1302719

関連する問題