Ruby 在 rails 上:参数问题

Ruby on rails : Issue with Params

我正在开发一个工作板,公司可以在其中提交招聘广告使用 jobdescriptions_controller,我还有一个 uuid 字段作为外部世界的 ID,名为 "applyjobid",但现在用于外部我创建 jobdetails_controller 的世界是为了找到职位描述。

所以,当我转到 http://localhost:3000/jobdetails/show?applyjobid=54da4118-0ba3-4375-ae87-6fa32201a369

我有这个错误:ActiveRecord::RecordNotFound 在 /jobdetails/show 找不到 'id'=54da4118-0ba3-4375-ae87-6fa32201a369

的职位描述

如果我去 http://localhost:3000/jobdetails/show?applyjobid=1 就可以了!!!但我真的很想用uuid。

如果你能告诉我问题是什么,将不胜感激,提前致谢。

Schema.rb

  create_table "jobdescriptions", force: true do |t|
    t.string   "applyjobid"
    t.string   "job_title"
    t.string   "department"
    t.text     "shift"
    t.string   "work_location"
    t.string   "position_supervisor"
    t.string   "supervisor_position_supervisor"
    t.decimal  "rate_pay"
    t.text     "benefits"
    t.text     "other_benefits"
    t.text     "job_summary"
    t.text     "job_duties"
    t.text     "tasks"
    t.text     "results"
    t.text     "responsibilities"
    t.text     "knowledge"
    t.text     "skills"
    t.text     "abilities"
    t.text     "physical_requirement"
    t.text     "work_envir_condition"
    t.text     "protective_clothing_and_devices_required"
    t.text     "tools_or_equipment_required"
    t.text     "qualifications"
    t.text     "education_and_training"
    t.text     "license_certification"
    t.text     "experience"
    t.text     "aptitudes_interests_temperament"
    t.text     "roles_relationships"
    t.text     "supervisory_responsibility"
    t.text     "advancement_promotion_opportunities"
    t.string   "internal_comment"
    t.string   "submited_by"
    t.string   "approved_by"
    t.string   "statut"
    t.date     "from_date"
    t.date     "end_date"
    t.integer  "user_id"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

jobdescriptions_controller.rb

class JobdescriptionsController < ApplicationController
  layout 'application'
  def new
    @jobdescription = Jobdescription.new
  end
  def create
    @jobdescription = current_user.jobdescriptions.create(jobdescription_params)
    redirect_to new_jobdescription_path
  end
private
  def jobdescription_params
    params.require(:jobdescription).permit(:applyjobid, :job_title,  )
  end
end

jobdetails_controller.rb

class JobdetailsController < ApplicationController
  layout 'application'

  def show
    @jobdetail = Jobdescription.find(params[:applyjobid])
  end


end

routes.rb

Rails.application.routes.draw do


  resources :tests


  devise_for :users
  resources :timesheets
  resources :expenses
  resources :jobdescriptions
  resources :jobdetails
  root :to => 'dashbords#index'

谢谢。

这里有什么问题是你在使用 find 时通过 id 查找,而你传递的是 applyjobid 所以你必须使用 find_by_applyjobid

试试这个

def show
   @jobdetail = Jobdescription.find_by_applyjobid(params[:applyjobid])
end