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
## Changeset Errors in a string | |
Enum.join(Enum.map(changeset.errors, fn(x) -> {a, b} = x; Atom.to_string(a) <> " " <> b; end), ",") | |
## Refund | |
alias Nectar.Repo; alias Nectar.LineItemReturn; alias Nectar.Refund | |
lr = Repo.get(LineItemReturn, 4) ## Change 4 to relevant id | |
c = Ecto.build_assoc(lr, :refund) | |
r = Refund.create_changeset(c, %{"amount" => 20}) | |
r.errors |
http://blog.codeclimate.com/blog/2012/10/17/7-ways-to-decompose-fat-activerecord-models/
- wisper: A micro library providing Ruby objects with Publish-Subscribe capabilities
- Service Objects https://blog.lelonek.me/what-service-objects-are-not-7abef8aa2f99#.fw7qvlure
- A Ruby implementation of an EventStore based on Active Record.
- Interactor provides a common interface for performing complex user interactions.
- Inspired from Light Service
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
add support for removing from schema as well | |
diff --git a/apps/nectar/web/models/product.ex b/apps/nectar/web/models/product.ex | |
index 100e830..38174a7 100644 | |
--- a/apps/nectar/web/models/product.ex | |
+++ b/apps/nectar/web/models/product.ex | |
@@ -2,7 +2,8 @@ defmodule Nectar.ModelExtension do | |
defmacro __using__(_opts) do | |
quote do | |
Module.register_attribute(__MODULE__, :schema_changes, accumulate: true) |
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
defmodule Nectar.ModelExtension do | |
defmacro __using__(_opts) do | |
quote do | |
Module.register_attribute(__MODULE__, :schema_changes, accumulate: true) | |
Module.register_attribute(__MODULE__, :remove_schema_changes, accumulate: true) | |
import Nectar.ModelExtension, only: [add_to_schema: 1, remove_from_schema: 1] | |
@before_compile Nectar.ModelExtension | |
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
# Without this fix, downgrading from Rails 4 to Rails 3 causes session cookies to blow up. | |
# | |
# The way the flash is stored in the session changed in a backwards-incompatible way. | |
if Rails::VERSION::MAJOR == 3 | |
module ActionDispatch | |
class Flash | |
def call(env) | |
if (session = env['rack.session']) && (flash = session['flash']) |
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
# Refer https://github.com/phoenixframework/phoenix/blob/master/lib/phoenix/view.ex#L136 | |
# For inspiration and implementation | |
defmodule Nectar.Web do | |
def view do | |
quote do | |
import unquote(__MODULE__), only: [template_root_folder: 1] | |
use Phoenix.View, root: template_root_folder(__MODULE__) | |
... | |
end | |
end |