0

I struggle with getting the id param out of this url:

http://localhost:3000/subscriberjobs/new?job_id=13

Currently I am using this line of code to get it:

@job = Job.find(params[:id])

This line directs to that:

redirect_to "/subscriberjobs/new?job_id=#{@job.id}"

Any help on how to achieve what I am trying to do is much appreciated!

0

2 Answers 2

1

You have set param as job_id not id

Change this

@job = Job.find(params[:id])

To this

@job = Job.find(params[:job_id])
Sign up to request clarification or add additional context in comments.

2 Comments

Tested that already, getting this error: ActiveRecord::RecordNotFound in SubscriberjobsController#update Couldn't find Job with 'id'=
If I change everything to id instead of job_id I don't receive any errors but it extracts the wrong (or none) id. So my general approach on Job.find(params[:id]) has to be wrong
0

If the query param is job_id, then you need to use params[:job_id], like MilesStanfield said, but are you sure that you want to use the new route with an id? If you are trying to edit an existing subscriber job, then the path should probably be http://localhost:3000/subscriberjobs/13/edit, and in SubscriberJobsController#edit, you would then use params[:id]. If you need to redirect to the edit form for the job, you can also use the path helper redirect_to edit_subscriberjobs_path(@job). More info on routing: http://guides.rubyonrails.org/routing.html#crud-verbs-and-actions

1 Comment

Thanks for your answer! Problem is that there is no SubscriberJob Model. It's just a controller to set the Job active and integrate stripe for payments.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.