Hi people. I''m a newbie so bare with me :P This is my first rails application: https://github.com/Agis-/ehm . It''s an app where visitors have the ability to see Offers submitted from Vendors. These Offers also belong to Categories. So Offers, Vendors and Categories are the models & resources in my application. Until now I implemented these pages: - list all Offers (app.com) - all Offers from a certain Vendor (app.com/v/<vendor-id>) - all Offers from a certain Category (app.com/c/<category-id>) and now the important part: I want in the vendor pages (app.com/v/<vendor-id>) where all the Vendor''s offers are listed, to have a sidemenu which will have all the Vendor''s offers grouped by categories. So the visitor will be able not only to see all the Offers from Vendor A, but all the Offers from Vendor A and in Category A, B or C. Thing is, I don''t know how to generally approach this issue. How should I route this? Should I add a sidebar partial template that will render the category menu? Should the routes be like app.com/v/<vendor-id>/c/<cat-id>? or maybe I should use query parameters like app.com/v/<vendor-id>?category=<category-id>? What would be the Rails way of doing this? Thanks:D -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/WBqUoR2RSbYJ. 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.
Agis A.
2012-Mar-11 04:32 UTC
Re: My first app. How should I approach this association thing?
Also, what about the controllers? Would I need all of them? Right now I have 3. I''m just thinking now, maybe the whole approach (following the RESTful architecture) isn''t the best choice for my app. Could I maybe do something like app.com/?vendor=blah&category=blah. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/htBIWvAwx_EJ. 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.
Since you are very new to Rails, I would suggest that you take a an hour or two to go through a three step approach to gather the knowledge you''ll need to answer this yourself. 1) Use the Rails scaffolding feature to build out the models, controllers, views and tests for each of your models. A lot of this code you will end up not using and/or modifying heavily, but it gives you a place to start and should help you to get more comfortable with the "restful" approach. ( http://guides.rubyonrails.org/getting_started.html#getting-up-and-running-quickly-with-scaffolding ) 2) Identify the ActiveRecord relationships you will need between your models. Implement those model relationships. ( http://guides.rubyonrails.org/association_basics.html#the-types-of-associations) Use IRB to build some records and test model relationships. ( http://guides.rubyonrails.org/command_line.html#rails-console ) Establish queries/scopes in your models, and test them also in IRB. ( http://guides.rubyonrails.org/active_record_querying.html#scopes ) 3) Implement the routes and nesting that make sense now that your models and relationships are established. ( http://guides.rubyonrails.org/routing.html#nested-resources , http://railscasts.com/episodes/196-nested-model-form-part-1) Based on the relationships/routing/nesting you implement, you will see what controllers and views you will need to build out. When I am starting a new, complex project, I will oftentimes go through this three step process two or three times, taking a slightly different approach to the models, relationships, queries, and routes each time. This allows me to see where the advantages and disadvantages to each approach pop-up. It is usually in this process where I end up answering the types of questions that you asked below. My apologies if this seems a little elementary (and I did not explicitly answer your questions,) but this is the approach I find useful with Rails'' tools. Hope this helps. On Saturday, March 10, 2012 2:56:04 PM UTC-7, Agis A. wrote:> > Hi people. I''m a newbie so bare with me :P > > This is my first rails application: https://github.com/Agis-/ehm . It''s > an app where visitors have the ability to see Offers submitted from > Vendors. These Offers also belong to Categories. So Offers, Vendors and > Categories are the models & resources in my application. > > Until now I implemented these pages: > > - list all Offers (app.com) > - all Offers from a certain Vendor (app.com/v/<vendor-id>) > - all Offers from a certain Category (app.com/c/<category-id>) > > and now the important part: I want in the vendor pages (app.com/v/<vendor-id>) > where all the Vendor''s offers are listed, to have a sidemenu which will > have all the Vendor''s offers grouped by categories. So the visitor will be > able not only to see all the Offers from Vendor A, but all the Offers from > Vendor A and in Category A, B or C. > > Thing is, I don''t know how to generally approach this issue. How should I > route this? Should I add a sidebar partial template that will render the > category menu? Should the routes be like app.com/v/<vendor-id>/c/<cat-id>? > or maybe I should use query parameters like app.com/v/ > <vendor-id>?category=<category-id>? > > What would be the Rails way of doing this? > > Thanks:D > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/u6jw0MhrwGEJ. 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.