2013-03-28 36 views
0

這是一個錯誤,我似乎無法弄清楚,我相信我有它路由。這是錯誤Rails中的路由錯誤沒有路由匹配{:action =>「ticket_action」,:controller =>「tickets」}

沒有路由匹配{:動作=> 「ticket_action」:控制器=> 「入場券」}

我這個代碼後出現此錯誤

<h4>New Action</h4> 
<% form_tag :action => 'ticket_action' do %> 
<p><b>Description</b><br/> 
    <%= text_area 'description', 'description', 'rows' => 5 %><br/> 
    User: <%= select("actUser", "user_id", User.find(:all).collect{|u| [u.name, u.id] })%> 
    <% end %> 

我有這樣的我ticket_controller.rb是,對於

#action 
def ticket_action 
    @act = Action.new(
     "ticket_id" => flash[:ticket_id], 
     "description" => params[:description]['description'], 
     "user_id" => params[:actUser]['user_id'] 
    ) 


routes 
    actions GET /actions(.:format)   actions#index 
      POST /actions(.:format)   actions#create 
new_action GET /actions/new(.:format)  actions#new 
edit_action GET /actions/:id/edit(.:format) actions#edit 
    action GET /actions/:id(.:format)  actions#show 
      PUT /actions/:id(.:format)  actions#update 
      DELETE /actions/:id(.:format)  actions#destroy 
    tickets GET /tickets(.:format)   tickets#index 
      POST /tickets(.:format)   tickets#create 
new_ticket GET /tickets/new(.:format)  tickets#new 
edit_ticket GET /tickets/:id/edit(.:format) tickets#edit 
    ticket GET /tickets/:id(.:format)  tickets#show 
      PUT /tickets/:id(.:format)  tickets#update 
      DELETE /tickets/:id(.:format)  tickets#destroy 
     users GET /users(.:format)   users#index 
      POST /users(.:format)   users#create 
    new_user GET /users/new(.:format)  users#new 
    edit_user GET /users/:id/edit(.:format) users#edit 
     user GET /users/:id(.:format)  users#show 
      PUT /users/:id(.:format)  users#update 
      DELETE /users/:id(.:format)  users#destroy 
    clients GET /clients(.:format)   clients#index 
      POST /clients(.:format)   clients#create 
new_client GET /clients/new(.:format)  clients#new 
edit_client GET /clients/:id/edit(.:format) clients#edit 
    client GET /clients/:id(.:format)  clients#show 
      PUT /clients/:id(.:format)  clients#update 
      DELETE /clients/:id(.:format)  clients#destroy 

回答

0

妥善安置這將有助於張貼調試這個問題的途徑,你的路線可參考門票尚未類是票。 你應該看看寧靜的路線,特別是給你的用例。看來你應該真的有一個動作控制器(ActionsController,名爲controllers/actions_controller.rb),然後張貼到創建動作並提供一個寧靜的路線(資源:動作) 我的建議是先閱讀休息和軌道。

此外,閃存不是您應該存儲ticket_id的位置,理想情況下,您應該通過發佈到/ action/ticket_action/1並通過訪問參數中的params [:id]來檢索您的操作控制器的創建操作。控制器。如果您確實必須將其存儲在會話中(session [:ticket_id] =「1」),但「休息」是您應該前往的地方。閃光燈將被刪除,只能在控制器中設置,然後顯示在下一頁上,之後將被刪除。

更新:好的感謝張貼您的路線。

您可以添加缺少的路線是這樣,如果你想:

resources :tickets do 
    member do 
    post 'ticket_action' 
    end 
end 

但是,這將更好地遵循這個模式:

在操作控制器:

def new 
    @action = Action.new 
end 

您的形式應該看起來有點像這樣,Rails會知道發佈到action#create,因爲@action是一個新記錄(如果你願意,你可以檢查@ action.new_record)

<%= form_for @action do |f| %> 
    <%= f.text_area :description, :rows => 5 %> 
    <%= f.hidden_field :ticket_id, flash[:ticket_id] %> 
    <%= f.select :user_id, User.find(:all).collect{|u| [u.name, u.id] } %> 
    <%= f.submit "Create" %> 
<% end %> 

然後在你的動作控制器:

def create 
    @action = Action.new(params[:action]) 
end 

或附魔少:

def create 
    @action = Action.new(:user_id => params[:action][:user_id], 
        :description => params[:action][:description], 
        :ticket_id => params[:action][:ticket_id]) 
    if @action.save 
    redirect_to actions_path(@action, :notice => "Created action") 
    else 
    render :new # any errors will be in @action.errors 
    end 
end 

你真的應該被設置,雖然在動作控制器的新方法TICKET_ID。

def new 
    @action = Action.new(:ticket_id => params[:ticket_id]) 
end 

然後在您的形式:

<%= f.hidden_field :ticket_id %> 
+0

我張貼了我的路線,我確實有一個動作控制器Helpdesk :: Application.routes。抽籤做 資源:行動 資源:門票 資源:用戶 資源:客戶 – rubyNOOB

0

你的文件名應該是 「tickets_controller.rb」,複數。

+0

我做了修正仍然給我同樣的錯誤。 – rubyNOOB

相關問題