비슷한 질문/답변을 읽었지만 버그에 대한 답변을 찾을 수 없습니다.알 수없는 작업 - 컨트롤러에 대한 작업을 찾을 수 없습니다.
나는 직업을 입력하는 양식과 시간 기록을 편집하는 양식이 있습니다. add와 edit는 레일즈 별 가이드 라인을 부분적으로 공유합니다. 내 추가 (새) 양식이 잘 작동합니다. 편집 양식을 제출할 때 오류/버그가 발생합니다.
Unknown Action
The action '11' could not be found for HoursController
이 화면에는 다른 출력이 없습니다.
이 화면에 대해 표시된 URL은 다음과 같습니다
후http://localhost:3000/hours/11/edit
제출 :
이http://localhost:3000/hours/11
내 편집 양식에 대한 양식 태그는 다음과 같습니다
<%= form_for(:hour, :url => {:action => 'update', :id => @hour.id}) do |f| %>
이것은 가야한다 '시간'컨트롤러를 '업데이트'작업으로 보냅니다. ... 어쩌면 내 컨트롤러와 다른 뭔가 문제가 있지만, 추가/새로운 형태의 잘 작동합니다 ... 혼란
내 컨트롤러 :
class HoursController < ApplicationController
before_filter :confirm_logged_in
def index
end
def list
if !params[:job_id].nil?
@hours = Hour.where(["job_id = ?",params[:job_id]]).date_sorted
else
@hours = Hour.date_sorted
end
end
def show
@hour = Hour.find(params[:id])
end
def new
@hour = Hour.new
end
def create
@hour = Hour.new(params[:hours])
if @hour.save
job = Job.find(params[:hours][:job_id])
flash[:notice] = "You have just entered hours for #{job.name}"
redirect_to(:action => "list", :job_id => params[:hours][:job_id])
else
flash[:notice] = "There were one or more problems with your form. Please try again!"
render('new')
end
end
def edit
@hour = Hour.find(params[:id])
end
def update
@hour=Hour.find(params[:id])
if @hour.update_attributes(params[:hour])
flash[:notice] = "You have just updated an Hours entry"
redirect_to(:action => "list", :job_id => params[:hours][:job_id])
else
render("edit")
end
end
def delete
@hour = Hour.find(id)
end
def destroy
Hour.find(params[:id]).destroy
flash[:notice] = "Hours Deleted Successfully!"
redirect_to(:action => 'list')
end
def search
if params[:job][:id]
@job = Job.find(params[:job][:id])
redirect_to(:action => "list", :job_id => @job.id)
end
end
end
내 경로는 시간 부분
resources :hours do
collection do
get :list
get :delete
end
end
에 대한 파일 나 제공
이 밖으로을 파악하는 방법에
list_hours GET /hours/list(.:format) hours#list
delete_hours GET /hours/delete(.:format) hours#delete
hours GET /hours(.:format) hours#index
POST /hours(.:format) hours#create
new_hour GET /hours/new(.:format) hours#new
edit_hour GET /hours/:id/edit(.:format) hours#edit
hour GET /hours/:id(.:format) hours#show
PUT /hours/:id(.:format) hours#update
DELETE /hours/:id(.:format) hours#destroy
어떤 아이디어가 크게 안목 것 iated. --jc
<% @hours 할 form_for | F | %> –
감사합니다. 그게 효과가 있었어. 나는 그 문제에 대해 전혀 몰랐기 때문에 온라인 튜토리얼을 따라왔다. 매우 감사드립니다. <% form_for @hours do | f | %> 일했습니다! –
@ JohnCowan이 내 대답의 왼쪽에있는 내 대답을 수락하여 감사하다고 말합니다. –