Reputation: 919
I have a one to many association between jobs and companies and it work fine now i want in the job show view to have a link to the company who has published the job for this in my job show view i put this code
<p>
<strong>company:</strong>
<%= link_to @job.company_name, company_path %>
</p>
but instead of going to http://localhost:3000/companies/company_id
I’m redirecting to http://localhost:3000/companies/job_id
where is the fault in my view
this is my routes
Ecole::Application.routes.draw do
devise_for :admin_users, ActiveAdmin::Devise.config
ActiveAdmin.routes(self)
resources :jobs
resources :companies
resources :posts, only: [:show, :create]
devise_for :users
root "welcome#index"
get "profiles/show"
get '/profile/:id' => 'profiles#show', :as => :profile
get 'profiles' => 'profiles#index'
Upvotes: 0
Views: 88
Reputation: 53018
Replace
<%= link_to @job.company_name, company_path %>
With
<%= link_to @job.company_name, company_path(@job.company) %>
Upvotes: 2
Reputation: 920
I think you should be passing the company id as a param for the company_path route. Try with company_path(:id=> company_id) with company_id being the targeted company id.
Upvotes: 0