Fixed multi coop routing and changed config accessors.
This commit is contained in:
parent
2860a3ca44
commit
ec2e761e7f
|
@ -5,7 +5,6 @@ db/*.sqlite3
|
|||
nbproject/
|
||||
config/environments/development.rb
|
||||
capfile
|
||||
config/environments/fcschinke09.rb
|
||||
*.swp
|
||||
public/**/*_cached.*
|
||||
.idea
|
||||
|
|
|
@ -1 +1,4 @@
|
|||
TODO..
|
||||
MULTI_COOP_INSTALL
|
||||
------------------
|
||||
|
||||
TODO ...
|
|
@ -5,8 +5,6 @@ class ApplicationController < ActionController::Base
|
|||
before_filter :select_foodcoop, :authenticate, :store_controller, :items_per_page, :set_redirect_to
|
||||
after_filter :remove_controller
|
||||
|
||||
helper_method :current_user
|
||||
|
||||
# Returns the controller handling the current request.
|
||||
def self.current
|
||||
Thread.current[:application_controller]
|
||||
|
@ -18,9 +16,10 @@ class ApplicationController < ActionController::Base
|
|||
# check if there is a valid session and return the logged-in user (its object)
|
||||
if session[:user_id] and params[:foodcoop]
|
||||
# for shared-host installations. check if the cookie-subdomain fits to request.
|
||||
@current_user ||= User.find_by_id(session[:user_id]) if params[:foodcoop] == Foodsoft.env
|
||||
@current_user ||= User.find_by_id(session[:user_id]) if session[:scope] == FoodsoftConfig.scope
|
||||
end
|
||||
end
|
||||
helper_method :current_user
|
||||
|
||||
def deny_access
|
||||
self.return_to = request.request_uri
|
||||
|
@ -104,28 +103,22 @@ class ApplicationController < ActionController::Base
|
|||
# It uses the subdomain to select the appropriate section in the config files
|
||||
# Use this method as a before filter (first filter!) in ApplicationController
|
||||
def select_foodcoop
|
||||
if Foodsoft.config[:multi_coop_install]
|
||||
if !params[:foodcoop].blank?
|
||||
if FoodsoftConfig[:multi_coop_install]
|
||||
if params[:foodcoop].present?
|
||||
begin
|
||||
# Set Config
|
||||
Foodsoft.env = params[:foodcoop]
|
||||
# Set database-connection
|
||||
ActiveRecord::Base.establish_connection(Foodsoft.database)
|
||||
# Set Config and database connection
|
||||
FoodsoftConfig.select_foodcoop params[:foodcoop]
|
||||
rescue => error
|
||||
flash[:error] = error.to_s
|
||||
redirect_to root_path
|
||||
redirect_to root_url, alert: error.message
|
||||
end
|
||||
else
|
||||
redirect_to root_path
|
||||
redirect_to root_url
|
||||
end
|
||||
else
|
||||
# Deactivate routing filter
|
||||
RoutingFilter::Foodcoop.active = false
|
||||
end
|
||||
end
|
||||
|
||||
def items_per_page
|
||||
if (params[:per_page] && params[:per_page].to_i > 0 && params[:per_page].to_i <= 100)
|
||||
if params[:per_page] && params[:per_page].to_i > 0 && params[:per_page].to_i <= 100
|
||||
@per_page = params[:per_page].to_i
|
||||
else
|
||||
@per_page = 20
|
||||
|
@ -143,4 +136,9 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
default
|
||||
end
|
||||
|
||||
# Always stay in foodcoop url scope
|
||||
def default_url_options(options = {})
|
||||
{foodcoop: FoodsoftConfig.scope}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -127,13 +127,13 @@ class OrdersController < ApplicationController
|
|||
def text_fax_template
|
||||
order = Order.find(params[:id])
|
||||
supplier = order.supplier
|
||||
contact = Foodsoft.config[:contact].symbolize_keys
|
||||
text = "Bestellung für" + " #{Foodsoft.config[:name]}"
|
||||
contact = FoodsoftConfig[:contact].symbolize_keys
|
||||
text = "Bestellung für" + " #{FoodsoftConfig[:name]}"
|
||||
text += "\n" + "Kundennummer" + ": #{supplier.customer_number}" unless supplier.customer_number.blank?
|
||||
text += "\n" + "Liefertag" + ": "
|
||||
text += "\n\n#{supplier.name}\n#{supplier.address}\nFAX: #{supplier.fax}\n\n"
|
||||
text += "****** " + "Versandadresse" + "\n\n"
|
||||
text += "#{Foodsoft.config[:name]}\n#{contact[:street]}\n#{contact[:zip_code]} #{contact[:city]}\n\n"
|
||||
text += "#{FoodsoftConfig[:name]}\n#{contact[:street]}\n#{contact[:zip_code]} #{contact[:city]}\n\n"
|
||||
text += "****** " + "Artikel" + "\n\n"
|
||||
text += "Nummer" + " " + "Menge" + " " + "Name" + "\n"
|
||||
# now display all ordered articles
|
||||
|
|
|
@ -10,6 +10,7 @@ class SessionsController < ApplicationController
|
|||
user = User.authenticate(params[:nick], params[:password])
|
||||
if user
|
||||
session[:user_id] = user.id
|
||||
session[:scope] = FoodsoftConfig.scope # Save scope in session to not allow switching between foodcoops with one account
|
||||
redirect_to session['return_to'] || root_url, :notice => "Logged in!"
|
||||
else
|
||||
flash.now.alert = "Invalid email or password"
|
||||
|
|
|
@ -4,15 +4,15 @@ class Mailer < ActionMailer::Base
|
|||
|
||||
layout 'email' # Use views/layouts/email.txt.erb
|
||||
|
||||
default from: "FoodSoft <#{Foodsoft.config[:email_sender]}>",
|
||||
sender: Foodsoft.config[:email_sender],
|
||||
errors_to: Foodsoft.config[:email_sender]
|
||||
default from: "FoodSoft <#{FoodsoftConfig[:email_sender]}>",
|
||||
sender: FoodsoftConfig[:email_sender],
|
||||
errors_to: FoodsoftConfig[:email_sender]
|
||||
|
||||
# Sends an email copy of the given internal foodsoft message.
|
||||
def foodsoft_message(message, recipient)
|
||||
@message = message
|
||||
|
||||
mail subject: "[#{Foodsoft.config[:name]}] " + message.subject,
|
||||
mail subject: "[#{FoodsoftConfig[:name]}] " + message.subject,
|
||||
to: recipient.email,
|
||||
from: "#{message.sender.nick} <#{message.sender.email}>"
|
||||
end
|
||||
|
@ -24,7 +24,7 @@ class Mailer < ActionMailer::Base
|
|||
@link = url_for(:controller => "login", :action => "password", :id => user.id, :token => user.reset_password_token)
|
||||
|
||||
mail :to => user.email,
|
||||
:subject => "[#{Foodsoft.config[:name]}] Neues Passwort für/ New password for #{user.nick}"
|
||||
:subject => "[#{FoodsoftConfig[:name]}] Neues Passwort für/ New password for #{user.nick}"
|
||||
end
|
||||
|
||||
# Sends an invite email.
|
||||
|
@ -33,7 +33,7 @@ class Mailer < ActionMailer::Base
|
|||
@link = url_for(:controller => "login", :action => "invite", :id => invite.token)
|
||||
|
||||
mail :to => invite.email,
|
||||
:subject => "Einladung in die Foodcoop #{Foodsoft.config[:name]} - Invitation to the Foodcoop"
|
||||
:subject => "Einladung in die Foodcoop #{FoodsoftConfig[:name]} - Invitation to the Foodcoop"
|
||||
end
|
||||
|
||||
# Notify user of upcoming task.
|
||||
|
@ -42,7 +42,7 @@ class Mailer < ActionMailer::Base
|
|||
@task = task
|
||||
|
||||
mail :to => user.email,
|
||||
:subject => "[#{Foodsoft.config[:name]}] Aufgaben werden fällig!"
|
||||
:subject => "[#{FoodsoftConfig[:name]}] Aufgaben werden fällig!"
|
||||
end
|
||||
|
||||
# Sends order result for specific Ordergroup
|
||||
|
@ -51,7 +51,7 @@ class Mailer < ActionMailer::Base
|
|||
@group_order = group_order
|
||||
|
||||
mail :to => user.email,
|
||||
:subject => "[#{Foodsoft.config[:name]}] Bestellung beendet: #{group_order.order.name}"
|
||||
:subject => "[#{FoodsoftConfig[:name]}] Bestellung beendet: #{group_order.order.name}"
|
||||
end
|
||||
|
||||
# Notify user if account balance is less than zero
|
||||
|
@ -60,17 +60,17 @@ class Mailer < ActionMailer::Base
|
|||
@transaction = transaction
|
||||
|
||||
mail :to => user.email,
|
||||
:subject => "[#{Foodsoft.config[:name]}] Gruppenkonto im Minus"
|
||||
:subject => "[#{FoodsoftConfig[:name]}] Gruppenkonto im Minus"
|
||||
end
|
||||
|
||||
def feedback(user, feedback)
|
||||
@user = user
|
||||
@feedback = feedback
|
||||
|
||||
mail :to => Foodsoft.config[:notification]["error_recipients"],
|
||||
mail :to => FoodsoftConfig[:notification]["error_recipients"],
|
||||
:from => "#{user.nick} <#{user.email}>",
|
||||
:sender => Foodsoft.config[:notification]["sender_address"],
|
||||
:errors_to => Foodsoft.config[:notification]["sender_address"],
|
||||
:sender => FoodsoftConfig[:notification]["sender_address"],
|
||||
:errors_to => FoodsoftConfig[:notification]["sender_address"],
|
||||
:subject => "[Foodsoft] Feeback von #{user.email}"
|
||||
end
|
||||
|
||||
|
@ -79,7 +79,7 @@ class Mailer < ActionMailer::Base
|
|||
@user = user
|
||||
|
||||
mail :to => user.email,
|
||||
:subject => "[#{Foodsoft.config[:name]}] \"#{task.name}\" braucht noch Leute!"
|
||||
:subject => "[#{FoodsoftConfig[:name]}] \"#{task.name}\" braucht noch Leute!"
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -33,7 +33,7 @@ class Article < ActiveRecord::Base
|
|||
|
||||
# The price for the foodcoop-member.
|
||||
def fc_price
|
||||
(gross_price * (Foodsoft.config[:price_markup] / 100 + 1)).round(2)
|
||||
(gross_price * (FoodsoftConfig[:price_markup] / 100 + 1)).round(2)
|
||||
end
|
||||
|
||||
# Returns true if article has been updated at least 2 days ago
|
||||
|
@ -120,8 +120,8 @@ class Article < ActiveRecord::Base
|
|||
false
|
||||
end
|
||||
else # get factors for fc and supplier
|
||||
fc_unit_factor = Foodsoft.config[:units][self.unit]
|
||||
supplier_unit_factor = Foodsoft.config[:units][self.shared_article.unit]
|
||||
fc_unit_factor = FoodsoftConfig[:units][self.unit]
|
||||
supplier_unit_factor = FoodsoftConfig[:units][self.shared_article.unit]
|
||||
if fc_unit_factor and supplier_unit_factor
|
||||
convertion_factor = fc_unit_factor / supplier_unit_factor
|
||||
new_price = BigDecimal((convertion_factor * shared_article.price).to_s).round(2)
|
||||
|
|
|
@ -27,7 +27,7 @@ class ArticlePrice < ActiveRecord::Base
|
|||
|
||||
# The price for the foodcoop-member.
|
||||
def fc_price
|
||||
(gross_price * (Foodsoft.config[:price_markup] / 100 + 1)).round(2)
|
||||
(gross_price * (FoodsoftConfig[:price_markup] / 100 + 1)).round(2)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -168,7 +168,7 @@ class GroupOrderArticle < ActiveRecord::Base
|
|||
# will be the value depending of the article results.
|
||||
def total_price
|
||||
unless order_article.order.finished?
|
||||
if Foodsoft.config[:tolerance_is_costly]
|
||||
if FoodsoftConfig[:tolerance_is_costly]
|
||||
order_article.article.fc_price * (quantity + tolerance)
|
||||
else
|
||||
order_article.article.fc_price * quantity
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
class SharedArticle < ActiveRecord::Base
|
||||
|
||||
# connect to database from sharedLists-Application
|
||||
SharedArticle.establish_connection(Foodsoft.config[:shared_lists])
|
||||
SharedArticle.establish_connection(FoodsoftConfig[:shared_lists])
|
||||
# set correct table_name in external DB
|
||||
set_table_name :articles
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
class SharedSupplier < ActiveRecord::Base
|
||||
|
||||
# connect to database from sharedLists-Application
|
||||
SharedSupplier.establish_connection(Foodsoft.config[:shared_lists])
|
||||
SharedSupplier.establish_connection(FoodsoftConfig[:shared_lists])
|
||||
# set correct table_name in external DB
|
||||
set_table_name :suppliers
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#{data_to_js(@ordering_data)}
|
||||
setGroupBalance(#{@ordering_data[:available_funds]});
|
||||
setDecimalSeparator(",");
|
||||
setToleranceBehaviour(#{Foodsoft.config[:tolerance_is_costly]});
|
||||
setToleranceBehaviour(#{FoodsoftConfig[:tolerance_is_costly]});
|
||||
setStockit(#{@order.stockit?});
|
||||
});
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
%b= h category
|
||||
%td{:colspan => "9"}
|
||||
- order_articles.each do |order_article|
|
||||
- if Foodsoft.config[:tolerance_is_costly]
|
||||
- if FoodsoftConfig[:tolerance_is_costly]
|
||||
- article_total = @price[i] * (@tolerance[i] + @quantity[i])
|
||||
- else
|
||||
- article_total = @price[i] * @quantity[i]
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#logo
|
||||
= link_to root_path do
|
||||
<span>food</span>soft
|
||||
%span{:style => "color:white; font-size:45%; letter-spacing: -1px;"}= Foodsoft.config[:name]
|
||||
%span{:style => "color:white; font-size:45%; letter-spacing: -1px;"}= FoodsoftConfig[:name]
|
||||
#nav= render :partial => 'layouts/main_tabnav'
|
||||
|
||||
#main
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
|
||||
--
|
||||
FoodSoft: <%= root_url %>
|
||||
Foodcoop-Homepage: <%= Foodsoft.config[:homepage] %>
|
||||
Hilfe/Help: <%= Foodsoft.config[:help_url] %>
|
||||
Foodcoop-Homepage: <%= FoodsoftConfig[:homepage] %>
|
||||
Hilfe/Help: <%= FoodsoftConfig[:help_url] %>
|
||||
|
|
|
@ -15,4 +15,4 @@
|
|||
= yield
|
||||
#meta
|
||||
Foodcoop
|
||||
= link_to_if Foodsoft.config[:homepage], Foodsoft.config[:name], Foodsoft.config[:homepage]
|
||||
= link_to_if FoodsoftConfig[:homepage], FoodsoftConfig[:name], FoodsoftConfig[:homepage]
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
- title "Einladung in die #{Foodsoft.config[:name]}"
|
||||
- title "Einladung in die #{FoodsoftConfig[:name]}"
|
||||
%p
|
||||
Du bist eingeladen worden als Mitglied der Gruppe
|
||||
%b= @invite.group.name
|
||||
in der Foodcoop
|
||||
= Foodsoft.config[:name]
|
||||
= FoodsoftConfig[:name]
|
||||
mitzumachen.
|
||||
%p
|
||||
Wenn Du mitmachen möchtest, dann fülle bitte dieses Formular aus.
|
||||
|
|
|
@ -6,4 +6,4 @@ Es wurden <%= @transaction.amount %> für "<%= @transaction.note %>" abgebucht,
|
|||
|
||||
Bitte zahlt so bald wie möglich wieder Geld ein, um das Gruppenkonto auszugleichen.
|
||||
|
||||
Viele Grüße von <%= Foodsoft.config[:name] %>
|
||||
Viele Grüße von <%= FoodsoftConfig[:name] %>
|
|
@ -11,4 +11,4 @@ Gesamtpreis: <%= @group_order.price %>
|
|||
|
||||
Bestellung online einsehen: <%= group_order_url(@group_order) %>
|
||||
|
||||
Viele Grüße von <%= Foodsoft.config[:name] %>
|
||||
Viele Grüße von <%= FoodsoftConfig[:name] %>
|
|
@ -12,4 +12,4 @@ Aufgaben für die nächste Woche:
|
|||
|
||||
Meine Aufgaben: <%= user_tasks_url %>
|
||||
|
||||
Viele Grüße von <%= Foodsoft.config[:name] %>
|
||||
Viele Grüße von <%= FoodsoftConfig[:name] %>
|
|
@ -21,18 +21,18 @@
|
|||
- title "Neue Nachricht"
|
||||
|
||||
= simple_form_for @message do |f|
|
||||
- if Foodsoft.config[:mailing_list].blank?
|
||||
- if FoodsoftConfig[:mailing_list].blank?
|
||||
= f.input :sent_to_all, :as => :boolean
|
||||
- else
|
||||
%b Nachrichten an alle
|
||||
verschickst Du bitte über den Verteiler:
|
||||
= mail_to Foodsoft.config[:mailing_list]
|
||||
= mail_to FoodsoftConfig[:mailing_list]
|
||||
%br/
|
||||
%small{:style => "color:grey"}
|
||||
Eventuell musst Du Dich dem Verteiler erst bekannt machen.
|
||||
%br/
|
||||
z.b. mit einer Mail an
|
||||
= mail_to Foodsoft.config[:mailing_list_subscribe]
|
||||
= mail_to FoodsoftConfig[:mailing_list_subscribe]
|
||||
|
||||
#recipients
|
||||
= f.input :recipient_tokens, :input_html => { 'data-pre' => User.find_all_by_id(@message.recipients_ids).map { |u| u.token_attributes }.to_json }
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Get ActiveRecord objects
|
||||
contact = Foodsoft.config[:contact].symbolize_keys
|
||||
contact = FoodsoftConfig[:contact].symbolize_keys
|
||||
|
||||
# Define header and footer
|
||||
#pdf.header [pdf.margin_box.left,pdf.margin_box.top+30] do
|
||||
|
@ -12,7 +12,7 @@ end
|
|||
|
||||
# From paragraph
|
||||
pdf.bounding_box [pdf.margin_box.right-200,pdf.margin_box.top], :width => 200 do
|
||||
pdf.text Foodsoft.config[:name], :align => :right
|
||||
pdf.text FoodsoftConfig[:name], :align => :right
|
||||
pdf.move_down 5
|
||||
pdf.text contact[:street], :align => :right
|
||||
pdf.move_down 5
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
%li
|
||||
= image_tag 'b_user.png' , :size => '7x10', :border => 0, :alt => "Profil"
|
||||
= link_to h(@current_user.nick), my_profile_path, { :title => "Profil bearbeiten" }
|
||||
- if Foodsoft.config[:homepage]
|
||||
%li= link_to Foodsoft.config[:name], Foodsoft.config[:homepage], { :title => "Go to your FoodCoop-Hompage" }
|
||||
- if FoodsoftConfig[:homepage]
|
||||
%li= link_to FoodsoftConfig[:name], FoodsoftConfig[:homepage], { :title => "Go to your FoodCoop-Hompage" }
|
||||
%li= link_to "Hilfe", 'http://dev.foodcoops.net/wiki/FoodsoftDoku'
|
||||
%li= link_to "Feedback", new_feedback_path, :title => "Fehler gefunden? Vorschlag? Idee? Kritik?"
|
||||
%li= link_to "Abmelden", logout_path
|
|
@ -1,10 +1,13 @@
|
|||
# Foodsoft configuration
|
||||
|
||||
development: &defaults
|
||||
default: &defaults
|
||||
# If you wanna serve more than one foodcoop with one installation
|
||||
# Don't forget to setup databases for each foodcoop. See also MULTI_COOP_INSTALL
|
||||
multi_coop_install: false
|
||||
|
||||
# If multi_coop_install you have to use a coop name, which you you wanna be selected by default
|
||||
default_scope: 'f'
|
||||
|
||||
# http config for this host
|
||||
# Required for action mailer
|
||||
protocol: http
|
||||
|
@ -75,6 +78,9 @@ development: &defaults
|
|||
100g: 0.1
|
||||
50g: 0.05
|
||||
|
||||
development:
|
||||
<<: *defaults
|
||||
|
||||
test:
|
||||
<<: *defaults
|
||||
|
||||
|
|
|
@ -1,28 +1,15 @@
|
|||
# Loads and returns config and databases for selected foodcoop.
|
||||
# TODO: When to use class or module. It seems this could also be a Foodsoft-class?
|
||||
module Foodsoft
|
||||
mattr_accessor :env, :config, :database
|
||||
CONFIGS = YAML.load(File.read(File.join(Rails.root, "/config/app_config.yml")))
|
||||
DATABASES = YAML.load(File.read(File.join(Rails.root, "/config/database.yml")))
|
||||
|
||||
class << self
|
||||
def env=(env)
|
||||
raise "No config or database for this environment (#{env}) available!" if CONFIGS[env].nil? or DATABASES[env].nil?
|
||||
@@config = CONFIGS[env].symbolize_keys
|
||||
@@database = DATABASES[env].symbolize_keys
|
||||
@@env = env
|
||||
end
|
||||
end
|
||||
end
|
||||
# Initial load the default config and database from rails environment
|
||||
Foodsoft.env = Rails.env
|
||||
# See config/app_config.yml for further details
|
||||
# Load Config, start by selecting defaults via current environment
|
||||
require 'foodsoft_config'
|
||||
FoodsoftConfig.init
|
||||
|
||||
# Set action mailer default host for url generating
|
||||
url_options = {
|
||||
:host => Foodsoft.config[:host],
|
||||
:protocol => Foodsoft.config[:protocol]
|
||||
:host => FoodsoftConfig[:host],
|
||||
:protocol => FoodsoftConfig[:protocol]
|
||||
}
|
||||
url_options.merge!({:port => Foodsoft.config[:port]}) if Foodsoft.config[:port]
|
||||
url_options.merge!({:port => FoodsoftConfig[:port]}) if FoodsoftConfig[:port]
|
||||
|
||||
Foodsoft::Application.configure do
|
||||
config.action_mailer.default_url_options = url_options
|
||||
|
@ -31,9 +18,9 @@ Foodsoft::Application.configure do
|
|||
# Configuration of the exception_notification plugin
|
||||
# Mailadresses are set in config/app_config.yml
|
||||
config.middleware.use ExceptionNotifier,
|
||||
:email_prefix => Foodsoft.config[:notification]['email_prefix'],
|
||||
:sender_address => Foodsoft.config[:notification]['sender_address'],
|
||||
:exception_recipients => Foodsoft.config[:notification]['error_recipients']
|
||||
:email_prefix => FoodsoftConfig[:notification]['email_prefix'],
|
||||
:sender_address => FoodsoftConfig[:notification]['sender_address'],
|
||||
:exception_recipients => FoodsoftConfig[:notification]['error_recipients']
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -6,9 +6,9 @@ Foodsoft::Application.routes.draw do
|
|||
|
||||
get "sessions/new"
|
||||
|
||||
root :to => redirect("/#{Foodsoft.env}")
|
||||
root :to => redirect("/#{FoodsoftConfig.scope}")
|
||||
|
||||
scope '/:foodcoop', :defaults => { :foodcoop => Foodsoft.env } do
|
||||
scope '/:foodcoop' do
|
||||
|
||||
# Root path
|
||||
root :to => 'home#index'
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
class FoodsoftConfig
|
||||
mattr_accessor :scope, :config
|
||||
APP_CONFIG = YAML.load(File.read(File.join(Rails.root, "/config/app_config.yml")))
|
||||
|
||||
class << self
|
||||
|
||||
def init
|
||||
# Load initial config from development or production
|
||||
set_config Rails.env
|
||||
# Overwrite scope to have a better namescope than 'production'
|
||||
self.scope = config[:default_scope] or raise "No default_scope is set"
|
||||
end
|
||||
|
||||
# Set config and database connection for specific foodcoop
|
||||
# Only needed in multi coop mode
|
||||
def select_foodcoop(foodcoop)
|
||||
set_config foodcoop
|
||||
setup_database
|
||||
end
|
||||
|
||||
# Provides a nice accessor for config values
|
||||
# FoodsoftConfig[:name] # => 'FC Test'
|
||||
def [](key)
|
||||
config[key]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_config(foodcoop)
|
||||
raise "No config for this environment (#{foodcoop}) available!" if APP_CONFIG[foodcoop].nil?
|
||||
self.config = APP_CONFIG[foodcoop].symbolize_keys
|
||||
self.scope = foodcoop
|
||||
end
|
||||
|
||||
def setup_database
|
||||
database_config = ActiveRecord::Base.configurations[Rails.env]
|
||||
database_config.merge!(config[:database]) if config[:database].present?
|
||||
ActiveRecord::Base.establish_connection(database_config)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -3,8 +3,8 @@ class Wikilink < WikiCloth::WikiLinkHandler
|
|||
|
||||
def link_attributes_for(page)
|
||||
permalink = Page.permalink(page)
|
||||
url_options = {:host => Foodsoft.config[:host], :protocol => Foodsoft.config[:protocol]}
|
||||
url_options.merge!({:port => Foodsoft.config[:port]}) if Foodsoft.config[:port]
|
||||
url_options = {:host => FoodsoftConfig[:host], :protocol => FoodsoftConfig[:protocol]}
|
||||
url_options.merge!({:port => FoodsoftConfig[:port]}) if FoodsoftConfig[:port]
|
||||
|
||||
if Page.exists?(:permalink => permalink)
|
||||
{ :href => url_for(url_options.merge({:controller => "pages", :action => "show",
|
||||
|
|
Loading…
Reference in New Issue