2017-07-27 84 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动作和使用

相关问题