hi
i am stuck!
i have a products controller, model and list view. model states: has_many :versions db table: id, title
i have a versions controller, model and list view. model states: belongs_to :products db table: id, num, product_id (hopefully the foreign key!)
i want to know how, in this scenario...
a user selects a product, say microsoft excel -> versions list for excel are displayed. IVE GOT THIS WORKING!
the passed url is: http://localhost:3000/product/show/1
but,
supposing i want to add a new version for excel, say program id => '1', how do i do this?
on the view, i have a button "add new version"
this in turn calls a create method in the controller, but i am unsure how i can pass the product_id across to populate the foreign key in the versions table. how can i get the product number, when it is only know from the URL, when passed to enter the associated versions page?
from the view:
<h1>Add new version</h1> <%= start_form_tag :action => 'create' %> <p><label for="version_number">Number</label>: <%= text_field 'version', 'number' %></p> <%= submit_tag "Create" %> <%= end_form_tag %>
from the version controller:
# create a new version def create @version = Version.new(params[:version]) if @version.save redirect_to :controller => 'product', :action => 'show', :id => @version.product.id end end
can you help? do u need more info?
HELP!!!!!!!!!
i cant find any similar tutorials on this kind of association! i bought the agile dev book, no real use!
can you recommened any good sites i could try? or books?