Rails design of an online newspaper -- controllers - ruby-on-rails

I have started a Ruby on Rails 3 project to make an online version of newspaper. The front page has the news headlines, sports headlines and life headlines. It has all the headlines for the different sections of the site.
All the stories are stored in one table and photos in another table. It is a very simple set up. I am trying be DRY but I can't seem to avoid it. On the index action page I have to look up sports stories and on the sports action page I have to look up sports.
My question is should I make a different controller for every category? Or have a main controller with categories as actions? ( which is what I am doing now? )

I would have a single Story controller that takes a querystring to determine the category. In other words, if you go to
/stories/
you get the front page, which lists all (or a portion of all) stories. If you want sports you go to
/stories/?category=sports
and the Story controller filters the list of stories (and presumably alters the view headings, etc.) based on the querystring.

Related

Toggle categories in a table in Ruby on Rails

I am trying to create a page that shows a table that contains products and I would like for the user to be able to toggle the categories. For example, if there are categories jeans, shirts and jackets, I would like a set of checkboxes that would toggle between showing the three categories of products. The problem is that I am unsure of how to approach this problem. I am not sure how to allow the user to relay the information to the controller without changing every users toggled categories. I also don't know how to get around the fact that refreshing the page to refresh the table would simply reset all of the categories.
you can do it in this way,
based upon event click of checkbox fire up ajax request on get req/param_catagory
get and assign data and load it over data table
you can use jquery data table plugins for that
There are few easy jquery plugins for that example: jquery data table
Hope this will help.

How to write URLs in MVC for 4 level Subcategories in menu without showing controller name and method name?

I am working on an E-Commerce website and my requirement is to show URLs something like following.
"../example.com/Electronics/Home-Audio-and-Theater/Portable-Audio/iPods"
Where Electronics is Main category and all of the subsequent parts are subcategories.
I have a Menu which shows level upto iPods(3rd level). I want that on click of any level the URL should be created accordingly. For Example:-
If I click on Electronics the URL should be:-
../example.com/Electronics
If clicked on "Home-Audio-and-Theater"
example.com/Electronics/Home-Audio-and-Theater
and so on.
All of the Names of levels are dynamic so I can't create controller for each level.
I need a technique by which I can show these URLs according to menu item clicked and hit the controller.
Please suggest ideas for this.
Thank You

How to display a different breadcrumb title for the same controller + action method?

I have a Home controller and a Business controller. The business controller has a few action methods on it: Search, Create, Update, Delete.
On my home page I have links to the Search and Create views on the Business controller. The Search view also has a link to the Create view.
I want the bread crumb to look like the following when Create is accessed from the home page:
Home > Create
…and i want it to look like the following when Create is accessed from the Search page:
Home > Business > Create
In both the cases the controller/action method is the same, but the breadcrumb I want displayed is different. Is it possible to do this using MvcSiteMapProvider?
As far as I know this is not supported out of the box. Meaning that you have to adapt the HtmlHelper template to you needs, see https://github.com/maartenba/MvcSiteMapProvider/wiki/HtmlHelper-functions.
The only way this can be done is if you add some information to your route to tell one request apart from the other, then you can configure 2 different nodes to create both breadcrumb trails.
I have a working example of how to do that on my blog: http://www.shiningtreasures.com/post/2013/08/10/mvcsitemapprovider-4-seo-features#canonical-tag. Make sure to check out the code download.

How to use a 'switch' to control Controller's Action choices in Rails?

In my new Rails project,I want to provide my user two kinds of category view mode
:one is List mode,other is Detail mode.
In List mode,the category page will just show the title of the article.In Detail mode,the page will show the title and the content.I want to use a 'switch' to control this two mode,when user choice 'List mode',all the category page will be shown in List mode.When they choice 'Detail mode',all the category page will be shown in Detail mode.
I think I could use different Action control this two view mode,so my question is how to set a 'switch' to control these different Actions in the whole site? A Variable?
Also welcome another solution.
Thank you.
You could use a variable and railscasts shows the way again. The new design of railscasts.com implements this sort of a design, where-in it provides an option to view articles in a list/grid fashion.
Since, railscasts is an open-source project, I encourage you to browse through the code in
episodes_controller
and the view episodes#index (he uses params[:view] to switch between different listing styles)
And you'll know exactly what to do.

Rails Shopping Cart Maximum amount

I am working on a rails 3 app and have a shopping cart functionality. On the products page I have Items listed and "Add to Cart". the cart is also rendered on same page as a partial. Now I need functionality to put in a maximum amount allowed in a cart. I have a input box on that page for this. When I click checkout I need to compare the the total cart price against the maximum amount and display appropriate message. Where do (which controller action) I capture form value for the maximum amount?
It would be nice if you add some code. No one is gonna tell you that at least that you said what controllers uses for your shopping cart. Maybe you should add a action in your "shop" controller, and add your restful route in your routes file.

Resources