Reputation: 2845
In my application, 'Users' has_many 'Jobs', through 'applications'
I'm trying to create a helper method has_job(@user, @job). Where, it will return true if the user has already associated itself to a particular job.
When I'm doing this though, if I apply to 1 job, then it returns true for all other jobs.
Why is this happening?
This is what my helper method looks like ->
def has_job(user,current_job)
if user.applications.any?
user.applications.each do |application|
return true if application.job_id = current_job.id
end
end
false
end
Upvotes: 1
Views: 916
Reputation: 3952
return true if application.job_id == current_job.id
The single =
would cause it to return true
every time.
Upvotes: 6