I have an issue with rails orm when i tried to get a field from a "belongs_to" model.
Processing by OdooHrDepartementController#index as HTML
Current user: admin (id=1)
Rendered plugins/redmine_odoo_link/app/views/odoo_hr_departement/index.html.erb within layouts/base (7.6ms)
Completed 500 Internal Server Error in 140.0ms
ActionView::Template::Error (undefined method `company' for #<OdooHrDepartement:0x007f96dcdea650>):
14: <tr>
15: <td class="username"><%= dp.create_date %></td>
16: <td class="firstname"><%= dp.name %></td>
17: <td class="lastname"><%= link_to dp.company.name , { :action => "show_companies", :id => dp.company_id }%></td>
18: <td class="email"><%= dp.note %></td>
19: <td class="email"><%= dp.OdooHrDepartement_id %></td>
20: <td class="email"><%= dp.OdooUsers_id %></td>
activemodel (3.2.19) lib/active_model/attribute_methods.rb:407:in `method_missing'
This is my view:
<h2>odoo departments</h2>
<table class="list">
<thead><tr>
<th>create date</th>
<th>name</th>
<th>company_id</th>
<th>note</th>
<th>parent_id</th>
<th>manager_id</th>
</tr></thead>
<tbody>
<% for dp in @departments -%>
<tr>
<td class="username"><%= dp.create_date %></td>
<td class="firstname"><%= dp.name %></td>
<td class="lastname"><%= link_to dp.company.name , { :action => "show_companies", :id => dp.company_id }%></td>
<td class="email"><%= dp.note %></td>
<td class="email"><%= dp.OdooHrDepartement_id %></td>
<td class="email"><%= dp.OdooUsers_id %></td>
</tr>
<% end -%>
</tbody>
</table>
This is my model:
class OdooHrDepartement < ActiveRecord::Base
belongs_to :Company
belongs_to :OdooHrDepartement
belongs_to :OdooUsers
end
This is my controller:
class OdooHrDepartementController < ApplicationController
unloadable
def index
@departments = OdooHrDepartement.all
end
def show_companies
@company = Company.find(params[:id])
end
end
there are my routes:
get 'odoo_departments', :to => 'odoo_hr_departement#index'
get 'odoo_departments/:id/' , :to => 'odoo_hr_departement#show_companies'
finally this is my migration code :
class CreateOdooHrDepartements < ActiveRecord::Migration
def change
create_table :odoo_hr_departements do |t|
t.timestamp :create_date
t.string :name
t.belongs_to :company, index: true
t.text :note
t.belongs_to :OdooHrDepartement
t.belongs_to :OdooUsers
end
end
end
I am not sure why this doesn't work.
Can someone please help me solve the error with the undefined method company
?