ruby on rails 3 - RoR 3.0.9 - Passing a variable from routes.rb to application_controller.rb or viceversa -



ruby on rails 3 - RoR 3.0.9 - Passing a variable from routes.rb to application_controller.rb or viceversa -

i have multi site project changes 1 changing 2 variables, 1 within routes.rb , other in application_controller.rb. possible pass variables between these files have alter parameter accomplish alter required?

on routes.rb file utilize variable assign right controller routes should use. example:

def showsite "mysite1" end root :to => "#{showsite}#index"

and on application_controller.rb utilize same parameter domain of site, layouts should utilize , things. example:

before_filter :set_defaults def showsite "mysite1" end def set_defaults if "#{showsite}" == "mysite1" @domain = 'mysite1.com' elsif "#{showsite}" == "mysite2" @domain = 'mysite2.com' else @domain.nil? end end def special_layout "#{showsite}" end

every time want show different version of project need alter 2 variables. know not lot have many times day. im pretty new on ror, if there improve solution please guide me it. thanks!

why not utilize rails initializer. e.g. following:

file: `config/initializers/showsite.rb`

with next content:

myapp::application.config.showsite = 'mysite1'

then should able use:

def showsite myapp::application.config.showsite end

and similar in routes file.

ruby-on-rails-3

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -