How do I set up my @product=Product.find(params[:id]) to have a product_url?
- by montooner
Trying to recreate { script/generate scaffold }, and I've gotten thru a number of Rails basics. I suspect that I need to configure default product url somewhere. But where do I do this?
Setup:
Have: def edit { @product=Product.find(params[:id]) }
Have edit.html.erb, with an edit form posting to action = :create
Have def create { ... }, with the code redirect_to(@product, ...)
Getting error: undefined method `product_url' for #< ProductsController:0x56102b0
My def update:
def update
@product = Product.find(params[:id])
respond_to do |format|
if @product.update_attributes(params[:product])
format.html { redirect_to(@product, :notice => 'Product was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @product.errors, :status => :unprocessable_entity }
end
end
end