0

我正在使用:Rails 3.1.3、HAML 和乘客

我在暂存分支中遇到路由问题,但在合并到暂存的另一个分支中,我完全没有问题。我试过比较我的路由文件和这两个分支中的表单文件,git diff但是这两个文件在分支中是相同的。

一个奇怪的事情是呈现的错误页面。这是屏幕截图的链接

错误信息

还有乘客的错误:

Rendered time_entries/_form_fields.haml (173.2ms)
Rendered time_entries/_form.haml (194.7ms)
Rendered time_entries/edit.haml within layouts/application (196.6ms)
Completed 500 Internal Server Error in 448ms

ActionView::Template::Error (No route matches {:controller=>"time_entries"}):
    5:     .field
    6:       = form.submit "Save"
    7:       |
    8:       = link_to "Cancel", project_time_entries_path(@project)
  app/views/time_entries/_form.haml:8:in `block in     _app_views_time_entries__form_haml__894171410_105032920'
  app/views/time_entries/_form.haml:3:in   `_app_views_time_entries__form_haml__894171410_105032920'
  app/views/time_entries/edit.haml:2:in `_app_views_time_entries_edit_haml__805073897_105087770'

我附上我的路线和表格中的代码

表单.haml

.app-form
  = error_messages_for :time_entry
  = form_for [@project, @time_entry] do |form|
    = render :partial => 'form_fields', :locals => {:form => form}
    .field
      = form.submit "Save"
      |
      = link_to "Cancel", project_time_entries_path(@project)

路线.rb

Titi::Application.routes.draw do

  root :to => 'time_entries#index'
  match 'home' => 'home#index', :as => :home

  match '/api/*other' => TitiAPI

  resources :projects do
    member do
      get 'archive'
      get 'unarchive'
    end

    resources :viewers
    resources :labels

    resources :time_entries do
      collection do
        get 'start'
      end
      member do
        get 'new_note'
        put 'add_note'
      end
    end

  end

  resources :bookings

  resources :technical_orientations, except: [:delete]

  match 'merge_labels/:projects_id' => 'labels#merge_labels', :as => :merge_labels
  match 'move_labels/:projects_id' => 'labels#move_labels', :as => :move_labels

  resources :time_entries do
    collection do
      get 'start'
    end

    member do
      get 'new_note'
      put 'add_note'
    end
  end

  resources :users do
    member do
      get 'time_entries'
      get 'edit_password'
      put 'update_password'
      get 'suspend'
      get 'unsuspend'
    end

    new do
      get 'invite_form'
      post 'invite'
    end

    collection do
      get 'all'
    end
  end

  resources :user_sessions

  match 'reports/timesheet' => 'reports#timesheet', :as => :timesheet
  match 'reports/:week/timesheet' => 'reports#timesheet', :as => :timesheet_week
  match 'reports/timesheet_detail' => 'reports#timesheet_detail', :as =>     :timesheet_detail
  match 'reports/dashboard' => 'reports#dashboard', :as => :dashboard_report
  match 'reports/timeentries_irregulars' =>    'time_entries_irregulars#timeentries_irregulars', :as => :timeentries_irregulars
  match 'reports/:week/timeirregulars' => 'time_entries_irregulars#timeentries_irregulars', :as => :timeirregulars_week

  match 'reports/timesheet/admin' => 'reports#timesheet_admin', :as => :timesheet_admin
  match 'reports/:week/timesheet/admin' => 'reports#timesheet_admin', :as => :timesheet_admin_week

  match 'reports/time_entries' => 'time_entries_reports#landing_report'
  match 'reports/time_entries/make' => 'time_entries_reports#index'
  match 'reports/time_entries/csv' => 'time_entries_reports#make_csv'

  match 'reports/:token' => 'reports#index', :as => :reports

  match 'login' => 'user_sessions#new', :as => :login
  match 'logout' => 'user_sessions#destroy', :as => :logout
  match 'register' => 'users#register', :as => :register

  resources :companies do
    collection do
      get 'settings'      
      get "remove_photo"
    end
  end  

  match 'labels/for_project_id/:id' => 'labels#for_project_id', :as => :for_project_id

  match 'holidays_for_company/:token' => 'holidays#public', :as => :public_holiday_for_company
  match 'holidays_by_year' => 'holidays#by_year', :as => :holidays_by_year

  resources :holidays 
  resources :clients

  resources :invoices do
    member do
      get 'pdf_invoice'
      get 'cancel'
    end
    resources :invoice_lines do
      collection do
        get 'add'
      end
    end
    resources :payments
  end

  resources :tweets do
    resource :tweet_likes, :path => 'likes' do
      collection do
        get 'names'
      end
    end
  end

  match 'select_invoices' => 'invoices#select_invoices', :as => :select_invoices

  match 'pusher/auth' => 'pusher#auth'

  resources :requests, :only=>[:create]
  match  '*request', :controller => 'requests', :action => 'options', :constraints => {:method => 'OPTIONS', :format => 'json'}
end

提前致谢。

4

1 回答 1

0

在 app/views/time_entries/_form.haml:8 上,@project 是否存在?也许您的暂存分支使用不同的数据库,因此您认为没有 @project?

此外,运行 rake routes 并验证 project_time_entries 是否在输出中。也许您需要 :as 在您的一条路线上。

于 2012-11-03T15:53:40.070 回答