0

我已经在我的初创公司工作了一周,在实施了大脑树(沙箱)之后,我无法paramshttp://0.0.0.0:3000/jobs/new表单加载。在显示和索引操作中没有简单地显示。当我尝试编辑报价http://0.0.0.0:3000/jobs/4/edit我收到错误

"The action 'update' could not be found for JobsController". 

在索引 ( http://0.0.0.0:3000/jobs/ ) 中,地点标题和描述是来自路线的地址。还缺少一个AvatarUploader以前的头像。 来自 http://0.0.0.0:3000/ 的报价

作业控制器.rb

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

_form.html.erb

<%= 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 %>

路线.rb

require 'sidekiq/web'

Rails.application.routes.draw do
  resources :jobs
  resource :subscription
  resources :meetups
  resources :posts do
    resources :comments
  end
  resources :meetups do
    resources :discussions
  end

  devise_for :users
  root to: 'welcome#index'
  get 'posts', to: 'posts#index'
  get '/jobs',   to: 'jobs#index'
  get '/team', to: 'team#index'
  get '/meetups', to: 'meetups#index'
end

存储库在这里<----------------------------

4

1 回答 1

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
于 2018-05-06T11:29:01.990 回答