Spree Commerce: display multiple categories on one page - ruby-on-rails

I'm trying to make a link that can open or go to other page that display several categories on one page, like this: mugs, bags, and books
Is it possible to achieve this without using deface or modifying any page?
Maybe a normal link like:
https://www.example.com/t/categories/mugs,bags,books
https://www.example.com/products?taxon=1,3,5
I've tried both of them. I get error from the former and get the first category from the latter.
If deface is the only solution, how to do it if I want the link to look like the first link?
If it helps, I use rails 4.2.1 and spree 3.0.1.

I don't think you get this sort of functionality by default in Spree. You're going to have to come up with a custom action that is capable of accepting the multiple categories and returning the products filtered by that category.

You should be able to set this up by through the admin panel in
"Products" --> "Taxonomies"
If you edit "Categories" and add subcategories of "Mugs", "Bags" and "Books" you should be able to get what you are after via
https://www.example.com/t/categories/

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 insert a page break manually in Rails?

In my project, an Article has many Items within it. Since each Item has different length, so I would like to implement pagination manually, for example, by creating a PageBreakItem model, in order to allow users insert page breaks wherever they want. But I don't know how to use "page" parameter in controller to render views correctly.
Some gems like kaminari or will_paginate only allow me to configure the number of items per page. They don't have options for inserting page breaks manually.
Any suggestions are greatly appreciated.
You don't need a special model for this. You could do this with small adaptation of your Item model:
Add sort_order numeric field to denote order of items within the article and is_on_new_page boolean field to denote a page break occurring before that article.

RAILS 4 Dynamic generating of select tag

I have two select tags/controls and I need the second select tag options to be dynamically generate based on the selection of first
For example I want to make after selecting a car brand in first select, the second must show the models of selected car brand, But I have not been able to do it please help
Please watch rails cast #88 dynamic select menus revised. The method you need to do this called grouped_collection_select
This method along with the proper coffee script (or JavaScript if you prefer that more than coffeescript) discussed in the video will complete exactly what you're looking for

rails_admin Handling Ancestry Category Trees

I'm evaluating rails_admin but am coming up against a problem with our use of the ancestry gem. In an admin context the default rails_admin simply displays the ancestry key as a text value (which is not that useful).
What would be better would be the ability to view the ancestry (up and down) for a given category in the show view, and to be able to select a new parent in the edit view (i've managed to create the dropdown, but not the control to preselect the current parent if there is one).
Have you come across this problem and do you have any ideas how to get round it?
Thanks!
I wrote this plugin using jquery nestable: https://github.com/dalpo/rails_admin_nestable
For more details see the github readme.
I have proper rendering of hierarchies with https://github.com/mceachen/closure_tree. Haven't tried ancestry with it though.
Give it a try and let us know

Kaminari pagination, how to get the number of the current page?

I am using Kaminari to paginate some results from a db query.
I would like to apply specific styling to the first page of the results.
The operation is very easy once I know on what page the user is, but I can't find a way to detect the current page.
If you want to check for first page you can do it like this:
if object.first_page?
#your logic here
end
If you find the specific page you can do something like this:
current_page_no = object.current_page
For more info refer: http://www.rubydoc.info/github/amatsuda/kaminari/master/Kaminari/PageScopeMethods
Have you generated the partials that kaminari uses?
See the section titled "Customizing the pagination helper" here:
https://github.com/amatsuda/kaminari
Oncey ou do that, you can edit the _paginator.html.erb file (or other kaminari partials if you need to) in order to get the pagination functionality you're looking for. These partials allow you to use local variables, like "current_page", "num_pages" and a few more. Sounds like that's what you're looking for.
Here's what those partials look like, if you want to see them before running the generator:
https://github.com/amatsuda/kaminari/tree/master/app/views/kaminari
Hope that points you in the right direction.
2020 Update. As of now I am able to do #users.current_page.

Resources