Searching / Ordering data with inherited_resources in Rails - ruby-on-rails

Is there a popular gem that makes it easier to build an admin interface in Rails that lets you search and order data? Bonus points if it integrates well with inherited_resources.
I don't want to use something as heavyweight as activeadmin.
Looking for something like this:

I found the sorted gem (https://github.com/mynameisrufus/sorted), which allows me to easily build sortable tables.
Ransack (https://github.com/ernie/ransack) lets me easily build searches.

The screenshot you provided is exactly what you are looking for
http://activeadmin.info/

Related

Setting up search page and filter (similar to ecommerce)

I'm building my first rails app and I'm trying to build the search page on an ecommerce type site. The idea is the model pulls all the data from the database according to the filter that is checked or selected on the view such as (category, sub-category, price, date, etc.)
I've watched railscasts on elasticsearch, solar, etc. They seem like they'd each work in this scenario but are they overkill? I'm just not sure what is the quickest and most scalable way to set up this search. I've read a little about the has_scope gem which seems like it would be one way but I can't find a good tutorial or documentation on has_scope. Can someone point me in the right direction for creating this search page? Should I build it out with has_scope, solar, or elasticsearch?
Thanks
In my own experience solr is the best search technology I've come across. It provides a feature called faceting which is what you are describing. You can read about it on their wiki here: http://wiki.apache.org/solr/SolrFacetingOverview
The best solr gem I've come across is sunspot. It has a very easy to use DSL for interfacing with solr from a Rails app and hooks in to active record very easily. Take a look at their github project page. I think that will answer your question.

How to build a Search functionality to search multiple models like GitHub?

I am wondering on how to implement a search functionality like Github.
Just one search box on the top header right and when searched for a keyword, displays the results for Repository, Code and User.
Is there any tutorial or example to implement this on Rails 3?
Odds are really good they're doing separate searches across the tables for the same value, then combining the results afterwards.
Use Rails to create a small form containing a text field. When it's submitted take the value of the field and do a query using that as the search term.
If you're not sure how to do queries using ActiveRecord, see "Active Record Query Interface" for a nice overview.
You will have to do several queries, one per model, and put the results together on the same view.
If your question is "how do I do full text searches on several activerecord models in a DRY way" then there are basically two paths:
The common solution, but a bit complex, is using a dedicated daemon on your machine, like Sphinx. Sphinx is a service in (like Apache or MySQL) that indexes your content and allows you to do searches. You can use the Thinking Sphinx gem to communicate with it easily from rails. An alternative to Sphinx is Solr (there's also a gem for it called Sunspot)
If you are using Postgresql, there's a simpler alternative that doesn't require external services running on your server. Postgresql has with some full-text search capabilities built-in. There's a gem called texticle that helps using these services from rails. You can have that working very quickly.

How can I export a rails model to json schema?

I am looking to optimize how we build forms for some of our models and ideally I would like to build them from json-schema.
Is there a gem or the like which would allow me to export a model definition to json-schema?
Bonus: With validations.
Bonus: While modelling association relationships.
I am working on a gem that creates models based on a JSON Schema: jsonmodel
And I am also working on support for formtastic in a separate gem: jsonmodel-formtastic
Please note that both are a work in progress, but it would be nice to get feedback :-)
Formtastic: http://github.com/justinfrench/formtastic has a mechanism for building forms from the models. Maybe you could base your code on theirs.
Check in lib/formtastic.rb line 474 or so.
Railscast for formtastic: http://railscasts.com/episodes/184-formtastic-part-1
I dont know about a gem that does this, but you could either pull the SQL or Rails schema data and then parse it, even easier if you're working with thw rails schema, as you can parse it by running it in a Ruby DSL.

Pattern to model wiki-type functionality

Is there a pattern or a gem (Ruby on rails) for modeling the wiki-like behaviour of a StackOverflow like web site?
I'm working on Ruby-on-Rails project so a gem or something in RoR would be appreciated but a well defined pattern is just as good.
Thanks
Did you try act_as_versioned? It is available as a gem, and adds simple versioning to any ActiveRecord model.
If you need more features, act_as_revisable might be interesting. According to the link, it adds the following features on top of act_as_versioned:
Pervasive Callbacks
Branching and Changesets
Deletes can be stored as a revision
Explicit is better than implicit
All data for a model is stored in one table
Wrapping up, requirements and installing

How do I do full-text searching in Ruby on Rails?

I would like to do full-text searching of data in my Ruby on Rails application. What options exist?
There are several options available and each have different strengths and weaknesses. If you would like to add full-text searching, it would be prudent to investigate each a little bit and try them out to see how well it works for you in your environment.
MySQL has built-in support for full-text searching. It has online support meaning that when new records are added to the database, they are automatically indexed and will be available in the search results. The documentation has more details.
acts_as_tsearch offers a wrapper for similar built-in functionality for recent versions of PostgreSQL
For other databases you will have to use other software.
Lucene is a popular search provider written in Java. You can use Lucene through its search server Solr with Rails using acts_as_solr.
If you don't want to use Java, there is a port of Lucene to Ruby called Ferret. Support for Rails is added using the acts_as_ferret plugin.
Xapian is another good option and is supported in Rails using the acts_as_xapian plugin.
Finally, my preferred choice is Sphinx using the Ultrasphinx plugin. It is extremely fast and has many options on how to index and search your databases, but is no longer being actively maintained.
Another plugin for Sphinx is Thinking Sphinx which has a lot of positive feedback. It is a little easier to get started using Thinking Sphinx than Ultrasphinx. I would suggest investigating both plugins to determine which fits better with your project.
I can recommend Sphinx. Ryan Bates has a great screencast on using the Thinking Sphinx plugin to create a full-text search solution.
You can use Ferret (which is Lucene written in Ruby). It integrates seamless with Rails using the acts_as_ferret mixin. Take a look at "How to Integrate Ferret With Rails". A alternative is Sphinx.
Two main options, depending on what you're after.
1) Full Text Indexing and MATCH() AGAINST().
If you're just looking to do a fast search against a few text columns in your table, you can simply use a full text index of those columns and use MATCH() AGAINST() in your queries.
Create the full text index in a migration file:
add_index :table, :column, type: :fulltext
Query using that index:
where( "MATCH( column ) AGAINST( ? )", term )
2) ElasticSearch and Searchkick
If you're looking for a full blown search indexing solution that allows you to search for any column in any of your records while still being lightning quick, take a look at ElasticSearch and Searchkick.
ElasticSearch is the indexing and search engine.
Searchkick is the integration library with Rails that makes it very easy to index your records and search them.
Searchkick's README does a fantastic job at explaining how to get up and running and to fine tune your setup, but here is a little snippet:
Install and start ElasticSearch.
brew install elasticsearch
brew services start elasticsearch
Add searchkick gem to your bundle:
bundle add searchkick --strict
The --strict option just tells Bundler to use an exact version in your Gemfile, which I highly recommend.
Add searchkick to a model you want to index:
class MyModel < ApplicationRecord
searchkick
end
Index your records.
MyModel.reindex
Search your index.
matching_records = MyModel.search( "term" )
I've been compiling a list of the various Ruby on Rails search options in this other question. I'm not sure how, or if to combine our questions.
It depends on what database you are using. I would recommend using Solr as it offers up a lot of nice options. The downside is you have to run a separate process for it. I have used Ferret as well, but found it to be less stable in terms of multi-threaded access to the index. I haven't tried Sphinx because it only works with MySQL and Postgres.
Just a note for future reference: Ultra Sphinx is no longer being maintained. Thinking sphinx is its replacement. Although it lacks several features at this time like excerpting which Ultra sphinx had, it makes up for it in other features.
I would recommend acts_as_ferret as I am using it for Scrumpad project at work. The indexing can be done as a separate process which ensures that while re-indexing we can still use our application. This can reduce the downtime of website. Also the searching is much faster. You can search through multiple model at a time and have your results sorted out by the fields you prefer.

Resources