class - what is the correct way to add classes to a controller in rails? -


if need add (project specific) classes controler in rails, correct way/place put , "include" them/there .rb files? (quotes for: not ruby keyword include)

i new rails, , did not find the correct way. lib sounds more public libraries , - have learned - not reloaded per default in dev mode.

sure, put in controler.rb, ...


the anser me:

first: there no rules, if keep in mind (or learn me) rails rules: nameofcla -> name_of_cla(.rb) <-- not using class word clearence

name class how like:

class extendcon #<--- not using controller here clearence     .... 

put in file extend_con.rb, wait path explaination, please. if named class 'mygreatthing' 'm_y_great_thing' (never testet that), avoid chineese charachters

if controller uses

@letssee=extendcon.new 

rails learns class , file (extend_con) on own. still did not figure out if server restart needed. (the first time)

choose path put file: (i preferre daves way) app/myexten or like, making 'app' specific , still distquishes standard rails 'things'

if not lasy me (i put in app/ontrollers) put path have choosen config/application.rb (comments there find it)

# custom directories classes , modules want autoloadable. # config.autoload_paths += %w(#{config.root}/app/controllers) config.autoload_paths += %w(#{config.root}/app/myexten)    

this 1 workes me in modes including "developer" , did not need put "my own" things in app/lib

it depends.

i tend put library code used explicitly (e.g., instantiated, injected, etc. app-level artifacts) app/xxx xxx signifies "type" of thing, decorators, services, etc.

magic stuff tends end in lib, monkey patches, architectural-level artifacts, , on.

code anywhere can added autoload paths, required automatically initializer, etc.


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -