hi ive followed along the depot book. i have a products table, cart, line_items. All works fine there with adding the products to the cart etc. now ive added another table user_products table. i want the user to be able to add these items to the cart also. but i dunno how to get this working. i tried to add in user_product code anywhere i saw code for the 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. any insight would be greatly appreciated need to get this fixed asap. can this be done..the cart taking in items from the products table and user_products table. Ive tried to find information on the web but to no avail..if anyone can point me to some info that would be great. -- 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.
On Wednesday, May 25, 2011 10:48:57 AM UTC-6, Ruby-Forum.com User wrote:> > hi > > ive followed along the depot book. i have a products table, cart, > line_items. All works fine there with adding the products to the cart > etc. > > now ive added another table user_products table. i want the user to be > able to add these items to the cart also. but i dunno how to get this > working. i tried to add in user_product code anywhere i saw code for the > 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.> any insight would be greatly appreciated need > to get this fixed asap. can this be done..the cart taking in items from > the products table and user_products table. Ive tried to find > information on the web but to no avail..if anyone can point me to some > info that would be great. > > -- > 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.
On 25 May 2011 17:48, Caroline M. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> hi > > ive followed along the depot book. i have a products table, cart, > line_items. All works fine there with adding the products to the cart > etc. > > now ive added another table user_products table. i want the user to be > able to add these items to the cart also. but i dunno how to get this > working. i tried to add in user_product code anywhere i saw code for the > 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.What are the columns in the products table and in the user_products table? Colin -- 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.
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 %>×</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-/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.
Colin Law wrote in post #1001031:> On 25 May 2011 17:48, Caroline M. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> belong to line_items too in the model like what is used for the products >> table. > > What are the columns in the products table and in the user_products > table? > > ColinColin, user_products table has photo, title, message, price, id. products table has title, price, category, image_url, and id. 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.
On 25 May 2011 22:05, Caroline M. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Colin Law wrote in post #1001031: >> On 25 May 2011 17:48, Caroline M. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>> belong to line_items too in the model like what is used for the products >>> table. >> >> What are the columns in the products table and in the user_products >> table? >> >> Colin > > Colin, > > user_products table has photo, title, message, price, id. > > products table has title, price, category, image_url, and id.Would it be possible to combine the two tables (so that the user products and products are in the same table)? Either using STI or maybe just have some way of knowing what sort each product is. Then from the point of view of your cart life would be easy. Colin -- 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.
Colin Law wrote in post #1001149:> On 25 May 2011 22:05, Caroline M. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> Colin, >> >> user_products table has photo, title, message, price, id. >> >> products table has title, price, category, image_url, and id. > > Would it be possible to combine the two tables (so that the user > products and products are in the same table)? Either using STI or > maybe just have some way of knowing what sort each product is. Then > from the point of view of your cart life would be easy. > > Colinthanks colin, i was trying to think about this already but not sure really what way to do it. im new to all this. i need the two separate controllers for the tables because i want users to be able to use the new/user_products path creating their own products, while on the products controller the new path is not visible to users. i prob also need to add user_id to the user_products table. im not sure how to combine the tables. im tryna fins stuff on net on STI but im not really understanding it too well. -- 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.
On 26 May 2011 11:38, Caroline M. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Colin Law wrote in post #1001149: >> On 25 May 2011 22:05, Caroline M. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>> Colin, >>> >>> user_products table has photo, title, message, price, id. >>> >>> products table has title, price, category, image_url, and id. >> >> Would it be possible to combine the two tables (so that the user >> products and products are in the same table)? Either using STI or >> maybe just have some way of knowing what sort each product is. Then >> from the point of view of your cart life would be easy. >> >> Colin > > thanks colin, i was trying to think about this already but not sure > really what way to do it. im new to all this. i need the two separate > controllers for the tables because i want users to be able to use the > new/user_products path creating their own products, while on the > products controller the new path is not visible to users.You don''t have to have separate models in order to have two controllers, both controllers can access the same model. Possibly the simplest way, to avoid the complications of STI, would just be to put all the columns you need for both types of product in one table and maybe use a special entry in the category table to say that is is a user model. Or alternatively a new column to indicate the type (don''t call it ''type'' though or rails will think you are using STI). Then just leave the unused columns empty.> i prob also > need to add user_id to the user_products table. im not sure how to > combine the tables. im tryna fins stuff on net on STI but im not really > understanding it too well.Again this will be much easier if you stick to one table. I presume you know about ActiveRecord relationships, if not have a look at the Rails Guide on relationships. You can say Product belongs to User and User has many Products. This will require a user_id column in the products table. Then you could use the fact that the user_id is nil to indicate that it is an ordinary product rather than a user product, rather than use a special category. I am sure you know that then if you have a user in @user then @user.products will give you all his products. I am assuming here that user products are different products to normal ones (rather than just being ''ordinary'' products that relate in some way to the user). If they are actually just the same products then you would want a different setup altogether. Colin> > -- > 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@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law wrote in post #1001188:> On 26 May 2011 11:38, Caroline M. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>> maybe just have some way of knowing what sort each product is. Then >>> from the point of view of your cart life would be easy. >>> >>> Colin >> >> thanks colin, i was trying to think about this already but not sure >> really what way to do it. im new to all this. i need the two separate >> controllers for the tables because i want users to be able to use the >> new/user_products path creating their own products, while on the >> products controller the new path is not visible to users. > > You don''t have to have separate models in order to have two > controllers, both controllers can access the same model. Possibly the > simplest way, to avoid the complications of STI, would just be to put > all the columns you need for both types of product in one table and > maybe use a special entry in the category table to say that is is a > user model. Or alternatively a new column to indicate the type (don''t > call it ''type'' though or rails will think you are using STI). Then > just leave the unused columns empty. > >> i prob also >> need to add user_id to the user_products table. im not sure how to >> combine the tables. im tryna fins stuff on net on STI but im not really >> understanding it too well. > > Again this will be much easier if you stick to one table. I presume > you know about ActiveRecord relationships, if not have a look at the > Rails Guide on relationships. You can say Product belongs to User and > User has many Products. This will require a user_id column in the > products table. Then you could use the fact that the user_id is nil > to indicate that it is an ordinary product rather than a user product, > rather than use a special category. I am sure you know that then if > you have a user in @user then @user.products will give you all his > products. > > I am assuming here that user products are different products to normal > ones (rather than just being ''ordinary'' products that relate in some > way to the user). If they are actually just the same products then > you would want a different setup altogether. > > ColinColin thanks so much for your help. the user products are products were the user can upload a photo using paperclip creating their own personalized products. so if im understanding correctly your saying to get rid of user_products table and add the fields for this table into the products table. and that i still have a products controller and user_products controller for the views to create the different products...however wont the user_products controller create them as user_products, not products? and not be read into the cart then.> Then you could use the fact that the user_id is nil > to indicate that it is an ordinary product rather than a user product, > rather than use a special category.where would i use this? -- 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.
On 26 May 2011 14:51, Caroline M. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Colin Law wrote in post #1001188: >> On 26 May 2011 11:38, Caroline M. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>>> maybe just have some way of knowing what sort each product is. Then >>>> from the point of view of your cart life would be easy. >>>> >>>> Colin >>> >>> thanks colin, i was trying to think about this already but not sure >>> really what way to do it. im new to all this. i need the two separate >>> controllers for the tables because i want users to be able to use the >>> new/user_products path creating their own products, while on the >>> products controller the new path is not visible to users. >> >> You don''t have to have separate models in order to have two >> controllers, both controllers can access the same model. Possibly the >> simplest way, to avoid the complications of STI, would just be to put >> all the columns you need for both types of product in one table and >> maybe use a special entry in the category table to say that is is a >> user model. Or alternatively a new column to indicate the type (don''t >> call it ''type'' though or rails will think you are using STI). Then >> just leave the unused columns empty. >> >>> i prob also >>> need to add user_id to the user_products table. im not sure how to >>> combine the tables. im tryna fins stuff on net on STI but im not really >>> understanding it too well. >> >> Again this will be much easier if you stick to one table. I presume >> you know about ActiveRecord relationships, if not have a look at the >> Rails Guide on relationships. You can say Product belongs to User and >> User has many Products. This will require a user_id column in the >> products table. Then you could use the fact that the user_id is nil >> to indicate that it is an ordinary product rather than a user product, >> rather than use a special category. I am sure you know that then if >> you have a user in @user then @user.products will give you all his >> products. >> >> I am assuming here that user products are different products to normal >> ones (rather than just being ''ordinary'' products that relate in some >> way to the user). If they are actually just the same products then >> you would want a different setup altogether. >> >> Colin > > > Colin thanks so much for your help. > > the user products are products were the user can upload a photo using > paperclip creating their own personalized products. > > so if im understanding correctly your saying to get rid of user_products > table and add the fields for this table into the products table. > and that i still have a products controller and user_products controller > for the views to create the different products...however wont the > user_products controller create them as user_products, not products? and > not be read into the cart then.There is no direct relationship between a controller and a model. The type is up to you. For example, if in user_products controller create action you say @product = Product.new( params[:product]) then it will make a new Product. The fact that the controller happens to be called user_products_controller is irrelevant to the model it manages. A froglets_controller can manage Products if you want it to.> >> Then you could use the fact that the user_id is nil >> to indicate that it is an ordinary product rather than a user product, >> rather than use a special category. > > where would i use this?In the controller or view to select which products you wish to view. Or any other time you wish to select products that are not user_products. Have you worked through the free-to-use-online tutorial railstutorial.org? Although it may not address your exact requirement it will introduce you to many useful techniques which will give you ideas on how to go about things. Colin -- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Caroline M.
2011-May-26 22:12 UTC
Re: Re: Re: Re: connecting 2 products tables to one cart
Colin Law wrote in post #1001240:> On 26 May 2011 14:51, Caroline M. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>>> new/user_products path creating their own products, while on the >>> >>> to indicate that it is an ordinary product rather than a user product, >> >> user_products controller create them as user_products, not products? and >> not be read into the cart then. > > There is no direct relationship between a controller and a model. The > type is up to you. For example, if in user_products controller create > action you say > @product = Product.new( params[:product]) > then it will make a new Product. The fact that the controller happens > to be called user_products_controller is irrelevant to the model it > manages. A froglets_controller can manage Products if you want it to. > >> >>> Then you could use the fact that the user_id is nil >>> to indicate that it is an ordinary product rather than a user product, >>> rather than use a special category. >> >> where would i use this? > > In the controller or view to select which products you wish to view. > Or any other time you wish to select products that are not > user_products. > > Have you worked through the free-to-use-online tutorial > railstutorial.org? Although it may not address your exact requirement > it will introduce you to many useful techniques which will give you > ideas on how to go about things. > > > ColinColin, i tried to implement what you said i have all the fields now in one table. im still having a few hiccups with the views and some actions. in products index i want the products created by user_id 1 only to display. user_id 1 is my admin user. on the user_products controller in the index view i want the products of the logged in user only to display, maybe if user_id 1 is logged in they could see all products created by other users. also when i create a product in the user_product new view after i press create it reverts the product back to the products index instead of keeping it in an user_products index view, which is what i want as i have different fields on display for the two different types. so if i click show etc it displays products show view page but what i want for that product is the user_product show view page. dunno if im explainin this too well. thanks again for your help. -- 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.
Colin Law
2011-May-27 16:25 UTC
Re: Re: Re: Re: Re: connecting 2 products tables to one cart
On 26 May 2011 23:12, Caroline M. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> ... > Colin, > > i tried to implement what you said i have all the fields now in one > table. im still having a few hiccups with the views and some actions. > > in products index i want the products created by user_id 1 only to > display. user_id 1 is my admin user.In the controller fetch the records where that is the id. @products = Product.where( :user_id => 1) or if you actually have the admin user available as an object then @products = admin_user.products which is much nicer.> > on the user_products controller in the index view i want the products > of the logged in user only to display,In this case @products = current_user.products> maybe if user_id 1 is logged in > they could see all products created by other users.If User has a method admin? that tells you whether he is the admin user (much better than relying on id) @products = current_user.admin? ? Product.all : current_user.products> > also when i create a product in the user_product new view after i press > create it reverts the product back to the products index instead of > keeping it in an user_products index view, which is what i want as i > have different fields on display for the two different types. so if i > click show etc it displays products show view page but what i want for > that product is the user_product show view page.Where it goes after the create action is up to the code you have written. After the save call you probably have a redirect_to statement which tells the browser which page to fetch next. In each controller specify where you want it to go. I think in an earlier post I suggested working through railstutorial.org. This would really be a good idea, at some point you will look back on these questions and be embarrassed that you had to ask them. :) Colin -- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Caroline M.
2011-May-27 17:24 UTC
Re: Re: Re: Re: Re: connecting 2 products tables to one cart
Colin Law wrote in post #1001554:> On 26 May 2011 23:12, Caroline M. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> > > In the controller fetch the records where that is the id. > @products = Product.where( :user_id => 1)oh thank you so much it worked!!! knew it was along this lines but i hadn''t the syntax right n hadn''t the .where either.>> on the user_products controller in the index view i want the products >> of the logged in user only to display, > > In this case > @products = current_user.productsagain brilliant, im act cant believe where my head is..above statement fairly obvious, think my head is so frazzled with ruby im not seeing common sense.> Where it goes after the create action is up to the code you have > written. After the save call you probably have a redirect_to > statement which tells the browser which page to fetch next. In each > controller specify where you want it to go.now that you point it out, im like of course, duh, ha. il have a play around with it and see, it was the same as the products controller so obv it was going there.> I think in an earlier post I suggested working through > railstutorial.org.thanks for that will have a look, hopefully help me avoid stupid pitfalls in the future.> you will look back on these questions and be embarrassed that you had > to ask them. :)already there ha now surprise surprise ive encountered another problem after i did above changes. ok so my index view now works perfectly in user_products controller.but when i click on create new product an error pops up. it was working fine, so dunno why a problem is caused now.unless ive done something stupid again. ive put whats showing up in the attached pdf. not sure what else to show you..i tried changing @product to @current_user.product but that didn''t help. :/ thanks for your time and patience!! Attachments: http://www.ruby-forum.com/attachment/6246/error.pdf -- 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.
Colin Law
2011-May-27 19:51 UTC
Re: Re: Re: Re: Re: Re: connecting 2 products tables to one cart
On 27 May 2011 18:24, Caroline M. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> ... > now surprise surprise ive encountered another problem after i did above > changes. ok so my index view now works perfectly in user_products > controller.but when i click on create new product an error pops up. it > was working fine, so dunno why a problem is caused now.unless ive done > something stupid again. ive put whats showing up in the attached pdf. > not sure what else to show you..i tried changing @product to > @current_user.product but that didn''t help. :/ > thanks for your time and patience!! > > Attachments: > http://www.ruby-forum.com/attachment/6246/error.pdfYou could just have pasted it all here. Including the complete error and stack frame is ok. undefined method `model_name'' for NilClass:Class Extracted source (around line #1): 1: <%= form_for(@product, :html => { :multipart => true }) do |f| %> The clue is in the message, it is saying something is nil and the code is asking for a method to be called on it. The problem is probably that @product is nil. Assuming that @product is setup by a find call on the database then it did not find a matching record for some reason (or perhaps the code does not include a find at all). As well as working through the tutorial have a look at the Rails Guide on debugging. It will show you how to use ruby-debug to break into your code and inspect data and follow flow, which can be invaluable if you cannot see the error by inspection. Also have a look at log/development.log in your app, it contains details of the actions called and the parameters and also the database queries called which can be invaluable when something is not working. Colin -- 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.