我的页面上有很多动画,这实际上减慢了我在水豚的测试速度,因为水豚经常需要等到一个元素被动画化,因为它开始隐藏.
我为所有基于jQuery的动画找到了这个解决方案:
<%= javascript_tag '$.fx.off = true;' if Rails.env.test? %>
但是我使用twitter bootstrap,而bootstrap中的大多数动画都是由CSS 3(使用javascript后备)制作的.所以我的问题是,有没有办法在测试中转换CSS 3过渡和动画?
首先,原谅我可怜的英语,我是法国人......解释我的问题很棘手!
我在Rails应用程序中有一个模型用户模型:
class User < ActiveRecord::Base
attr_accessible :email, :gender, :lastname, :firstname
end
Run Code Online (Sandbox Code Playgroud)
以及从User继承的BackUser模型:
class BackUser < User
# Class for Backoffice User
devise :database_authenticatable,
:rememberable,
:trackable,
:lockable,
:invitable,
:confirmable,
:validatable,
:validate_on_invite => true
attr_accessible :password, :password_confirmation, :remember_me, :active, :role
validates :role, presence: true,
inclusion: ["admin", "normal"]
validates :gender, presence: true
validates :firstname, presence: true
validates :lastname, presence: true
def admin?
self.role == 'admin'
end
end
Run Code Online (Sandbox Code Playgroud)
第二节课应该在邀请之前验证记录!但是,当我使用控制台执行以下操作时:
u = BackUser.new
u.invite!
Run Code Online (Sandbox Code Playgroud)
"u"保存在数据库中,邀请被发送到空白电子邮件...
你知道我要做什么吗?
吃了很多!
我有一个存储在/ lib(/lib/buffer_app.rb)中的自定义类:
require 'HTTParty'
class BufferApp
include HTTParty
base_uri 'https://api.bufferapp.com/1'
def initialize(token, id)
@token = token
@id = id
end
def create(text)
message_hash = {"text" => text, "profile_ids[]" => @id, "access_token" => @token}
response = BufferApp.post('/updates/create.json', :body => {"text" => text, "profile_ids[]" => @id, "access_token" => @token})
end
end
Run Code Online (Sandbox Code Playgroud)
我试图在Active Admin资源中使用此类,并在生产(Heroku)时收到以下错误:
NameError (uninitialized constant Admin::EventsController::BufferApp):
Run Code Online (Sandbox Code Playgroud)
值得注意的是,我在application.rb中有这一行,并且此功能在开发中本地工作:
config.autoload_paths += %W(#{Rails.root}/lib)
Run Code Online (Sandbox Code Playgroud)
如果我尝试include BufferApp或require 'BufferApp'该行本身导致错误.我有命名空间问题吗?这需要是一个模块吗?或者这是一个简单的配置疏忽?
我正在写一些代码,结果却让我觉得太难看了.反正我是否可以重构它以便我不使用嵌套的if语句?
def hours_occupied(date)
#assuming date is a valid date object
availability = get_work_hours(date)
focus = "work"
if availability.nil
availability = get_family_hours(date)
focus = "family"
if availability.nil
availability = get_friend_hours(date)
focus = "friends"
end
end
end
Run Code Online (Sandbox Code Playgroud)
我知道我可以做这样的事情以获得可用性
availability = get_work_hours(date) || get_family_hours(date) || get_friend_hours(date)
Run Code Online (Sandbox Code Playgroud)
但是如何相应地设置焦点变量?
我有这个嵌套的if语句,我无法弄清楚如何重构它...它非常简单,但我无法得到正确的想法,希望有人可以提供帮助.
首先,我有一个嵌套的if语句(坏):
unless record.valid?
if condition_1
action_1
elsif condition_2
action_2
elsif condition_3
action_3
end
end
Run Code Online (Sandbox Code Playgroud)
然后我尝试了这个,但这看起来没有任何好转(如果没有任何内部的if语句也是坏的):
if record.valid?
# do nothing
elsif condition_1
action_1
elsif condition_2
action_2
elsif condition_3
action_3
end
Run Code Online (Sandbox Code Playgroud)
有没有人知道如何重构这些语句,以便它看起来更好?
我最终做的只是:
return if record.valid?
if condition_1
action_1
elsif condition_2
action_2
elsif condition_3
action_3
end
Run Code Online (Sandbox Code Playgroud) 我有3个模型:用户,答案和问题。
user.rb
has_many :questions
has_many :answers
Run Code Online (Sandbox Code Playgroud)
Question.rb
has_many :answers
belongs_to :user
accept_nested_attributes_for :answers
Run Code Online (Sandbox Code Playgroud)
answer.rb
belongs_to :question
belongs_to :user
Run Code Online (Sandbox Code Playgroud)
在questions / show.html.erb中
form_for @question do |f|
f.fields_for :answers, @question.answers.build do |builder|
builder.text_area, :body
end
f.submit
end
Run Code Online (Sandbox Code Playgroud)
Submit调用问题#update动作,由于嵌套了资源,新答案将被保存在数据库中。我想知道:user_id提交问题后,如何将答案列保存在数据库中?提交表格后,我能以某种方式通过current_user.id答案user_id栏吗?
ruby ×2
animation ×1
capybara ×1
class ×1
css ×1
devise ×1
heroku ×1
if-statement ×1
namespaces ×1
nested-if ×1