Creating an Online Shop in Rails – Part 1
Articles,  Blog

Creating an Online Shop in Rails – Part 1


hey everyone this is Baylor and welcome
back to the channel welcome back to everything so what we’re gonna do in
this video is we’re gonna start a small series on building a CMS with Rails.
I started this channel you know with PHP and then since we’re done to really
really like that or rails I love dotnet, no I dislike dotnet; I
like rails and I work with dotnet that’s this the downside so what I want
to do is build just a basic shopping cart application which is not a great
CMS so maybe I might change the title to being building an e-commerce platform I
don’t know but it’s not gonna be a full-fledged commerce platform it’s just
going to be something we can do in a video so let’s do it so I’ve laid out a
basic schema definition against this what you might call this so we’re gonna
call it shopper we’re gonna have products categories orders and order
items and on these different models we’re gonna have these fields so title
description and price or product and so on and so forth so let’s go ahead and
get started right hopefully this is what I’m using
rails 5 1 3 and Ruby 2 3 so am i behind it behind but I’m not too concerned
about it because everything I do in this video should be compatible with the
latest and if it’s not then yell at me in the comments or something I don’t
care so I do care I shouldn’t say that well I don’t really care but we’re gonna
do is say rails new and we’re gonna call this shopper now I have some defaults I
prefer so like I want to use proscribes as my database and you can get these
options I’m about to pass in if you just say rails by itself and so they’ll tell
you everything that’s available so like database is dash D and I’m gonna say
skip test which is big t I think that’s all I’m gonna do so we rails new shopper
– t – t opposes rescue all and so I break them in when you create a new
rails app – to specify the database that you’re
gonna use because it gives you a lot of boilerplate stuff that it’s not very fun
to go back and do later plus it helps get your DB schema file more correct and
more accurate to what you might actually have in the big – T is because I have
another I think it I don’t refresh this with mini test or oh I can’t remember
the other ones but I prefer r-spec so that’s just I pick T just so I don’t get
to default so we will wait for this to load if you’ll run this on x – if you
don’t – wait because I’m not going to edit it out hmm
slow internet super slow internet but it is what it is yes still waiting I
hopefully you’re watching this on x – in which case I will talk it as super slow
rate so you can understand me without having to listen carefully okay no good
games gonna take a long time I’ve seen nokogiri is gonna take a long time very
long time while we wait we’ll play a quick game of chess with the computer so
II for oh I’ll play with myself is this done nope so eating okay mmm still
waiting what kind of opening is this I don’t even know but I do know this much
I’m biased towards a white so white might just win this a game or will heat
that is the question we all know the answer – mmm so y’all did not know that
was playing crazy house must take the pawn can we take it with if we just
avoid losing what happens in this game I do not know how’s it finished yet okay
it’s finished okay well we’ll finish this cancer by
the time just memorize it okay so we now have our app so we can CD into
that directory that it created for us and the first thing I want to do is just
run get in it it already did that so I don’t have to do that what I always do
every time I create a new project is you can see this created a git ignore file
every new project I always create or my initial commit is for the getting more
file and I say something like a project so the reason I do that is because it it
just creates a interesting state if you start doing something and you need to
undo it just makes it easier if your first commit is kind of where you kind
of set the foundation of what the project directory structure should look
like and now I always say add rails so two commits this also helps you pad your
numbers if you’re a developer in a small company because you always have to
commit to each project great just something know and so now what we’ll do
is I’m just going to run screen yeah term too long hmm okay that’s four PI T MUX here we
are I think it is 14 oh it’s 40 max with my font um oh I can’t remember I bought
the font I don’t even know what it’s called so many things to talk about
outside of what we’re actually doing operator mano that’s the font that’s the
font that I use so yes so I’m trying a team accession which I didn’t really
want to do but will do it’s fine we’ll call this boom and we’re another tab
we’re good in this one server and we’re gonna run it rails s so we may not
actually open their browser app I don’t know but what we will have server
running so case you want to look anything we’re doing in this video which
is not very much so because this video is all about building the schema right
so let’s go ahead and get started we can do this in basically any order the only
time we’re going to have something the only time we’re gonna have something
that’s kind of an interesting we’re gonna have a mini – mini association
between these two entities I think that’s it this one’s going to
kind of have a mini – mini product and order items but not in the same way
actually that’s not many too many never mind okay we’ll ignore that we have them
we have a mini mini order two products but it done not in the same way so I
designed the same way so let’s start with product where we have a title
description our price how do we do that well what we do is this so we’re in our
project we’re gonna say rails generate and we’re gonna say we want generate a
model what I’m gonna show you in this video like yeah I was kind of thinking
about this I don’t think it’s necessarily that important to try to
memorize all the rails commands because it’s one of the things where you’ll
remember what she used frequently and what’s used frequently is because you
use it frequently it’s not like yeah if that makes any sense
and so plus I don’t think it’s worth trying to take the time to memorize them
because the Ruby community as a whole is really good about following conventions
and so if you download a gym pretty comfortably you’re going to just know
how to use it with the generators but for those of you that want to know
you’re gonna run rails G by itself and this will spit out a full list of
everything that’s available to you so you can see I ran rails G and I was
going to run model here and I imagine if I run rails G model it’ll give me more
information about that particular one but I will not do that for this because
I knew what I want to run so I’m just a realist ran right model we’re gonna
generate a product you can name this plural you can name it singular you can
do a Pascal case you can do it every one I do here it’s going to still do what it
wants to do as far as rails conventions and we don’t need to specify a title
rails does that one so that means all we care about is title description in price
so for title we can just do that and the reason we can do that is because by
default rails will name this string which in Postgres is going to I just do
of our car hopefully you’re not bar Carmack’s but it very well likely do
that might do that not certain but we can set a max link on that and then for
description and price description will actually specify this entry
text because when with this one I have more space than title and then we get
prices decimal and decimal is just a really good format to actually store
monetary values own – Eagle server has like money but you don’t want to use
money that is considered very bad and it’s just kind of ironic so that gives
us our product now I would I usually do here when I kind of know my schema is I
just join as many as I can out of the box wouldn’t then go back and try to
edit them so we’re gonna share another model for our category and this is gonna
have a title and a disk what does category have it just has a
title okay so we just do that um oh I forgot I had variations on the products
so what I wanted to do is I wanted to create a good schema where we have like
many too many associations and then we have a one dominio let’s create a
variation as well so I’m going to call that product variant and this has a
title and a price and like this before we’re going to
title or price with a decimal let’s do our next one so we are at order and this
has a first name strained oh that’s not not required last name and we have a
subtotal sorry if that was like super loud what’s
a lot of my headphones remodel and then I’m just kind of going through this
quickly but I think you can kind of see the pattern here relish generate model
and then what this is doing is its generating the database migration which
we’ll look at in a second and it’s also joining in our class for us as well so
this is the last one I guess I should have mentioned that before but at least
I didn’t finish all of them before I told you that so this has a quantity and
a price quantity quantity should be a float no it should be a name that’s all
do and I always forget this is virtually about I think I have to write up an
injury all the way out that’s as far as bad now for those that you that kind of
have seen the mistake that I’ve made I did catch this look at the time
I realized it was running order item I do not set up my associations so there’s
no way for order item to know that it belongs to order likewise there’s no way
for product for a grant to understand what product is and their relationships
so let’s do that real quick so and this also teaches us how to create migrations
right and we have human seen migrations how great of a video is this we’re going
to learn how to do things we don’t know if they’re doing but we’re going to do
that real quick and then we’ll look at all of it together as a group so I’m
gonna say rails generate migration and the first thing we want to do is add
product variant to product and so what we can say is we can actually just say
product : belongs to you think oh what kind of what is this and well hopefully
you don’t really think that too hard because like you know like don’t pop a
blood vessel or something trying to figure out that this is not a scalar in
the database this is actually going to create an association from our what this
was a horrible name we need to name this how good of a job is this we need to say
like add product to product variants now this is where rails gets super super
cool so I didn’t do a good job with that but basically what we do is we say rails
generate migration this is our command that we want to run and in the first
argument for migrations is to the title of it so you can see these had like
create categories create product variants create orders like that but
this one will do is it’s going to realize this too right here and it’s
going to understand that our table name is product variants I don’t know how
deep this goes I imagine hunting that singularly it would still work because
rails is awesome and then what’s going to happen here is when it creates this
migration it’s going to say we need to create an association from product
variants back to product and this is going to be a belongs to so it’s kind of
cool we can run that and it works and we’ll see what that did in a second I
need to do one more I’ll ski migration add order item to orders order the long
– and I think that was everything that I missed I guess the last thing we can do
is we want to have a mini – mini association between these two and so
what we could do for that is just a rails generate model and we’re gonna say
we want to create a product category and this is going to have a product belongs
to in a category belongs to and so if this was actually going to allow us to
create a join table that’s what this is there’s also conjunction table I have to
remember conjunction table is that what it’s called
sequel junction table is that what it’s called mm-hmm we need a mini with a
junction table so it’s a joint table or a junction table depends on where you
are from and and so I call them a drawing table some people come a
conjunction table icon and we need to say rails je migration model now what
we’ve done this one so like these we did migrations to make changes to our
entities that we’re creating this one were just and when it’s not necessary to
it belongs to an ax migration like I showed here you can actually do it when
you create the model I just forgot because I’m an idiot so we
have a bunch of files now and we have a couple migrations I’m gonna just hop in
here and go into our migrations and we’re gonna start with the first one
because these are basically all gonna be the same I might sort of mold them more
than more than one but I’m just gonna go to for the first one for now so here we
define that we’re doing a create table for products and we had our fields that
we generated here I’m going to do the precision on this 215 and the scale to 3
actually the scales can be – I think that’s fine so this is specifying how
wider range to expect our allowed price so like if you’re doing gas prices here
in the United States we might have three because that’s how we do gas prices in
the US sure how that looks around the world but
here we like to have it in thousandths hey that’s right anyways in the US and
see they they didn’t like it’s more than 200 here this see the little nine you
can just barely make it out that is that is what we do here in the states we have
three decimal places so for price here though we don’t really need that so
we’re just gonna go with two and what I’m also gonna do is say the title is
null false because we don’t want this to be knowable it’s a required build you
have to put in that title in this T timestamps with this does is some magic
it’s gonna add it created at like created at and then updated at columns
that are both daytime and have at default of panel and real stores
everything is you to see by default so if you’re if you’ve been burned by that
in the past you won’t have that problem here in rails so let’s go to the next
one no false no follows no false and
precision 15 scale assume probably got these backwards but I don’t think I did
because always gonna backwards gonna try to get the other way this time we might
say the first thing could be no but the last time different can’t be at all in the order of these arguments is
important I’m just trying to create some kind of consistency and that reminds me
that I did not set this and all false and I should and no false default will
be zero and all false precision is 15 and scale is 2 and yes so here’s what we
did our ad product to product variance so you can see that it’s saying on our
table product variance we want to add a product it has a foreign key of true and
all a false I think that is necessary to add so what this is going to do is it’s
going to do a whole lot more than simply say product ID it’s going to add that
well I guess that’s all it really does but it it’s also going to give us our
foreign key constraint so that we can’t insert into the product variants table
with a product ID that doesn’t exist keeping our schema good so what we’re
doing here and we’re going to say no if also this as well and oh yes here as
well and what I’m going to do so this is really interesting here something I
haven’t paid attention to before is product this one let’s hit add reference
as it belongs to I think it’s the same thing if it’s not I’m about to find out
the hard way but I haven’t paid too close attention to this before it’s one
thing when you do it by yourself then you’re just like chillin it’s nothing
weird I like a video and you’re out of breath because you can’t talk and think
at the same time I guess what we can do is Oh – is broken
– we’re gonna look at documentation
together because that’s what you do when you’re making a video here we go rails
and we’re looking at add reference so I guess it’s the same thing it has a null
column default so true yeah so we did no false for a reason because we don’t want
me to be normal because they are required yes so we’ll just ignore that
that looks correct okay so now what we do well we would define our schema now
what we do is we say rails DB migrated and how this is a communal lat
so what this will do is it’s going to run through those migrations in order by
date and then it’s going to apply those to the database and I might get in here
that the database doesn’t exist alright so rails DB create oh actually I
don’t have pro scratch running so let’s see that and and they created them good
and so now we can migrate the database and you can see kaboom we got it
so now I don’t know that my I guess it’s sharper underscore development actually
I wasn’t so what we have done now if I running that command is it created to
have a room open already yeah we have created this file called DB / schema
darby here and what this does it has its version by just the date time I think
this date time actually goes off the last migration date don’t quote me on
that but I think I’m correct it looks like I am because you could see it right
here and so this is basically just a ruby written implement our definition of
our database schema and so you can use this file for two reasons the first is
that when you go back and need to see what schema you have you don’t have to
go and look at the database you can just open this file up in your editor and
just kind of scan it real quick can’t beat that
the other thing is that if you’re if you have like a new developer come on or you
set up a new database you don’t have to run your migrations in order you can do
this thing load this thing and so what that’ll do
is it’ll actually rebuild a database from this scheme or RB file so it’s
important that you keep that in source control or this not that this and you
can basically just see everything that we’ve got here that we have our
categories and we have things which have to find their order items order items
don’t have an order ID what was I thinking
orders haven’t already so I got that way backwards what did I run perhaps I
should have actually looked to see what I was doing
no matter let’s see what did I run oh I wrote an ad order item two orders like
an idiot so what we need to do is what we can do here is it’s a rails DB
rollback and I may have to do that a bunch of times yeah because it’s time
one by one add it order item two orders there we go so this is our n I’m just
gonna change this to items and say it’s order yes and now we can say migrate and
it goes all the way to the end so there we go that’ll fix that and now if we
look at our schema file you can see that now order items has our foreign key
constraint and orders does not because it doesn’t belong orders Wow how
embarrassing should I keep this video I am going to
keep this video because I’m in a good mood and I don’t really know how bad it
is until maybe I watch it but in that case you will not see this will you know
so this is our schema and what we’re gonna do is just commit this add the
schema for our add the schema not Rea descriptive but it tells the point what
is that’s what it adds the schema and every time I commit I always like to
have it lower case and present tense as I present tense add the schema I don’t
even know it’s not added that’s past it’s this add do this whatever that is
so my English understanding of the grammatical requirements of English
language are minimal even though I feel like it should be a lot higher
considering that it’s my only language I know so what I’m gonna do now is we’re
gonna actually kind of play with this a little bit so let’s before we get into
it this is one of the coolest parts of rails is that rails has a CLI so if we
were in rails C which ends for console rail C gives us a way to play with
everything that we have available to us is if though we were in the system
running so to speak so like I might say product at first you’re gonna see this
comes back with nil because we haven’t created a product so we can do that when
say product create and if we run that with a bang this is where it’s good to
have this API that is API that Ruby on Rails oughta work I just have just this
nice app to bring it to my attention as how I need it and so if we look at
create and create bang we want this one on active record relation maybe that’ll
do yeah doesn’t play that’s relation because it
is perhaps anyways so what this does is this will try to create a this is not
correct I’m looking for act record point out application maybe no that’s it we’re
not right either active record association persistence collation
persistence this is it okay so this method tries to create an object within
or crates like a database entity that you pass in a hash to and so you can see
like a traits right scrape first our user here with the first name of Jamie
you can create multiple users by passing in an array you can do things like that
and then if you do with the bank it’s basically the same
thing except that it will throw an exception if it’s wrong raises a record
and about arif validation fails and so because what we’re going to need to do
is we if I try to do this real quick you can see that just try to insert it
didn’t run any validations and threw an error because or Postgres database said
that title could not be null and so what we need to do is add a validation before
we get that far so if we go into our product record so it’s now that’s in HAP
models and then product we can say that we validates the title and the presence
is true now there’s a whole bunch of these that you can learn and like I kind
of think all the time you should always just look at the documentation and see
what’s there and there’s a bunch of these if you scroll down somewhere
there’s a list of them somewhere there is a list of them I’m not lying to you I
promise I don’t even know I guess these are him him these are them with a T in
the front of that CL suppose my English was bad probably thinking he’s a fool
but now you know he is a fool so yeah you can validate all sorts of stuff here
we’re looking at the presence here we don’t look about uniqueness although
that we might do that in the future but we don’t have a database going straight
for that so we won’t worry about it so we’re saying product title presence
is required and so now if we go back into our console and say product not
create we’re gonna see a new error Wow title can’t be blank so this didn’t even
try to hit the database that’s the cool thing about this so we could catch that
exception or rescue from it the other cool thing we could do is just say
product got create dot errors and this will give us back a list of the errors
um with the field they actually occurred excuse me Wow so if we run this this
will give us back a list of the errors and this with the field they occurred on
and it’s in a string array basically or array of strings so we have like it
can’t be blank it must be unique and all sorts of calls
and that would happen for this so let’s go ahead and create a product now is a
product that create and we’re going to be the title of candy bar and our price
of 150 and a description of delicious and fortunate for us that ID start with
two because that makes the most sense so now if we say product that first though
will actually get back to our air occurred here and what’s cool is you can
see oh nevermind there is a way to get this to cash something that’s neat in
the rails console underscores your last result so you could say now I just like
product equals underscore and they don’t have to reach that so that’s kind of
neat so this console basically gives us a way to interact with all our objects
without having to create UI around them or go directly to the database we can
just we can actually play with rails without having to do anything so here we
can also do like let’s we created the many-to-many association between
products and categories and so if we actually go and look cata or product
category it has these Long’s to on both sides so if we want to go from product
to category though we don’t have that let me make this a little bigger so
unless i go to product on the right side go to category and product how to get
squished in the middle but if we want to go from product to category what we can
do is we can say we has many product categories and rails relies very heavily
on an inflexion to know that if I say categories plural that I am looking at a
associate our product category here in the table name and then we’ll go to
singular here we’ll say and we have or has many categories through our product
categories and so what this will do well we’ll just look at it in a second
but I am going to just paste this over here and I’m just going to change this
on the products so from category we got back to product categories which goes
over here and then it says we have a long su product so when I say has many
products now it does our join through product category where the category
matches we grab the product IDs and then we have a list of all our products so
now let’s actually play with that so if we go into rails console here we can say
that we have our product at first and how to do the Bhangra I didn’t you –
whatever and so here we’ll have our product equals underscore because that
gives us back our previous result and now we get to say product categories and
you’ll see the seagull that generates and so you can see it said select start
on categories from categories where and join on product categories where the
product the callaloo where the product ID matches and like and so I did not
read that sequel very well at all so let’s read that again so I start from
categories because that’s the only interested we care about here we’re
joining our product categories where the category ID matches the product
categories and where that product categories product ID equals to because
that’s the idea of our product and what’s cool with this is we can actually
say create here and we’ll say title is equal to snacks and so what does it is
it inserted into categories to create our new category and then also inserted
to product categories to create that association between the two now and it
does this inside of a transaction so if this one failed or this one that would
not matter but if this one failed then it wouldn’t continue and it would roll
back before I got to this categories so very cool stuff because with this now
let’s just hop into a clean slate we say product about first dot categories you
can see that we’ve got back the first category of snacks and we can do this
stuff we can do like our new product and here we’ll do like title his what
will we name this will name this a candy I’m a product helmet because I have
advice Oklahoma out of my desk price will be fifty dollars because I don’t
worry about you paid for it and we’ll do categories and this is gonna be an array
of category new and we’ll have a title I don’t do I have to do that this is a
good question if I just name this safety category expected got title okay so it
does expect innocence I thought it did but I had to try it and I can’t get out
there we go so now here we here we go real big so we insert into products we
insert into categories and we create that joint all at the same time
and so now if I say like category dot last dot products you can see we get
back just our helmet here because we order by category ID descending so that
gives us our newest ones first in theory we always assume the ID is
ascending so we say descending to give us our highest numbers first and we
limit to one and so that gives us back just one category and then we take that
category ID to get back our products and we can do cool things here I’m realized
I’m just kind of giving you like a huge idea of what you can do with rails but
this is just kind of a real thick primer so that next week you might have some
ideas of things that you can play with until I make the next video so we could
do say things like product that includes categories and so what this will do is
this avoids big o-notation because what it did it says giving all
the products now give me all the product categories for these two products and
now giving all the categories inside of those two product categories so that now
when we query off of more say that products equal this
so now if I say products like categories you can see that’s not expected to see products at first what if I created I’ve
done something terribly wrong not to array how about that okay there we go
so what this did is st. includes does our multiple queries to actually get all
the products and all the categories are related to these products and so when I
actually kind of cached that result take that cash result and push it to a
variable when I say like give me the first products categories you can see it
just loaded that because it had already loaded it before
so what rails is capable of doing is some very complex things because to do
this in other or realms well so I’m gonna show you any more difficult but if
you look at things like entity framework it’ll generate the most nasty query in
the world that will not run in point three milliseconds and I’ve done
something horrible I apologize so yes I think that’s what I want to leave this
video if you what I may do or what you can do is go into your DB seed start RB
file and gives you an example that you can create data here and then you just
run rails DB seed and then when you run that command it’ll just engineering all
your data so that when you start your project or when a new database gets
created you can go ahead and have test data to work with I’ve never really done
this but it is something that is available to you if you need it yeah and
I guess you could find really good use of cases for this just haven’t really
needed it before so these two entities are into these we haven’t done a good
job with adding validations or associations between everything I’ll
probably do that between here in the next video but this does probably give
you a good idea I guess I could do it belongs to so you could see how that
works but what do that some other time so thank you for watching this video
have a great evening or morning afternoon whatever time it is and I’ll
see you next week

20 Comments

  • s1234

    Thank you for the tutorial! I’m trying to learn rails, but I found it pretty confusing to set associations between tables, can you tell me how did you learn them?

  • Drew G

    Does this project apply to SQlite3 database's? My coding bootcamp class has been using SQlite3 the whole way, but i have been hearing about posgresql. Will the instructions for this ecommerce website apply for the SQlite3 database ? Or do you recommend downloading postgresql

  • Steve S

    Was looking through the rails documentation as I'm going through this and it looks like rails will create a join table for you, you just have to run a migration with the CreateJoinTable or create_join_table (whatever you prefer) in the name so I ran rails g migration CreateJoinTableProductCategory product category. Now to find out how good it be, yo (or something).

  • Al Barleta

    lol. This is the only webdev tutorial I've watched that involves a chess match. Amazing content! More rails please! 🙂

  • Seán Black

    Great tutorial series. I just discovered your channel. Are you planning on making more rails tutorials in the future. I want to try and build as many rails apps as I can, trial and error has to be the best way to learn? But resources for rails on you tube are not great imo. So channels like yours are a savior to aspiring rails developers. Thanks for your work.

  • Ivan Escalante

    all those "git st, git aa' git ci' alias commands you have, can you make public the original names of the commands ? like just their equivalents ( newbie here ) havin a hard time following you bc of it

  • uma sai

    i m getting this error at 34:36

    2.6.3 :007 > products.categories
    Traceback (most recent call last):
    8: from bin/rails:4:in `<main>'
    7: from bin/rails:4:in `require'
    6: from /home/uma/.rvm/gems/ruby-2.6.3/gems/railties-4.2.10/lib/rails/commands.rb:17:in `<top (required)>'
    5: from /home/uma/.rvm/gems/ruby-2.6.3/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    4: from /home/uma/.rvm/gems/ruby-2.6.3/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:68:in `console'
    3: from /home/uma/.rvm/gems/ruby-2.6.3/gems/railties-4.2.10/lib/rails/commands/console.rb:9:in `start'
    2: from /home/uma/.rvm/gems/ruby-2.6.3/gems/railties-4.2.10/lib/rails/commands/console.rb:110:in `start'
    1: from (irb):7
    NameError (undefined local variable or method `products' for main:Object)

    please let me know what is the error????

  • uma sai

    now its getting like this

    2.6.3 :010 > products.categories
    Traceback (most recent call last):
    11: from bin/rails:4:in `<main>'
    10: from bin/rails:4:in `require'
    9: from /home/uma/.rvm/gems/ruby-2.6.3/gems/railties-4.2.10/lib/rails/commands.rb:17:in `<top (required)>'
    8: from /home/uma/.rvm/gems/ruby-2.6.3/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    7: from /home/uma/.rvm/gems/ruby-2.6.3/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:68:in `console'
    6: from /home/uma/.rvm/gems/ruby-2.6.3/gems/railties-4.2.10/lib/rails/commands/console.rb:9:in `start'
    5: from /home/uma/.rvm/gems/ruby-2.6.3/gems/railties-4.2.10/lib/rails/commands/console.rb:110:in `start'
    4: from (irb):10
    3: from (irb):10:in `rescue in irb_binding'
    2: from /home/uma/.rvm/gems/ruby-2.6.3/gems/activerecord-4.2.10/lib/active_record/relation/delegation.rb:99:in `method_missing'
    1: from /home/uma/.rvm/gems/ruby-2.6.3/gems/activerecord-4.2.10/lib/active_record/relation/delegation.rb:136:in `method_missing'
    NoMethodError (undefined method `categories' for #<Product::ActiveRecord_Relation:0x000055686d7e5bc8>)

    is there any error in this???

Leave a Reply

Your email address will not be published. Required fields are marked *