我被困在这上面一整天了。当我试图在我的rails项目中显示一个作业的细节、创建一个作业或编辑一个当前的作业时,我在第二行的Jobs#show中得到一个Jobs#show,解释到编辑页面的链接有问题。
Jobs/show.html
<p id="notice"><%= notice %></p>
<p>
<strong>Name:</strong>
<%= @job.name %>
</p>
<p>
<strong>Employer:</strong>
<%= @job.employer %>
</p>
<p>
<strong>Sector:</strong>
<%= @job.sector_id %>
</p>
<p>
<strong>Experience req:</strong>
<%= @job.experience_req %>
</p>
<p>
<strong>Job info:</strong>
<%= @job.job_info %>
</p>
<h2>Star comment: </h2>
<%=form_for([@job, Request.new]) do |f| %>
</h3></br>
<%= f.text_area:content, :rows => 4, :cols=> 40%>
<div class = "actions">
<%=f.submit "Make a request for the job"%>
</div>
<% end %>
<%if @job.requests.empty? %>
<h3> You are the first to Request</h3>
<% else %>
<h2> Who else had made a request for this job:</h2>
<% @job.requests.reverse.each do |request| %>
<p><%= request.content %>
Posted <%=time_ago_in_words(request.created_at)%> ago by
<%=request.candidate.can_name%></p>
<% end %>
<% end %>
<%= link_to 'Edit', edit_jobs_path(@job) %> | **This line highlights an error**
<%= link_to 'Back', jobs_path %>Jobs/edit.html
<h1>Editing job</h1>
<%= render 'form' %>
<%= link_to 'Show', @job %> |
<%= link_to 'Back', jobs_path %>路由
Rails.application.routes.draw do
# get 'sessions/new'
# get 'sessions/create'
#get 'sessions/destroy'
controller :sessions do
get 'login' =>:new
post 'login' =>:create
get 'logout' =>:destroy
delete 'logout' =>:destroy
end
#get 'pages/home'
#get 'pages/about'
resources :candidates
resources :requests
resources :employers
resources :jobs
resources :sectors
# The priority is based upon order of creation: first created -> highest
# priority.
# See how all your routes lay out with "rake routes".
# You can have the root of your site routed with "root"
root 'pages#home'
#root :to=>'pages#home
#'welcome#index'
resources :jobs do
resources :requests
end
endJobs_Controller
class JobsController < ApplicationController
before_action :set_job, only: [:show, :edit, :update, :destroy]
# GET /jobs
# GET /jobs.json
def index
@jobs = Job.all
end
# GET /jobs/1
# GET /jobs/1.json
def show
end
# GET /jobs/new
def new
@job = Job.new
end
# GET /jobs/1/edit
def edit
end
# POST /jobs
# POST /jobs.json
def create
@job = Job.new(job_params)
respond_to do |format|
if @job.save
format.html { redirect_to @job, notice: 'Job was successfully created.'
}
format.json { render :show, status: :created, location: @job }
else
format.html { render :new }
format.json { render json: @job.errors, status: :unprocessable_entity
}
end
end
end
# PATCH/PUT /jobs/1
# PATCH/PUT /jobs/1.json
def update
respond_to do |format|
if @job.update(job_params)
format.html { redirect_to @job, notice: 'Job was successfully updated.'
}
format.json { render :show, status: :ok, location: @job }
else
format.html { render :edit }
format.json { render json: @job.errors, status: :unprocessable_entity }
end
end
end
# DELETE /jobs/1
# DELETE /jobs/1.json
def destroy
@job.destroy
respond_to do |format|
format.html { redirect_to jobs_url, notice: 'Job was successfully
destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_job
@job = Job.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white
#list through.
def job_params
params.require(:job).permit(:name, :employer, :sector_id,
:experience_req,:job_info)
end
end更新
乌尔苏斯告诉我,我必须将<%= link_to 'Show', @job %>改为<%= link_to 'Show', job_path(@job) %> in Jobs/edit.html。我这样做了,但是当我尝试创建一个新的作业或编辑一个当前的作业时,我仍然会得到相同的错误,但是新的作业仍然创建吗?
发布于 2016-11-03 18:11:15
这
<%= link_to 'Show', @job %>应该是
<%= link_to 'Show', job_path(@job) %>https://stackoverflow.com/questions/40408209
复制相似问题