I have a large certifications table that I would like to have a little
more controll over, it is part of a HABTM relationship.
-----------------------------------
db''s (simplified)
>certifications
id
course
>employees
id
department_id
type_id
name
>departments
id
name
>types
id
kind
>certifications_employees
certification_id
employee_id
-----------------------------------------
Models
class Employee < ActiveRecord::Base
belongs_to :type
belongs_to :department
has_and_belongs_to_many :certifications
end
class Department < ActiveRecord::Base
has_many :employees
end
class Type < ActiveRecord::Base
has_many :employees
end
------------------------------------------
Using the following code in my employees view _form.rhtml produces
output from my certifications table, it works. The problem is, its a
large table and this will potetially produce hundreds of checkboxes.
---------------------------------------------------
<h1>Certification</h1>
<p>
<% for certification in @certifications %>
<input type="checkbox"
id="<%=certification.id%>"
name="certification_ids[]"
value="<%=certification.id%>"
<%if @employee.certifications.include?
certification%>checked="checked"<% end
%>><%=certification.course%> <br />
<% end %>
----------------------------------------------------
I think I really have two questions.
Is there a way, by way of a the employees_helper.rb to format the result
of <%=certification.course%> may be into 3 or 4 columns ?
And
How could I display just the records I wanted from the table ? For
example, I tried the following, which produced this erorr - undefined
method `apparatus_pump_testing''
<% for certification in @certifications %>
<input type="checkbox"
id="<%=certification.id%>"
name="certification_ids[]"
value="<%=certification.id%>" >
<%=certification.apparatus_pump_testing%>
<% end %>
Kindest regards and many thanks.
--
Posted via http://www.ruby-forum.com/.