I was talking about this problem on here about a week ago, and then had
to
break off from working on it. Returning again.
I’m having an issue with a show action on a nested resource (REST based
controllers).
The main resource (not the nested one) is Candidates
The nested resource is Canbackgrounds
To show the relevant database columns(with example):
Candidates table:
| id | user_id | …other fields |
±----±-------------±---------------------|
| 12 | 1 | |
Canbackgrounds table:
| id | candidate_id | user_id |
±–±--------------------±--------------+
| 28 | 12 | 1 |
so to display candidates here, candidates/12
to display canbackgrounds - candidates/12/canbackgrounds/28 (And this
works)
The problem is the link_to
<%= link_to ‘show’, canbackground_url(@candidate) %>
when i hold the cursor over this link it shows
candidates/12/canbackgrounds/12 (maybe this is wrong)
which produces this error:
couldn’t find Canbackground with ID=12 AND (canbackgrounds.candidate_id
In the Canbackgrounds contoller I have a before filter which seems to be
necessary otherwise the error is “couldn’t fine without id”
before_filter :find_candidate
private
def find_candidate
@candidate_id = params[:candidate_id]
redirect_to candidate_url unless @candidate_id
@candidate = Candidate.find(@candidate_id)
end
Can anyone tell me where my problem is ?
TIA
Stuart
–