Skip to content

Instantly share code, notes, and snippets.

View haslinger's full-sized avatar
🏠
Working from home

Stefan Haslinger haslinger

🏠
Working from home
View GitHub Profile
@haslinger
haslinger / 0001 Sortable tree structure for Hobo .markdown
Last active December 30, 2015 04:39
Sortable tree structure for Hobo

Sortable tree structure for Hobo

I like the ability to have draggable and sortable lists via acts-as-list in Hobo, but I needed more:

I had a hierarchical structure, like a category tree, that needed to be sortable. I wanted a drag and drop interface. Furthermore the updates should be immediate via Ajax. Because this can take a while for huge trees, the user should be informed clearly, but unobtrusively, when update started, when update suceeded and when it failed.

I found Hobo to be compatible with the Ancestry gem and it plays nicely with Nestable.js and Messenger.js and it doesn't break the Bootstrap look and feel too much.

@haslinger
haslinger / 0002 Live CKEditor in Hobo.markdown
Last active September 22, 2016 17:48
Live CKEditor in Hobo

Live CKEditor in Hobo

This in a quite ugly hack ... but its working ...

It is actually quite easy to enable inline editing in Hobo using Clickeditor, which is awesome. It is also possible to use Ckeditor in Hobo, which is awesome as well.

There is even some integration between the two, so clicking on a cktext-attribute unhides the already embedded CkEditor. But unfortunately, you can't save, there isn't even a save button.

@haslinger
haslinger / 0003 Migraton generator hack.markdown
Last active December 30, 2015 13:49
Tricking the migration generator when having two models with same table_namein Hobo

Two models / same table_name in Hobo

I had the following issue:

A hobo model like this:

class Category < ActiveRecord::Base
  hobo_model
  fields do
@haslinger
haslinger / 0004 Translation of Enum-Tags in Hobo.markdown
Last active December 31, 2015 00:39
EnumStings in Hobo can be translated easily.

EmumStrings are an awesome feature of Hobo for a set of constants for select-options, that should be localized (gender, titles, types,...).

I didn't understand how to translate Hobo EnumStrings (I believe I saw other things on Hobocentral).

My thanks go to Iox, who helped me figure it out.

The most tricky part for me is the key: contentelement/markups: in the .yml file

  • The Model class is named ContentElement (so neither ContentElement nor content_elements is right here)

Hobo can even create an autocompletion for relations from the has_many side of a relation.

Started GET "/story_statuses/index2" for 127.0.0.1 at 2013-12-25 15:50:49 +0100
Processing by StoryStatusesController#index2 as HTML
  User Load (0.2ms)  SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1  [["id", "1"]]
DEPRECATION WARNING: Relation#all is deprecated. If you want to eager-load a relation, you can call #load (e.g. `Post.where(published: true).load`). If you want to get an array of records from a relation, you can call #to_a (e.g. `Post.where(published: true).to_a`). (called from block in dev_user_changer at /var/rails/hobo/hobo_clean/taglibs/nav.dryml:5)
  User Load (0.4ms)  SELECT "users".* FROM "users" LIMIT 30
  StoryStatus Load (0.4ms)  SELECT "story_statuses".* FROM "story_statuses" LIMIT 30 OFFSET 0
   (0.2ms)  SELECT COUNT(*) FROM "story_statuses"
  Rendered story_statuses/index2.dryml (119.9ms)
Completed 500 Internal Server Error in 126ms

Works also on Linux Mint LMDE, see Guide for details. Even if I got everything running, I'm still prefering to deploy to my own servers, it was a hassle. Sometimes deploying free applications is dead slow.

  • Installing the Heroku on Ubuntu wget -qO- https://toolbelt.heroku.com/install-ubuntu.sh | sh
  • Login heroku login
  • Add Repo git remote add heroku git@heroku.com:autocomplete-has-many-demo.git
  • Push
@haslinger
haslinger / 0006 Paste Upload in Hobo.markdown
Last active August 29, 2015 13:55
Uploading images by pasting them into a HTML Element
@haslinger
haslinger / 0007 Hobo Ajax features and Faye Messaging Server.markdown
Last active August 29, 2015 13:56
Hobo Ajax features and Faye Messaging Server

A few weeks ago I posted about a poor man's chat server I created with Hobo's Ajax features. I now had the request to improve performance, so I tried to fix it.

I pimped my old solution with a Faye messaging server: Ryan Bates created a gem and a Railscast about it.

Lets see how we update data on all connected clients but only when necessary. In conversation.dryml we subscribe to a faye server:

<%= subscribe_to "/conversations/" + this.id.to_s %>
@haslinger
haslinger / 0008 Integration of Elastic Search into Hobo.markdown
Last active August 29, 2015 14:01
Integration of Elastic Search into Hobo

I have got a Webshop applacation with a structure of 1700 products in 400 product categories through categorizations, and 1600 product properties in 1100 property groups and their 105 000 values.

For filtering and wanted to have a facetted search on category level on the values, like in the screenshot in the file facets.png

In the /Gemfile I load the Searchkick Gem:

gem "searchkick"                                    # Elastic Search integration