如何让我的Rails应用程序的每个独角兽工作者在另一个日志文件中写入?
原因:混合日志文件的问题...在其默认配置中,Rails会将其日志消息写入单个日志文件:log/<environment>.log.
Unicorn工作人员会立即写入同一个日志文件,这些消息可能会混淆.当request-log-analyzer解析日志文件时,这是一个问题.一个例子:
Processing Controller1#action1 ...
Processing Controller2#action2 ...
Completed in 100ms...
Completed in 567ms...
Run Code Online (Sandbox Code Playgroud)
在此示例中,在100毫秒内完成了什么操作,在567毫秒内完成了什么操作?我们永远无法确定.
我有一个表Foo有一个多态的belongs_to关联调用bar.该foos表具有标准bar_id列.但是,bar_type我有一个整数bar_type_id列,而不是基于字符串的列.此列引用id表中的列bar_types.bar_types.name保存表示特定bar实例的类的类的名称.
Rails(理想情况下> = 2.3.10)是否允许这种类型的多态关联?
我需要在网页上呈现二进制内容(图像).我用数据类型二进制文件在数据库中保存图像.现在我需要迭代数据库中的可用图像并在网页上呈现.
请检查我正在做的以下代码.图标是材质中的图像列名称.
// iterating all materials
<% @materials.each do |material| %>
// for each material
<span><%= image_tag(material.icon) %></span>
<% end %>
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激..
我正在使用Devise与Omniauth让用户通过Facebook登录我的应用程序.我使用Railscast教程来启动并运行它.
如果用户已经是我的网站的成员通过Facebook进行身份验证工作正常.在使用facebook验证新用户时会出现此问题.当它为我的用户模型创建一个新用户时,我得到"users.encrypted_password可能不是NULL"错误.我无法弄清楚如何从Facebook信息将密码传递给用户模型.
这就是我所拥有的:
authentations_controller.rb
class AuthenticationsController < ApplicationController
def index
@authentications = current_user.authentications if current_user
end
def create
omniauth = request.env["omniauth.auth"]
authentication = Authentication.find_by_provider_and_uid(omniauth['provider'], omniauth['uid'])
if authentication
flash[:notice] = "Signed in successfully."
sign_in_and_redirect(:user, authentication.user)
elsif current_user
current_user.authentications.create!(:provider => omniauth['provider'], :uid => omniauth['uid'])
flash[:notice] = "Authentication successful."
redirect_to authentications_url
else
user = User.new
user.apply_omniauth(omniauth)
if user.save
flash[:notice] = "Signed in successfully."
sign_in_and_redirect(:user, user)
else
session[:omniauth] = omniauth.except('extra')
redirect_to new_user_registration_url
end
end
end
Run Code Online (Sandbox Code Playgroud)
user.rb
def apply_omniauth(omniauth)
self.email = omniauth['user_info']['email'] if email.blank?
authentications.build(:provider …Run Code Online (Sandbox Code Playgroud) 我有两种模式:折扣已经属于许多商业.
我想验证折扣总是至少有一个业务,以及另一个条件(例如active?).我尝试了以下方法:
class Discount < ActiveRecord::Base
has_and_belongs_to_many :businesses,
before_remove: :validate_publish_status
def validate_publish_status(*arg)
if active? && businesses.count == 0
errors[:active] << 'discount with no business'
end
end
end
Run Code Online (Sandbox Code Playgroud)
但是这不起作用(没有引发验证错误),我意识到这可能是因为它只是一个回调,而不是验证.我怎么能编码它所以我可以使用errors像我做自定义验证?
我有的控制器动作(对于ajax):
def remove
@business = Business.find(params[:business_id])
if @business.in? @discount.businesses
@discount.businesses.delete(@business)
end
render json: @business.as_json(only: [:id, :type, :name, :address],
methods: [:city_name, :country_name]).
merge(paths: paths_for(@discount, @business))
rescue ActiveRecord::RecordInvalid # even tried the generic Exception
respond_to do |f|
f.json { render json: {error: $!.message}, status: 403 }
end
end
Run Code Online (Sandbox Code Playgroud) 我们的应用在此次通话中收到错误500:
有谁知道任何问题?
有一个解决方法,只需用"m.facebook.com"替换"www.facebook.com"
出于某种原因,处理图像(carrierwave + minimagick)在服务启动后大约一周停止工作.流量或上传流程没有异常增加.一旦发生ENOMEM错误,一切似乎都"锁定",任何后续进程也会失败.
如果系统处于该行为中甚至可以防止这种情况发生,我怎样才能"拯救"系统?
一些错误:
Errno::ENOMEM (Cannot allocate memory - export LANG=C && identify -ping /tmp/mini_magick20111219-18047-1dhmawm.jpg 2>&1):
app/uploaders/photo_uploader.rb:70:in `custom_thumbnail'
app/controllers/upload_controller.rb:186:in `process_upload'
app/middleware/flash_session_cookie_middleware.rb:17:in `call'
app/middleware/flash_session_cookie_middleware.rb:17:in `call'
Errno::ENOMEM (Cannot allocate memory - export LANG=C && mogrify -format jpg /tmp/mini_magick20111219-18047-1c43qpf.jpg 2>&1):
app/controllers/upload_controller.rb:186:in `process_upload'
app/middleware/flash_session_cookie_middleware.rb:17:in `call'
app/middleware/flash_session_cookie_middleware.rb:17:in `call'
...
...
Errno::ENOMEM (Cannot allocate memory - export LANG=C && mogrify -resize "120x180" -gravity "Center" -extent "120x120" /tmp/mini_magick20111219-18047-155ofje.jpg 2>&1):
app/controllers/upload_controller.rb:186:in `process_upload'
app/middleware/flash_session_cookie_middleware.rb:17:in `call'
app/middleware/flash_session_cookie_middleware.rb:17:in `call'
Run Code Online (Sandbox Code Playgroud)
内存和交换空间信息:
Mem: 8193476k total, 7907152k used, 286324k free, 5968k buffers
Swap: …Run Code Online (Sandbox Code Playgroud) 我的折扣类有一个sales_period.我想编写一个方法,可以在它不存在时构建这个关联,或者在它存在时更新它.目前我正在编写以下条件.
class Discount < ActiveRecord::Base
has_one :sales_period
def fetch_period
end_date = ...
if sales_period.nil?
build_sales_period( end: end_date )
else
sales_period.end = end_date
end
end
end
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法来做到这一点,类似于find_or_create?
升级到Rails 3.2.6或Rspec 2.11.0后,我的规范开始显示如下的路由错误:
4) UsersController GET activate activation code not exist
Failure/Error: subject{ get :activate }
ActionController::RoutingError:
No route matches {:controller=>"users", :action=>"activate"}
Run Code Online (Sandbox Code Playgroud)
每个钩子错误之后还有一个
An error occurred in an after(:each) hook
RSpec::Mocks::MockExpectationError: (#<EmailSubscriber[...]>).update_attributes({:enable=>true})
expected: 1 time
received: 0 times
occurred at [...]/spec/controllers/users_controller_spec.rb:75:in `block (3 levels) in <top (required)>'
Run Code Online (Sandbox Code Playgroud)
开发模式下的应用程序运行良好.
有没有办法在地图选项字段中加载语言?
像这样的东西:
var mapOptions = {
center : new google.maps.LatLng(43.97918, 53.716647),
zoom : 10,
mapTypeId : google.maps.MapTypeId.ROADMAP,
language : 'fr'
};
Run Code Online (Sandbox Code Playgroud) binaryfiles ×1
blob ×1
carrierwave ×1
devise ×1
facebook ×1
journey ×1
logging ×1
minimagick ×1
oauth ×1
omniauth ×1
rspec ×1
ruby ×1
unicorn ×1
worker ×1