我有一个Release模型medium和country列(以及其他).不应该releases有相同medium/ country组合的共享.
我如何将其写为rails验证?
activerecord ruby-on-rails ruby-on-rails-3 ruby-on-rails-4 rails-activerecord
我正在使用webmock和VCR进行一些基本的Rspec测试,但是我想为我的验收测试禁用webmock,以便我可以实际发出外部HTTP请求.
最好的方法是什么?
我在标题中包含了两个以下脚本,我收到错误"您已在此页面上多次包含Google Maps API.这可能会导致意外错误."
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js key=************"></script>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?libraries=places&sensor=false"></script>
Run Code Online (Sandbox Code Playgroud)
当我删除任何一个脚本时,我会得到额外的js错误.如何在我的rails应用程序中正确地重构这两个脚本?
在当地显示很好.但是当我上传到Heroku时,我得到以下内容:
<%= image_tag('logo-red.png') %>
Run Code Online (Sandbox Code Playgroud)
它位于资产/图像/
我没有使用Turbolinks.我是否需要在Heroku上运行命令来解决这个问题,或者是否存在一些我缺少的配置设置?
编辑1:试过跑步 heroku run rake assets:precompile RAILS_ENV=production
编辑2:heroku员工的回复:
看起来您的应用正在正确编译该图像:〜/ public/assets $ pwd/app/public/assets~/public/assets $ ls | grep logo-red logo-red-a07050d882e1dba431cef2130d39f929c611eaf8b0ec3c50db0742ddccb14d93.png
我在使用Mixpanel为我的Rails应用程序计算会话时遇到问题.基本上,每当有人从外部URL(而不是mydomain.com)访问页面时,我就会触发"会话"混合面板跟踪事件.
所以我在我的application_controller.rb中有这样的东西在钩子之前:
def count_session
referral = request.referer
root_url = Figaro.env.root_uri
### If there's a referral and it includes the root domain, then don't
### track because it's the same session
if referral && referral.include?(root_url)
puts "!!!! NOT TRACKED !!!!!"
else
puts "!!!!! TRACKED #{id} !!!!!!"
mixpanel.track("Session", "ID" => current_user.id, "Version" => Figaro.env.ab_version )
end
end
Run Code Online (Sandbox Code Playgroud)
为了调试,我能看到"!!!!! TRACKED 4 !!!!!!" 在我的控制台中从我的帐户访问该页面时(用户ID:4).但是当我访问MixPanel时,仪表板中没有显示任何事件.
如果我在隐身浏览器中访问(ID为nil),或者如果我访问隐身,然后明确登录到我的帐户,我可以记录会话事件.但目标是在用户从外部URL访问时随时注册事件.
我的其他mixpanel活动正常.知道为什么会话事件不会在这个实例中触发?我该如何进一步调试呢?
谢谢!
编辑:我正在使用Mengpaneel进行ruby实现,这是我的设置:
初始化/ mengpaneel.rb:
Mengpaneel.configure do |config|
config.token = Figaro.env.mixpanel_token
end
Run Code Online (Sandbox Code Playgroud)
application_controller.rb:
before_action :setup_mixpanel
before_action :count_session …Run Code Online (Sandbox Code Playgroud) 我有一个火种风格的应用程序,允许用户评价事件.在用户对事件进行评级后,将运行后台resque作业,根据用户的反馈对其他事件进行重新排序.
此后台作业大约需要10秒钟,每个用户每分钟运行大约20次.
用一个简单的例子.如果我有10个用户在任何给定时间使用该应用程序,并且我从不希望等待工作,那么最佳方法是什么?
我对Dynos,resque pool和redis连接感到困惑.有人能帮我理解其中的区别吗?有没有办法计算这个?
我在我的rails应用程序中使用Facebook Oauth和Devise.我成功地进入了facebook登录页面,但随后在回调操作中出错.跟踪它以request.env["omniauth.auth"]返回nil我的回调动作.
的Gemfile:
gem 'devise'
gem 'omniauth'
gem 'omniauth-facebook'
Run Code Online (Sandbox Code Playgroud)
路线:
devise_scope :user do
get '/users/auth/facebook/callback', to: 'users/omniauth_callbacks#facebook'
end
resources :users
devise_for :users, path: '', path_names: { sign_up: 'register', sign_in: 'login', sign_out: 'logout'}, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
Run Code Online (Sandbox Code Playgroud)
初始化/ devise.rb:
config.omniauth :facebook, Figaro.env.facebook_key, Figaro.env.facebook_secret,
scope: 'email,public_profile',
callback_url: Figaro.env.facebook_callback_url
Run Code Online (Sandbox Code Playgroud)
User.rb:
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :confirmable, :validatable,
:omniauthable, :omniauth_providers => [:facebook]
Run Code Online (Sandbox Code Playgroud)
omniauth_callbacks_controller.rb:
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def facebook
@user = User.from_omniauth(request.env["omniauth.auth"]) …Run Code Online (Sandbox Code Playgroud) 我正在我的电子商务网站上运行全站点AB测试.访问者登陆后,我为他们分配了一个本地存储密钥/值:
function isLocalStorageNameSupported() {
var testKey = 'test', storage = window.localStorage;
try {
storage.setItem(testKey, '1');
storage.removeItem(testKey);
return true;
} catch (error) {
return false;
}
}
$(function() {
if(isLocalStorageNameSupported()){
var version = Cookies.get("version");
if (version == null) {
if (Math.random() >= 0.5){
Cookies.set("version", "A");
var version = "A"
}else{
Cookies.set("version", "B");
var version = "B"
}
ga('create', 'UA-XXXXXXXX-1', 'auto');
ga('send', {
hitType: 'event',
eventCategory: 'Pricing Experiment',
eventAction: 'New Unique Visit',
eventLabel: version,
eventValue: 0
});
}
}
});
Run Code Online (Sandbox Code Playgroud)
访问者签出后,我会检查他们所在的版本并发送另一个Google Analytics事件. …
我有一个'项目'形式作为部分.我正在尝试使用jquery在用户单击按钮时呈现部分:
$('.projects').append("<%= render partial: 'projects/project') %>").html_safe
Run Code Online (Sandbox Code Playgroud)
但是使用上面的代码实际上是在页面上呈现"<%= render partial:'projects/project')%>"而不是实际的部分.
我有一个嵌套的表单来处理调查及其答案.但是当我加载表单时,我收到一个奇怪的错误:
的ActiveRecord :: HasManyThroughNestedAssociationsAreReadonly
有任何想法吗?我不确定如何修复这些关联.
<%= form_for @survey do |f| %>
...
<%= f.fields_for :answers do |builder| %>
<%= builder.text_field :content, :class=>"form-control" %>
<% end %>
...
<% end %>
Run Code Online (Sandbox Code Playgroud)
调查#新
def new
@survey = Survey.new
@template = Template.find(params[:template_id])
@patient = Patient.find(params[:patient_id])
@survey.answers.build
end
Run Code Online (Sandbox Code Playgroud)
Survey.rb
class Survey < ActiveRecord::Base
belongs_to :template
has_many :questions, :through=> :template
has_many :answers, :through=> :questions
accepts_nested_attributes_for :answers
end
Run Code Online (Sandbox Code Playgroud)
Template.rb
class Template < ActiveRecord::Base
belongs_to :survey
has_many :questions
end
Run Code Online (Sandbox Code Playgroud)
Question.rb
class Question < ActiveRecord::Base
belongs_to :template
has_many …Run Code Online (Sandbox Code Playgroud)