rails_admin Handling Ancestry Category Trees - ruby-on-rails

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

Related

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.

Dynamic Search Field in Rails

I want to build a search field that give suggestions based on what the user is typing. Like the wikipedia search bar.
It should only query for the title names (not implementing any complex algo). What is the best way to do this with rails: gem and from scratch?
Use select2 jquery plugin. Its documentation is pretty cool as well. Visit https://select2.github.io/examples.html . Pass your collection to your form select box and call the class of it with select2. It will suggest the user according to the input.

Spree Commerce: display multiple categories on one page

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/

HTML select with insertion option

I need to render a <select> with some values.
Those values correspond to a model that the rendered view's model belongs_to - e.g. Foo has_many Bar, I'm rendering Bar, and its form should include Foo's ids and names in the <select>.
That is no problem - right now I'm using simple_form for that.
But in addition to a fixed set of values, the user should be able to insert a new Foo aynchronously (in some popup / whatever), updating the <select> in the browser with the newly-generated id, and the given name.
That is no problem to implement by hand, but is there a Rails feature (like UJS) or plugin (like simple_form) which provides exactly that?
You can try selectize-rails
Examples can be found here. http://brianreavis.github.io/selectize.js/

What is the Rails way to split a view into separate pages?

Within my show action/view I'm displaying a lot of data that I want to split-up into separate pages (in this case three pages total). I can do this easily by adding a new action and view for each additional page, but is that the "correct" way to do it in Rails?
Great question!
I can do this easily by adding a new action and view for each additional page, but is that the "correct" way to do it in Rails?
I suspect you are unsure about violating REST?
I don't know what data you are displaying, but In the end the clearest and simplest solution for you (code wise) and your users (design wise) should win, if that means adding a new action, so be it. Avoid adding a new controller just for the sake of a new show action.
Are you looking for a pagination solution? If so, I would suggest either kaminari or will_paginate. Also, they each have railscast if you need any help getting set up.

Resources