2015-02-10 60 views
-1

我正在开发一个工作板,公司可以通过jobdescriptions_controller提交招聘广告,我也有一个uuid字段作为外部世界的ID,名为“applyjobid”,但现在是外部世界我创建了jobdetails_controller以便找到作业描述。Ruby on rails:问题与参数

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

我有这样的错误:的ActiveRecord :: RecordNotFound在/ jobdetails /显示 无法与 'ID'= 54da4118-0ba3-4375-ae87-6fa32201a369

找到Jobdescription

如果我去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' 

谢谢。

+0

你'routes.rb'应为这种情况做好准备。你已经改变了它,并通过'applyjobid'创建了你想要访问的特定页面(更好的想法是'apply_job_id')。 – PatNowak 2015-02-10 22:07:14

+0

嗨Pipes,谢谢,我明天再试。 – reme 2015-02-10 22:10:24

回答

3

什么是错在这里是你被发现的ID,你正在使用的发现,和你逝去的applyjobid 所以,你必须使用find_by_applyjobid

试试这个

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

嗨桑蒂亚,谢谢我明天再试。 – reme 2015-02-10 22:09:31

+0

当然,希望它可以帮助你。 – Sontya 2015-02-10 22:12:31

+0

我做了你告诉我要做的事,并且......它完美地工作,非常感谢你的快速反应。 – reme 2015-02-10 22:29:07