reynaldo hernandez wrote:
i have a trouble with my application, because i need to load three
combobox, called employes, customer, products, but i cannot to access
them.
i need a model for each one them?
how can i access to the info of the three tables: employes, customers,
products, to show in a view…
please
help me…
thanks
Are you trying to assign an employee, customer, and a product to some
other model? Such as this?
class Post < ActiveRecord::Base
has_one :employee
has_one :customer
has_one :product
end
If so then is not too hard.
<%= select ‘post’, ‘employee_id’,
Empolyee.find(:all).collect {|emp| [emp.name, emp.id]} %>
<%= select ‘post’, ‘customer_id’,
Customer.find(:all).collect {|cus| [cus.name, cus.id]} %>
<%= select ‘post’, ‘product_id’,
Product.find(:all).collect {|prod| [prod.name, prod.id]} %>
You can simply call you find methods on your classes from your view.
Or if you actually want three different models in your view:
#Controller
def new
@employee = Employee.new
@customer = Customer.new
@product = Product.new
end
def create
Employee.create(params[:employee])
Customer.create(params[:customer])
Product.create(params[:product])
end
#View new.rhtml
<%= form_tag :action => ‘create’ %>
<%= text_field ‘employee’, ‘name’ %>
<%= text_field ‘customer’, ‘email’ %>
<%= text_field ‘product’, ‘price’ %>
<%= submit_tag ‘Create’ %>
<%= end_form_tag %>