2015-02-10 91 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