我试图在节目视图上打开一个职位帖但我得到下面的错误。如果我用find_by替换find它会以某种方式工作,但它只获得活动记录的第一项。
**ActiveRecord::RecordNotFound in JobsController#show** Couldn't find Job with 'id'=id
模特:
class Job < ActiveRecord::Base
validates :title, presence: true
validates :company, presence: true
validates :url, presence: true, uniqueness: true
end
控制器:
class JobsController < ApplicationController
def index
@jobs = Job.page(params[:page]).per(12)
end
def show
@job = Job.find(params[:id])
end
def new
@job = Job.new
end
def create
@job = Job.new(job_params)
if @job.save
redirect_to root_path
else
render 'new'
end
end
private
def job_params
params.require(:job).permit(:title, :company, :url)
end
end
索引
<% @jobs.order("created_at desc").each do |job| %>
<p><%= link_to job.title, job_path(:id) %></p>
<% end %>
答案 0 :(得分:2)
在您看来:
<% @jobs.order("created_at desc").each do |job| %>
<p><%= link_to job.title, job_path(job) %></p>
<% end %>