Hello i got this partial
_form
<%= error_messages_for :product %>
<!--[form:product]-->
<p><label for="product_name">Name</label><br/>
<%= text_field ''product'', ''name''
%></p>
<p><label
for="product_description">Description</label><br/>
<%= text_area ''product'', ''description''
%></p>
<p><label
for="product_category">Category</label><br/>
<%= select(:id,''category'',@categories) %></p>
<!--[eoform:product]-->
in the model i got
class Product < ActiveRecord::Base
belongs_to :category
validates_presence_of :name
end
the problem is that i dont see where is the problem to update the cell
"category_id" <<< it always in ull
here is my controller
def update
@product = Product.find(params[:id])
if @product.update_attributes(params[:product])
flash[:notice] = ''Product ready.''
redirect_to :action => ''show'', :id => @product
else
render :action => ''edit''
end
end
--
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Edgar Gonzalez wrote:> Hello i got this partial > _form > > <%= error_messages_for :product %> > <!--[form:product]--> > <p><label for="product_name">Name</label><br/> > <%= text_field ''product'', ''name'' %></p> > > <p><label for="product_description">Description</label><br/> > <%= text_area ''product'', ''description'' %></p> > > <p><label for="product_category">Category</label><br/> > <%= select(:id,''category'',@categories) %></p> > > <!--[eoform:product]--> > > in the model i got > class Product < ActiveRecord::Base > belongs_to :category > validates_presence_of :name > > endyou have to assign the category to the product (the product belongs_to category). as i gather from peaking at your post, the selected select-tag that you have there (selecting from @categories) should be the category_id of the @product. so, you have to assign it. this can be done in many different ways. here are two solutions: 1. change the select(:id, ''category'', @categories) to select(:category_id, ''product'', @categories) # this changes to the correct params, and will update the correct column (category_id) 2. in the controller add: @product.category_id = params[:id] #if the select tag has select(:id ... which means the params[:id] is the value of what was chosen in the select_tag hth. --shai -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I thought when you put "belongs_to" in model, it save the category id automatically in the db. -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Wel i got this resolved doing this: <p><label for="producto_categoria">Categoria</label><br/> <%= select(:producto,''categoria_id'',@categorias) %></p> :product = the model i am using category_id = the field i want to fill @categories = the choices thanks for all Shai Edgar Gonzalez wrote:> I thought when you put "belongs_to" in model, it save the category id > automatically in the db.-- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---