I am trying to ensure that each job has the correct link when a user clicks on it.
The issue I am having is that I keep getting the error Couldn't find job without an ID
.
In my view I have the following code:
<% @jobs.group_by{|x| x.created_at.strftime("%d %b. %Y")}.each do |date,jobs_on_that_date| %>
<section class="date"><%= date %></section>
<section id="top-job">
<% jobs_on_that_date.each do |job| %>
<section id="job-wrapper">
<%= link_to url_with_protocol(@link.job_url), :target => '_blank' do %>
<section id="job">
<%= job.title %> - <%= job.company %>
<%= job.salary %>
<%= job.location %>
<%= job.job_type %>
</section>
</section>
<% end %>
<% end %>
</section>
<% end %>
In my controller I am creating an object called @link
as follows:
def index
@user = current_user
@jobs = Job.where('created_at > ?', 30.days.ago).reverse
@link = Job.find(params[:id])
end
Finally I have the following Routes setup.
JobappV2::Application.routes.draw do
devise_for :users
resources :jobs
resources :users do
resources :jobs
end
root :to => 'jobs#index'
end
If I use @link = Job.find(2)
this works but every job ends up with the link input by the job with id 2.
Thanks in advance for any help!