我已经在我的创业公司工作了一个星期,在实施braintree(沙盒)后,我无法从http://0.0.0.0:3000/jobs/new格式加载generate()
。在show和index动作中,不会简单地显示任何内容。当我尝试修改优惠http://0.0.0.0:3000/jobs/4/edit时,我收到错误
params
在地方标题和描述中的索引(http://0.0.0.0:3000/jobs/)中是路线的地址。还缺少来自"The action 'update' could not be found for JobsController".
的头像。
offer from http://0.0.0.0:3000/
jobs_controller.rb
AvatarUploader
_form.html.erb
class JobsController < ApplicationController
before_action :set_job, only: [:show, :edit, :update, :destroy]
before_action :authenticate_user!, except: [:index, :show]
def destroy
@job = Job.find(params[:id])
@job.destroy
end
def set_job
@job = Job.find(params[:id])
end
def index
@jobs = Job.all
fresh_when last_modified:
@jobs.maximum(:updated_at)
if params[:search]
@jobs = Job.search(params[:search]).order("created_at DESC")
else
@jobs = Job.all.order("created_at DESC")
end
if(params.has_key?(:job_type))
@jobs = Job.where(job_type: params[:job_type]).order("created_at desc")
end
# GET /jobs/1
# GET /jobs/1.json
def show
@job = Job.find(params[:id])
end
# GET /jobs/new
def new
@job = current_user.jobs.build
@job = Job.new
end
# GET /jobs/1/edit
def edit
@job = Job.find(params[:id])
end
# POST /jobs
# POST /jobs.json
def create
@job = current_user.jobs.build(@job_params)
job_type = params[:job_type]
job_salary = params[:salary]
job_title = params[:title]
respond_to do |format|
if @job.save
format.html { redirect_to @job, notice: 'Your job listing was purchased successfully!' }
format.json { render :show, status: :created, location: @job }
else
format.html { render :new }
format.json { render json: @job.errors, status: :unprocessable_entity }
end
end
def update
@job = Job.find(params[:id])
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
def job_params
params.require(:job).permit(:title, :description, :requirements, :url, :job_type, :location, :job_author, :remote, :apply_url, :avatar, :salary, :multisport_card, :medical_care, :cold_drinks, :parking, :job_category)
end
end
end
end
的routes.rb
<%= simple_form_for @job, html: { multipart: true } do |f| %>
<div class="field">
<div class="control">
<%= f.input :title, required: true,input_html: { class: "input is-rounded" }, wrapper: false, label_html: { class: "label" }, label: "Tytuł stanowiska" %>
</div>
</div>
<div class="field">
<div class="control">
<%= f.input :apply_url, required: true, input_html: { class: "input is-rounded" }, wrapper: false, label_html: { class: "label" }, label: "Adres do rekrutacji" %>
</div>
</div>
<div class="number_field">
<div class="control">
<%= f.input :salary, required: true, input_html: { class: "input is-rounded" }, wrapper: false, label_html: { class: "label" }, label: "Wynagrodzenie ($) / rok" %>
</div>
</div>
<br>
<div class="columns">
<div class="field column is-4">
<div class="control">
<label class="label">Typ zatrudnienia:</label>
<div class="control has-icons-left">
<span class="select">
<%= f.input_field :job_type, required: true, collection: Job::JOB_TYPES, prompt: "Wybierz typ zatrudnienia", class: "input is-rounded" %>
</span>
<span class="icon is-small is-left">
<i class="fa fa-briefcase"></i>
</span>
</div>
</div>
</div>
<div class="field column is-4">
<div class="control">
<label class="label">Kategoria</label>
<div class="control has-icons-left">
<span class="select">
<%= f.input_field :job_type, required: true, collection: Job::JOB_CATEGORY, prompt: "Wybierz kategorie", class: "input is-rounded" %>
</span>
<span class="icon is-small is-left">
<i class="fa fa-briefcase"></i>
</span>
</div>
</div>
</div>
<div class="column">
<div class="field">
<div class="control">
<%= f.input :location, required: true, input_html: { class: "input is-rounded" }, wrapper: false, label_html: { class: "label" }, label: "Lokalizacja" %>
</div>
</div>
</div>
</div>
<div class="field column">
<div class="field">
<div class="control">
<%= f.input :description, required: true, input_html: { class: "textarea is-rounded" }, wrapper: false, label_html: { class: "label" }, label: "Opis" %>
</div>
</div>
<div class="field">
<div class="control">
<%= f.input :requirements, required: true, input_html: { class: "textarea is-rounded" }, wrapper: false, label_html: { class: "label" }, label: "Wymagania" %>
</div>
</div>
<div class="columns">
<div class="field column">
<div class="control">
<%= f.input :job_author, required: true, input_html: { class: "input is-rounded" }, wrapper: false, label_html: { class: "label" }, label: "Firma" %>
</div>
</div>
<div class="field column">
<div class="control">
<%= f.input :url, required: true, input_html: { class: "input is-rounded" }, wrapper: false, label_html: { class: "label" }, label: "Strona Firmy" %>
</div>
</div>
</div>
<div class="columns">
<div class="field column is-4">
<div class="control">
<label class="label">Logo firmy</label>
<div class="file">
<label class="file-label">
<%= f.input :avatar, as: :file, required: false, input_html: { class:"file-input is-rounded job-avatar" }, label: false, wrapper: false %>
<span class="file-cta">
<span class="file-icon"><i class="fa fa-upload"></i></span>
<span class="file-label">Wyślij na serwer</span>
</span>
</label>
</div>
</div>
</div>
<div class="field">
<div class="control">
<label for="job[remote]">
<%= f.input :remote, required: false, input_html: { class: "checkbox is-rounded"}, wrapper: false, label: false %>
Praca zdalna
</div>
<div class="control">
<label for="job[multisport_card]">
<%= f.input :multisport_card, required: false, input_html: { class: "checkbox is-rounded"}, wrapper: false, label: false %>
Karta multisport
</div>
<div class="control">
<label for="job[medical_care]">
<%= f.input :medical_care, required: false, input_html: { class: "checkbox is-rounded"}, wrapper: false, label: false %>
Opieka medycnza
</div>
<div class="control">
<label for="job[cold_drinks]">
<%= f.input :cold_drinks, required: false, input_html: { class: "checkbox is-rounded"}, wrapper: false, label: false %>
Zimne napoje
</div>
<div class="control">
<label for="job[parking]">
<%= f.input :parking, required: false, input_html: { class: "checkbox is-rounded"}, wrapper: false, label: false %>
Parking
</div>
</div>
<div class="column">
<output id="list"></output>
</div>
</div>
<hr />
<%= link_to 'Subscribe to add offer', new_subscription_path %>
<%= f.button :submit, class: "button is-link is-fullwidth is-rounded", value: "Dodaj ofertę pracy" %>
<% end %>
repository here&lt; ---------------------------
答案 0 :(得分:0)
我建议您正确格式化和缩进代码(某些IDE甚至会自动执行此操作)。因为如果你这样做了,你会注意到你将index
方法下的所有方法嵌套到index
方法的主体中。
class JobsController < ApplicationController
before_action :set_job, only: [:show, :edit, :update, :destroy]
before_action :authenticate_user!, except: [:index, :show]
def destroy
@job = Job.find(params[:id])
@job.destroy
end
def set_job
@job = Job.find(params[:id])
end
def index
@jobs = Job.all
fresh_when last_modified: @jobs.maximum(:updated_at)
if params[:search]
@jobs = Job.search(params[:search]).order("created_at DESC")
else
@jobs = Job.all.order("created_at DESC")
end
if(params.has_key?(:job_type))
@jobs = Job.where(job_type: params[:job_type]).order("created_at desc")
end
# GET /jobs/1
# GET /jobs/1.json
def show
@job = Job.find(params[:id])
end
# GET /jobs/new
def new
@job = current_user.jobs.build
@job = Job.new
end
# GET /jobs/1/edit
def edit
@job = Job.find(params[:id])
end
# POST /jobs
# POST /jobs.json
def create
@job = current_user.jobs.build(@job_params)
job_type = params[:job_type]
job_salary = params[:salary]
job_title = params[:title]
respond_to do |format|
if @job.save
format.html { redirect_to @job, notice: 'Your job listing was purchased successfully!' }
format.json { render :show, status: :created, location: @job }
else
format.html { render :new }
format.json { render json: @job.errors, status: :unprocessable_entity }
end
end
def update
@job = Job.find(params[:id])
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
def job_params
params.require(:job).permit(:title, :description, :requirements, :url, :job_type, :location, :job_author, :remote, :apply_url, :avatar, :salary, :multisport_card, :medical_care, :cold_drinks, :parking, :job_category)
end
end
end
end
只需将其修复为以下版本,即可找到create
方法。
class JobsController < ApplicationController
before_action :set_job, only: [:show, :edit, :update, :destroy]
before_action :authenticate_user!, except: [:index, :show]
def destroy
@job = Job.find(params[:id])
@job.destroy
end
def set_job
@job = Job.find(params[:id])
end
def index
@jobs = Job.all
fresh_when last_modified: @jobs.maximum(:updated_at)
if params[:search]
@jobs = Job.search(params[:search]).order("created_at DESC")
else
@jobs = Job.all.order("created_at DESC")
end
if(params.has_key?(:job_type))
@jobs = Job.where(job_type: params[:job_type]).order("created_at desc")
end
end
# GET /jobs/1
# GET /jobs/1.json
def show
@job = Job.find(params[:id])
end
# GET /jobs/new
def new
@job = current_user.jobs.build
@job = Job.new
end
# GET /jobs/1/edit
def edit
@job = Job.find(params[:id])
end
# POST /jobs
# POST /jobs.json
def create
@job = current_user.jobs.build(job_params)
job_type = params[:job_type]
job_salary = params[:salary]
job_title = params[:title]
respond_to do |format|
if @job.save
format.html { redirect_to @job, notice: 'Your job listing was purchased successfully!' }
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
def update
@job = Job.find(params[:id])
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
def job_params
params.require(:job).permit(:title, :description, :requirements, :url, :job_type, :location, :job_author, :remote, :apply_url, :avatar, :salary, :multisport_card, :medical_care, :cold_drinks, :parking, :job_category)
end
end