Speeding up Rails 3.2.1 Development Environment - ruby-on-rails-3

I'm running a rather large project in Development and its just too slow. I believe the reason is because on each request Rails reloads every class. This project literally has hundreds of classes so the response time is too slow.
How can I speed up my development environment?
I'm running Apache server, the latest version of Passenger, RVM ruby 1.9.2-p180 (which I'm more or less locked into the ruby version).
development.rb:
# (Development-only) what is our localhost called?
LOCALDOMAIN = File.read("/etc/context_dev_host").strip
# Don't verify SSL connections.
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
SMSAdmin::Application.configure do
config.cache_classes = false # reload on every request
config.whiny_nils = true # Log error messages when you accidentally call methods on nil.
config.consider_all_requests_local = true # Show full error reports and disable caching
config.action_controller.perform_caching = false # Show full error reports and disable caching
config.action_mailer.raise_delivery_errors = false # Don't care if the mailer can't send
config.action_mailer.default_url_options = { :host => "#{APP_HOSTNAME}" } # default url_for :host
config.action_mailer.raise_delivery_errors = false
# Distributed Assets will expect an asset host for path resolution:
config.action_controller.asset_host = Proc.new do |source, request|
ssl = request && request.ssl?
hash = false
subd = true
host = ( hash ? "a#{source.hash % 4}." : "" ) + ( subd && request && request.host || APP_HOSTNAME )
( ssl ? "https://" : "http://" ) + host
end
ActionMailer::Base.delivery_method = :sendmail
config.after_initialize do
# Custom developer files (generally to support Rake tasks, where we don't have a request to determine the FB API Key)
dh = File.read("/etc/context_dev_host").strip.split(".").first
df = File.expand_path("../#{dh}.rb", __FILE__)
if File.exists?(df) then
silence_warnings do
require(df)
end
end
end
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = false
config.assets.digest = false
# Raise exception on mass assignment protection for Active Record models
config.active_record.mass_assignment_sanitizer = :strict
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
config.active_record.auto_explain_threshold_in_seconds = 0.5
end

Related

404 when executing docker push to gitlab-container-registry

I have installed gitlab-ce 13.2.0 on my server and the container-registry was immediately available.
from a other sever (or my local machine) I can login, but when pushing a image to the container-registry I get a 404-error: error parsing HTTP 404 response body: invalid character '<' looking for beginning of value: "<!DOCTYPE html>\n<html>\n<head>...
in my gitlab.rb I have:
external_url 'https://git.xxxxxxxx.com'
nginx['enable'] = true
nginx['client_max_body_size'] = '250m'
nginx['redirect_http_to_https'] = true
nginx['ssl_certificate'] = "/etc/gitlab/trusted-certs/xxxxxxxx.com.crt"
nginx['ssl_certificate_key'] = "/etc/gitlab/trusted-certs/xxxxxxxx.com.key"
nginx['ssl_protocols'] = "TLSv1.1 TLSv1.2"
registry_external_url 'https://git.xxxxxxxx.com'
what is confusing, is that the registry_external_url is the same as the external_url. There are those lines in the gitlab.rb:
### Settings used by GitLab application
# gitlab_rails['registry_enabled'] = true
# gitlab_rails['registry_host'] = "git.xxxxxxxx.com"
# gitlab_rails['registry_port'] = "5005"
# gitlab_rails['registry_path'] = "/var/opt/gitlab/gitlab-rails/shared/registry"
But when I uncomment this, I cannot login.
what can be the problem here?
This is actually because you are using https port without proxying the registry in nginx.
Fix these lines according to the following in gitlab.rb:
registry_nginx['enable'] = true
registry_nginx['listen_https'] = true
registry_nginx['redirect_http_to_https'] = true
registry_external_url 'https://registry.YOUR_DOMAIN.gtld'
You don't need to touch nginx['ssl_*] parameters when you are using letsencrypt since the chef would take care.
How is your image named? Your image name must match exactly not only the registry URL, but project too.
You can't just build "myimage:latest" and push it. It must be like git.xxxxxxxx.com/mygroup/myproject:latest. You can obtain correct name from $CI_REGISTRY_IMAGE predefined variable.

devise ldap auth with group restrict rails 5 and devise 4.3

i have a problems to restirct access from a member of a group. My application are a Rails 5 app with devise and devise_ldap_authenticatable gems installed.
this my ldap.yml
authorizations: &AUTHORIZATIONS
allow_unauthenticated_bind: false
group_base: "CN=Domain Admins,CN=Users,DC=XXX,DC=XX"
## Requires config.ldap_check_group_membership in devise.rb be true
# Can have multiple values, must match all to be authorized
required_groups:
- CN=Domain Admins,CN=Users,DC=xxx,DC=xx
my devise.rb
config.ldap_logger = true
config.ldap_create_user = true
config.ldap_update_password = true
#config.ldap_config = "#{Rails.root}/config/ldap.yml"
config.ldap_check_group_membership = true
config.ldap_ad_group_check = true
##config.ldap_check_attributes = true
config.ldap_use_admin_to_bind = true
i try all combination but nothing works. I changed the line 174 of connection.rb
filter = Net::LDAP::Filter.eq("uniqueMember", dn)
with
filter = Net::LDAP::Filter.eq("member", dn)
OR
filter = Net::LDAP::Filter.eq("memberOf", dn)
but nothing happens please i need to solve this!
thanks for all reply
UPDATE
check the # <<: *AUTHORIZATIONS at bottom of authentication Ldap and uncomment it <<: *AUTHORIZATIONS
this put the group check into ldap auth.
bye!!!

Sinatra app as rack middleware TimesOut Rails 3

While in the Rails development environment, I am attempting to add a Sinatra app as a middleware. The Sinatra app uses the geoip gem that processes a user's ip address and returns json with their city.
I can view the returned json by going directly to the example url in the browser or using curl in the command line, http://local.fqdn.org/geoip/locate.json?ip=24.18.211.123. However when I attempt to call the url with wget from within a Rails controller, the Rails app stops responding often crashing my browser and my rails server wont exit using the control+C command.
Any clue to what is happening here? Why would going directly to the url in the browser return the proper response but my call in the controller results in a Time Out?
sinatra-geoip.rb
require 'sinatra'
require 'geoip'
require 'json'
# http://localhost/geoip/locate.json?ip=24.18.211.123
#
# {
# latitude: 47.684700012207
# country_name: "United States"
# area_code: 206
# city: "Seattle"
# region: "WA"
# longitude: -122.384803771973
# postal_code: "98117"
# country_code3: "USA"
# country_code: "US"
# dma_code: 819
# }
class GeoIPServer < Sinatra::Base
get '/geoip/locate.json' do
c = GeoIP.new('/var/www/mywebsite.org/current/GeoLiteCity.dat').city(params[:ip])
body c.to_h.to_json
end
end
routes.rb
mount GeoIPServer => "/geoip"
config/environments/development.rb
Website::Application.configure do
require "sinatra-geoip"
config.middleware.use "GeoIPServer"
...
end
controller
raw_geo_ip = Net::HTTP.get(URI.parse("http://#{geoip_server}/geoip/locate.json?ip=#{request.ip}"))
#geo_ip = JSON.parse(raw_geo_ip)
Our solution was difficult to find. We ended up finding a method in the sinatra source code call forward.
new sinatra-geoip.rb
class GeoIPServer < Sinatra::Base
if defined?(::Rails)
get '/properties.json' do
env["geo_ip.lookup"] = geo_ip_lookup(request.ip)
forward
end
end
def geo_ip_lookup(ip = nil)
ip = ip.nil? ? params[:ip] : ip
result = GeoIP.new('/var/www/mywebsite.org/current/GeoLiteCity.dat').city(ip)
result.to_h.to_json
end
end
Essentially, we removed the /geoip/locate.json route from the file and converted it to a simple method. We needed the geoip lookup to occur when the properties.json was being called, so a new param was added with the geoip information. Then we set the new param equal to #geo_ip variable in the controller.
New properties controller
if Rails.env.development? or Rails.env.test?
# Retrieves param set by sinatra-geoip middleware.
#geo_ip = JSON.parse(env["geo_ip.lookup"] || "{}")
else
# Production and staging code
end
Rather obscure problem and solution. Hopefully it will help someone out there. Cheers.

Altering CSS in Rails 3.2 does not change styles without precompiling assets first

I upgraded an app to Rails 3.2 and installed Bourbon on it. When I make a CSS change locally, for some reason I'm not seeing any change made. Only when I precompile the assets after making a change do I see it in development. Does anyone know what might be going wrong?
Here's my development.rb:
POP::Application.configure do
# Settings specified here will take precedence over those
# in config/application.rb
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false
# Print deprecation notices to the Rails logger
config.active_support.deprecation = :log
# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin
# Raise exception on mass assignment protection for Active Record models
config.active_record.mass_assignment_sanitizer = :strict
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
config.active_record.auto_explain_threshold_in_seconds = 0.5
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = true
# # GMail settings
# ActionMailer::Base.smtp_settings = {
# :address => "smtp.gmail.com",
# :port => 587,
# :authentication => "plain",
# :enable_starttls_auto => true
# }
end
And application.rb:
require File.expand_path('../boot', __FILE__)
require 'rails/all'
if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
Bundler.require(*Rails.groups(:assets => %w(development test)))
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)
end
module POP
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified
# here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Custom directories with classes and modules you want to be autoloadable.
# config.autoload_paths += %W(#{config.root}/extras)
# Only load the plugins named here, in the order given (default is
# alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named.
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
# Activate observers that should always be running.
# config.active_record.observers = :cacher, :garbage_collector,
# :forum_observer
# Set Time.zone default to the specified zone and make Active Record
# auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names.
# Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from
# config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales',
# '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
# Configure the default encoding used in templates for Ruby 1.9.
config.encoding = "utf-8"
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password]
# Use SQL instead of Active Record's schema dumper when creating the
# database.
# This is necessary if your schema can't be completely dumped by the
# schema dumper,
# like if you have constraints or database-specific column types
# config.active_record.schema_format = :sql
# Enforce whitelist mode for mass assignment.
# This will create an empty whitelist of attributes available for
# mass-assignment for all models
# in your app. As such, your models will need to explicitly whitelist or
# blacklist accessible
# parameters by using an attr_accessible or attr_protected declaration.
config.active_record.whitelist_attributes = true
# Enable the asset pipeline
config.assets.enabled = true
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
# Config spec generators
config.generators do |g|
g.test_framework :rspec,
:fixtures => true,
:view_specs => false,
:helper_specs => false,
:routing_specs => false,
:controller_specs => true,
:request_specs => true
g.fixture_replacement :factory_girl, :dir => "spec/factories"
end
config.assets.initialize_on_precompile = false
end
end
Looks like a previous question I hadn't found had the answer. All I needed to do was run:
bundle exec rake assets:clean

How to perform 301 before force_ssl? Rails 3.1

I need to make http://example.com go to https://www.example.com. right now it's warning in the browser. I followed: http://www.simonecarletti.com/blog/2011/05/configuring-rails-3-https-ssl/
loading from /lib/middleware (Rails 3.1)
class WwwMiddlewareRedirect
def initialize(app)
#app = app
end
def call(env)
request = Rack::Request.new(env)
if request.host.starts_with?("example.com")
[301, {"Location" => request.url.sub("//", "//www.")}, self]
else
#app.call(env)
end
end
def each(&block)
end
end
production env
Example::Application.configure do
config.force_ssl = true
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true
config.middleware.use "WwwMiddlewareRedirect"
end
If you can get your webserver to do the redirect, that's usually best. If you're on Heroku or a similar platform where you can't get the webserver to redirect for you, make these changes:
Change the middleware line to be:
config.middleware.insert_before Rack::SSL, "WwwMiddlewareRedirect"
Then in your gemfile, include:
gem 'rack-ssl', :require => 'rack/ssl'
Unless I'm misunderstanding, I think you are using the < 3.1 instructions for a 3.1 app. In 3.1 you only need to set force_ssl to true and it will result in the behavior you desire.