My product table is id type price location 1 chips $3 aisle3 I have a question with adding the products in groups. There is a quantity field(nonmodel) where the user can enter the quantity While adding a new product if the user enters: type: soda quantity: 3 Then 3 records should be created in product model with type= soda like the following. id type 2 soda 3 soda 4 soda If user enters location: aisle4 quantity: 2 Then id location 5 ailse4 6 ailse4 Can you tell me how to pass the nonmodel field ''quantity'' to the rails(model or controller) and how use it to add the products in groups as mentioned above? or should I create a column called quantity in my product table? Will the history be updated too for all these new records with after_create filter which I already have created? Is there any good tutorial or book which shows how to pass such nonmodel html/javascript fields from view to rails and then back to the view? Any help will be greatly appreciated. Thanks -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I think it makes most sence to have a "stock" field in the database, instead of having one record per stock item.> how to pass such nonmodel html/javascript fields from view > to rails and then back to the viewYou mean "non database" fields, right? Add this to the model: attr_accessor :attribute_name Then you can use this field like any other field, except that it wont be stored in the database. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Seems a little odd what you are doing however to answer your question: You can add a text_field_tag or a select_tag to your form http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#M001731 e.g. <%=text_field_tag :quantity%> You can then get that via params[:quantity] in your controller from there you can either pass to your model/business logic class or do a simple: 1.upto(params[:quantity].to_i) do |i| Product.create!(params[:product]) end Personally though I would seriously consider relooking at the way you are working and perhaps normalize your data so you have 3 models: location has_many :products type has_many :products product belongs_to :location belongs_to :type Then you can do the reverse and use fields_for to add multiple products to a location. Similar to this (http://railscasts.com/episodes/196-nested-model-form-part-1) Cheers Luke -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.