0

我的应用程序使用票证和 call_logs。我将它们嵌套在一起,因此票证可以有许多 call_logs。我收到 [GET] "/call_logs" 的错误,我不知道我在这里缺少什么。
我确实有我的路线嵌套在routes.rb

  resources :tickets do
    resources :call_logs
  end

耙路线

ticket_call_logs     GET    /tickets/:ticket_id/call_logs(.:format)          call_logs#index
                     POST   /tickets/:ticket_id/call_logs(.:format)          call_logs#create
 new_ticket_call_log GET    /tickets/:ticket_id/call_logs/new(.:format)      call_logs#new
edit_ticket_call_log GET    /tickets/:ticket_id/call_logs/:id/edit(.:format) call_logs#edit
     ticket_call_log GET    /tickets/:ticket_id/call_logs/:id(.:format)      call_logs#show
                     PUT    /tickets/:ticket_id/call_logs/:id(.:format)      call_logs#update
                     DELETE /tickets/:ticket_id/call_logs/:id(.:format)      call_logs#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

call_logs 控制器

class CallLogsController < ApplicationController

  before_filter :get_ticket

  # GET /call_logs
  # GET /call_logs.json
  def index
    @call_logs = @ticket.call_logs.all

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @call_logs }
    end


    # GET /call_logs/1
    # GET /call_logs/1.json
    def show
      @call_log = @ticket.call_logs.find(params[:id])

      respond_to do |format|
        format.html # show.html.erb
        format.json { render json: @call_log }
      end
    end

    # GET /call_logs/new
    # GET /call_logs/new.json
    def new
      @call_log = @ticket.call_logs.build

      respond_to do |format|
        format.html # new.html.erb
        format.json { render json: @call_log }
      end
    end

    # GET /call_logs/1/edit
    def edit
      @call_log = @ticket.call_logs.find(params[:id])
    end

    # POST /call_logs
    # POST /call_logs.json
    def create
      @call_log = CallLog.new(params[:call_log])

      respond_to do |format|
        if @call_log.save
          format.html { redirect_to ticket_call_logs_url(@ticket), notice: 'Call log was successfully created.' }
          format.json { render json: @call_log, status: :created, location: @call_log }
        else
          format.html { render action: "new" }
          format.json { render json: @call_log.errors, status: :unprocessable_entity }
        end
      end
    end

    # PUT /call_logs/1
    # PUT /call_logs/1.json
    def update
      @call_log = @ticket.call_logs.find(params[:id])

      respond_to do |format|
        if @call_log.update_attributes(params[:call_log])
          format.html { redirect_to ticket_call_logs_url(@ticket), notice: 'Call log was successfully updated.' }
          format.json { head :no_content }
        else
          format.html { render action: "edit" }
          format.json { render json: @call_log.errors, status: :unprocessable_entity }
        end
      end
    end

    # DELETE /call_logs/1
    # DELETE /call_logs/1.json
    def destroy
      @call_log = @ticket.call_log.find(params[:id])
      @call_log.destroy

      respond_to do |format|
        format.html { redirect_to ticket_call_logs_path(@call_log)}
        format.json { head :no_content }
      end
    end
  end
end

    private
    def get_ticket
      @ticket = Ticket.find(params[:ticket_id])
    end

我相信在指向 call_log 页面时,我的 url 路径中有错误,但我似乎找不到它。任何建议或提示将不胜感激,因为我是菜鸟。谢谢你。

4

2 回答 2

0

看起来您已经在 routes.rb 中进行了更改,但没有在模型中维护关系。正如 rake 路由所说的 ticket_call_logs GET /tickets/:ticket_id/call_logs(.:format)

应该可以通过 /ticket/id/call_logs 访问,现在这里的“id”是票证 ID。这将列出该特定ticket_id 的所有通话记录。

于 2013-09-11T14:19:54.773 回答
0

从 的输出中可以看出rake routes,您没有匹配 /call_logs 的路由。由于这是一个嵌套资源路由,因此您必须在前面加上票证和票证 id: /tickets/<id>/call_logs

于 2013-03-27T16:26:03.253 回答