Dynamic filter in spree - ruby-on-rails

I use spree(v. 0.70.5) an I need realize dinamic filters for product. Options for the filter defined by the current taxon.
What should I do?

Related

limiting tags to use with ActsAsTaggableOn

I'm currently evaluating whether to use ActsAsTaggableOn or roll my own.
I can't have users create tags at random but want to define a list of allowed tags for a project model. Users associated with that project can only select the tags that are allowed for that project (through project and tag model where a project can have multiple tags).
The sane thing to do seems to use ActsAsTaggableOn, but after googling for more than one hour I can't find a lot of documentation on my use-case.
I haven't used ActsAsTaggableOn but if your only issue is retricting what tags can be selected, that should be easy.
Use a gem like chosen-rails to make a nice selector to choose tags from an array of allowed tags that you supply. The returned array of selected tags are assigned to your acts_as_taggable_on field.
If the ActsAsTaggableOn doesn't support array input (I'm not clear on that) make the array an attr_accessor field such as tag_array and then do
my_object.my_tags = tag_array.join(',')

ng-tables using custom names for my filters

I'm trying to use ng-table filters with a search backend called ransack (under Ruby on Rails) is there a way to use custom filter names?
eg:
description_cont
When used with ransack this will look for any text within description.

Multiple select field in LocomotiveCMS?

I need to set up a field in LocomotiveCMS that is similar to Select but allows multiple selections. Something like in HTML... does LocomotiveCMS allow for that, or will I have to do some ruby coding to get that to work?
Any help would be appreciated, thanks!
Old question but still a thing.
I'm unsure whether your question relates to fields within the Locomotive CMS Back Office or on the front end so I've addressed both below.
Front End
Irrespective of whether or not you're dealing with Locomotive CMS content types, either of the following will allow selection of multiple values on the front end:
Listbox (select element with the multiple attribute)
A series of checkbox inputs with the same value in the name property
Back Office
If you need to allow selection of multiple values within the Back Office, you can do this for content types using the has_many or many_to_many content type relationships.
If you need multiple value selection outside of content types (e.g. in metafields schema) you're unfortunately out of luck.

How can I make a rails model searchable by the user?

I'm trying to expose a search feature in rails. I want a user to be able to enter a string like name:"john" color:"blue" and get a list of ActiveRecord objects for some model that have a name attribute containing john and a color attribute containing blue. I'd also like them to be able to use and and or and parentheses e.g. name:"john" or color:"blue" or (name:"john" color:"blue") or name:"bill". Ideally they could also use things like age<20 where age is an numeric field. Is there a rails plugin that does this. I've was looking briefly at sphinx and ferret both of which seem to create an api for this but it was unclear whether they provided a clear text based option or if I would need to parse the search strings myself.
Ernie's Ransack gem is a good place to start.
You will have to provide an intermediate layer between your submitted form and the Ransack code (this would be a good idea anyway for security reasons) to convert strings from the format you desire to something Ransack can understand.
If you check the demo page and the documentation for the gem you'll find it's quite simple to create the sort of queries you're after.
Watch how GET requests are generated from the conditions you build and in your application replace the builder Ernie has in the demo with a single textfield accepting strings like (name:"john" color:"blue") or name:"bill". Do some pattern matching when this field is submitted and build a proper querystring to pass onto the Ransack gem.
Edit
For future questions like "what's a popular gem for ______?", check out The Ruby Toolbox. If Ransack doesn't suit your needs, perhaps a gem in the Rails Search category has what you're looking for. I personally use Ransack for exactly what you're describing; providing a custom query interface for my application's User model.
I'd suggest doing your own search class. I find that for each app I do, the needs of search change considerably and it's simple enough to create a search app that considers all the variables you might want in a search query, posed against any number of classes you want to search.
In your Search class, have it return a collection, in the order you desire, and the collection can be made up of object instances that the searcher may desire.

Best way to implement simple sorting / searching in Rails

What's the best way to implement an interface that looks like this in rails?
Currently I'm using Searchlogic, and it's a tad painful. Problems include:
Making sure certain operations remain orthogonal -- for example, if you select "Short Posts" and then search, your search results should be restricted to short posts.
Making sure the correct link gets the "selected" class. Right now the links are <a>'s, so maintaining this state client-side is tricky. I'm hacking it by having the AJAX response to, say, sorting return a new sort links section with the correct link "selected". Using radio buttons instead of <a> tags would make it easier to maintain state client-side -- maybe I should do that?
I recently solved a similar problem using named_scopes and some ruby metaprogramming that I rolled up into a plugin called find_by_filter.
find_by_filter accepts a hash of scope
names and values, and chains them into
parametised scope calls. If the model has a named_scope that matches the provided name, this is called.If no named_scope is found, an anonymous scope is created.

Resources