简体   繁体   English

Ruby on Rails:Params问题

[英]Ruby on rails : Issue with Params

I'm developing a job board where the companies can submit job ads With jobdescriptions_controller, I also have an uuid field as ID for the outside world called "applyjobid", but now for the outside world I have created jobdetails_controller in order to find the jobdescription. 我正在开发一个工作板,公司可以通过Jobdescriptions_controller提交求职广告,我还有一个uuid字段作为外部世界的ID,称为“ applyjobid”,但是现在对于外部世界,我创建了jobdetails_controller以查找工作描述。

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

I have this error : ActiveRecord::RecordNotFound at /jobdetails/show Couldn't find Jobdescription with 'id'=54da4118-0ba3-4375-ae87-6fa32201a369 我有此错误:/ jobdetails / show中的ActiveRecord :: RecordNotFound找不到'id'= 54da4118-0ba3-4375-ae87-6fa32201a369的Jobdescription

If I go to http://localhost:3000/jobdetails/show?applyjobid=1 it works !!! 如果我去http:// localhost:3000 / jobdetails / show?applyjobid = 1可以! but I really want to use uuid. 但是我真的很想用uuid。

If you can tell me what is the problem, it would be very appreciated, thanks in advance. 如果您能告诉我问题出在哪里,将不胜感激,在此先感谢您。

Schema.rb 模式.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 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 jobdetails_controller.rb

class JobdetailsController < ApplicationController
  layout 'application'

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


end

routes.rb routes.rb

Rails.application.routes.draw do


  resources :tests


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

thanks. 谢谢。

What's wrong here is you are finding by id as you are using find, and you are passing applyjobid So you have to use find_by_applyjobid 出问题了,您在使用查找时正在按ID查找,并且正在传递applyjobid,因此必须使用find_by_applyjobid

try this 尝试这个

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM