This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ rails _4.2.6_ new sti_object_label | |
... | |
$ cd sti_object_label | |
$ echo "gem 'rails_admin', '~> 0.8.1'" >> Gemfile | |
$ bundle | |
... | |
$ rails _4.2.6_ g rails_admin:install | |
... | |
<enter> | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ rails -v | |
Rails 4.2.6 | |
$ rails new nested_update | |
... | |
$ cd nested_update | |
$ echo "gem 'rails_admin', '~> 0.8.1'" >> Gemfile | |
$ bundle | |
... | |
$ rails g rails_admin:install | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# in host app | |
class Activity | |
def action | |
status_label.downcase | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('#products').append('<%= j render(@products) %>'); | |
<% if @products.next_page %> | |
$('.pagination').replaceWith('<%= j will_paginate(@products) %>'); | |
<% else %> | |
$('.pagination').remove(); | |
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Ingredient < ActiveResource::Base | |
def recipes | |
# returns all recipes with this ingredient as a component | |
Recipe.joins(components).merge(components) | |
end | |
def components | |
Component.where :ingredient_id => id | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Ingredient < ActiveRecord::Base | |
def as_json(options = {}) | |
super(options.merge( | |
:only => [:id, :name], | |
:methods => [:time_to_harvest], | |
:include => { | |
:substitutes => { :only => [:name] } | |
} | |
)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# instead of { "my_model": { "id": 1, "title": "foo" } } | |
# to_json produces { "id": 1, "title": "foo" } | |
ActiveRecord::Base.include_root_in_json = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"id" => 1, | |
"name" => "sassafras" | |
} | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'fakeweb' | |
# this can also be set to a regular expression to whitelist URI's | |
FakeWeb.allow_net_connect = false | |
def load_fixture(name) | |
path = "#{Rails.root}/features/fixtures/#{name}.rb" | |
eval File.open(path).map { |line| line }.join("") | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class IngredientsSweeper < ActionController::Caching::Sweeper | |
observe Ingredient | |
def after_save(record) | |
expire_action :controller => "ingredients", | |
:action => "index", | |
:format => :json | |
expire_action :controller => "ingredients", | |
:action => "show", |
NewerOlder