sugar-framework / sugar

Modular web framework for Elixir
https://sugar-framework.github.io/
MIT License
430 stars 29 forks source link

name of the project? #87

Closed ror6ax closed 8 years ago

ror6ax commented 8 years ago

I've created a project by mix new stuff

Following the documentation, added the app to mix.exs:

def application do
  [ applications: [ :sugar ],
    mod: {Stuff, []} ]
end

Unexpectedly:

** (Mix) Application callback module (:mod) should be either [] or {module, start_args} (got {Stuff} instead)

Any hints? Also, I'll be looking into calling a separate function asynchronously from controller. Any hidden magic I should expect with regard to importing?

slogsdon commented 8 years ago

Hi @ror6ax! Sorry for the delay.

Did you create your new application with the --sup flag when calling mix new? If unsure, does your Stuff module look similar to this?

defmodule Stuff do                                                                                                                                                                                                                                                                                                      
  use Application                                                                                                                                                                                                                                                                                                        

  # See http://elixir-lang.org/docs/stable/elixir/Application.html                                                                                                                                                                                                                                                       
  # for more information on OTP Applications                                                                                                                                                                                                                                                                             
  def start(_type, _args) do                                                                                                                                                                                                                                                                                             
    import Supervisor.Spec, warn: false                                                                                                                                                                                                                                                                                  

    children = [                                                                                                                                                                                                                                                                                                         
      # Define workers and child supervisors to be supervised                                                                                                                                                                                                                                                            
      # worker(Stuff.Worker, [arg1, arg2, arg3]),                                                                                                                                                                                                                                                                       
    ]                                                                                                                                                                                                                                                                                                                    

    # See http://elixir-lang.org/docs/stable/elixir/Supervisor.html                                                                                                                                                                                                                                                      
    # for other strategies and supported options                                                                                                                                                                                                                                                                         
    opts = [strategy: :one_for_one, name: Stuff.Supervisor]                                                                                                                                                                                                                                                             
    Supervisor.start_link(children, opts)                                                                                                                                                                                                                                                                                
  end                                                                                                                                                                                                                                                                                                                    
end   

The error message that you are seeing looks to be related to how the {Stuff, []} tuple is being interpreted during the loading of your application. Using the --sup flag during the call sets up all of this for you automatically, and adding :sugar to your applications list is pretty straightforward at that point.

To the other side of your question, there shouldn't be any magic necessary for importing and/or using other modules and functions from within a controller. They are pretty basic modules that follow the Plug specification.

ror6ax commented 8 years ago

Thanks, this works!

YellowApple commented 8 years ago

I've tweaked the docs a bit to reflect the need to use the --sup flag, since that wasn't in there previously.