2017-07-27 83 views
-1

這是我的工作控制器如何爲列出所有數據,而我已經使用的顯示控制器

def index 
    @job = Job.new 
end 
def create 
    @job = Job.new(job_params) 
if @job.save 
    flash[:notice] = "resume is uploaded" 
    redirect_to @job 
else 
    flash[:notice] = "resume is not uploaded" 
    redirect_to blogs_path 
end 
end 

def list 
    @jobs = Job.all 
end 
def messages 
@pages = Page.all 
end 
def show 
@job = Job.find(params[:id]) 
end 
def new 
@post = Post.new 
end  

我的錯誤是,如果我將查詢職位空缺/列表,它會採取列表是一個ID創建新動作。這意味着id ='list'.Why它不採取行動。

我confif/routes.rb中 resources :jobs do collection do get ':list' :as => 'list' end end

這也我增加,但不工作

獲得 '工作/列表'


得到 '名單':爲=>「名單「是不是working.And還我已經使用雙模式(工作,郵政)在單個控制器也錯誤,以後我會張貼issue.so先告訴我上面question.I希望能跟大家

+0

嘗試用'得到「名單」:爲=>「list''。 –

+0

爲什麼你在你的'JobsController.new'行動做'@post = Post.new'?你爲什麼要在你的'JobsController.index'操作中做'@job = Job.new'?它看起來像你從根本上誤解了標準REST行爲。你可能想考慮一下。 – jvillian

回答

0

路由添加這樣

resources :jobs do 
    collection do 
     get 'list' 
    end 
end 

和運行耙路線,看看它顯示了list動作和使用

相關問題