我的应用程序使用票证和 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 路径中有错误,但我似乎找不到它。任何建议或提示将不胜感激,因为我是菜鸟。谢谢你。