Kendall Gifford wrote in post #1001028:
> On Wednesday, May 25, 2011 10:48:57 AM UTC-6, Ruby-Forum.com User wrote:
>> product table in the cart and line_item. also added that user_products
>> belong to line_items too in the model like what is used for the products
>> table.
>>
>> i added an extra column in line_item table for user_product_id.
>>
>> still cant get it working.
>>
> In what way doesn't it work? What is the error message and stack trace
> returned when it fails?
>
> Also, if you want help here you're probably going to have to post some
> actual code, since just going off your description of what you did
> really
> tells us close to nothing. Debugging takes concrete data.


Sorry just dunno what exactly i should be posting as it seems bits are
needed in alot of places. i'll try and explain the basics.

my _line_item.html.erb file is as follows:

<% if line_item == @current_item %>
<tr id="current_item" >
<% else %>
<tr>
<% end %>
<td><%= line_item.quantity %>&times;</td>
<td><%= line_item.product.title  %></td>

<td class="item_price" ><%= number_to_currency(line_item.total_price)
%></td>
</tr>



that takes in the information from the products table and displays said
product in the cart. my new table is user_products and i want if one of
these products chose to be displayed in cart also. im new to all this so
quite lost. i tried adding "<td><%= user_product.title %></td>" under
the line_item.product.title but it wouldnt run the page and returned an

NameError....undefined local variable or method `user_product' for #.

basically i dont know how to add in the new instance of a
user_product...should i be using if statement etc.

i have an add to cart button for user_products:
<%= button_to 'Add to Cart', line_items_path(:user_product_id =>
user_product),
:remote => true %>

but it says user_product is undefined.


in my line items controller i added user_products lines from what was
already there for product:

 def create
    @cart = current_cart
    product = Product.find(params[:product_id])
     @line_item = @cart.add_product(product.id)
    user_product = UserProduct.find(params[:user_product_id])
     @line_item = @cart.add_user_product(user_product.id)


    respond_to do |format|
      if @line_item.save
        format.html { redirect_to(store_url) }
        format.js   { @current_item = @line_item }
        format.xml  { render :xml => @line_item,
          :status => :created, :location => @line_item }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @line_item.errors,
          :status => :unprocessable_entity }
      end
    end
  end


hope this is understandable. for user_products it was created using
scaffold so have separate controller,models etc then product.

-- 
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@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to