小编Nic*_*o77的帖子

尝试使用collection_select显示eamil时获取[email protected]

我使用Ruby 1.8.7与Rails 2.3.9.使用集合选择创建电子邮件地址下拉列表时,电子邮件地址不会显示.相反,我在下拉菜单中看到"[email protected]".是否有一些开关造成这种情况?

当它看到列表中的电子邮件时,似乎有一些javascript被应用于下拉列表中的每个项目.当我只列出用户名时,javascript就不存在了.

<script type="text/javascript">
/* <![CDATA[ */
3(function(){try{var s,a,i,j,r,c,l=document.getElementById("__cf_email__");a=l.getAttribute("cf_sec");if(a){s='';r=parseInt(a.substr(0,2),16);for(j=2;a.length-j;j+=2){c=parseInt(a.substr(j,2),16)^r;s+=String.fromCharCode(c);}s=document.createTextNode(s);l.parentNode.replaceChild(s,l);}}catch(e){}})();
4/* ]]> */ 
<script/>
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails cdn cloudflare

16
推荐指数
2
解决办法
4681
查看次数

我如何进行Ruby on Rails并发测试?

在rails 3上使用ruby进行并发测试的最佳方法是什么?我的网站上有很多竞争条件,目前正在对它们进行测试是一项非常耗时的不精确科学.

提前感谢您的回复.

ruby concurrency ruby-on-rails race-condition

14
推荐指数
1
解决办法
4120
查看次数

Rails 3和Rspec 2关闭各个测试的事务夹具

我正在将我的应用程序升级到Rails 3.我开始在Rails 3中使用Rspec 2.我需要为我的一些rspec测试关闭事务装置.之前我在我的模型规范中使用了以下代码

 before(:all) do
    ActiveSupport::TestCase.use_transactional_fixtures = false
  end

  after(:all) do
    ActiveSupport::TestCase.use_transactional_fixtures = true
    clean_engine_database
  end
Run Code Online (Sandbox Code Playgroud)

那现在给了我错误:

 Failure/Error: ActiveSupport::TestCase.use_transactional_fixtures = false
     undefined method `use_transactional_fixtures=' for ActiveSupport::TestCase:Class
Run Code Online (Sandbox Code Playgroud)

有没有办法在Rails 3中使用Rspec 2的每个测试块执行此操作?

rspec ruby-on-rails rspec2

11
推荐指数
1
解决办法
9110
查看次数

Cakephp搜索MySQL

对使用MySQL数据库的Cakephp应用程序进行基于文本的搜索的哪种实现是"最好的"?

php cakephp

7
推荐指数
2
解决办法
5439
查看次数

jQuery UI自动完成autoFocus无法正常工作

我正在使用jQuery UI自动完成并尝试实现autoFocus选项.

文档说明如下:如果设置为true,则第一个项目将自动聚焦.

我创建了一个基本的例子,无法开始工作.我一定错过了一些明显的东西.见这里:http://jsfiddle.net/9bQJX/

$("#autocomplete").autocomplete({
    source: [
        "ActionScript",
        "AppleScript",
        "Asp",
        "BASIC",
        "C",
        "C++",
        "Clojure",
        "COBOL",
        "ColdFusion",
        "Erlang",
        "Fortran",
        "Groovy",
        "Haskell",
        "Java",
        "JavaScript",
        "Lisp",
        "Perl",
        "PHP",
        "Python",
        "Ruby",
        "Scala",
        "Scheme"
    ],
    autoFocus: true
});
Run Code Online (Sandbox Code Playgroud)

jquery jquery-ui jquery-ui-autocomplete

7
推荐指数
1
解决办法
9709
查看次数

Ruby on Rails应用程序的只读模式

我有一个交互式Ruby on Rails应用程序,我希望在某些时候将其置于"只读模式".这将允许用户读取他们需要的数据,但阻止他们写入数据库的操作.

实现此目的的一种方法是在进行任何写入之前检查数据库中的真/假变量.

我的问题.这个问题有更优雅的解决方案吗?

ruby ruby-on-rails

5
推荐指数
2
解决办法
4657
查看次数

rails rspec预计自定义验证失败

运行我的rspec期望使用自定义验证器时出现此错误.

expect {@ua.save!}.to  raise_error(ActiveRecord::RecordInvalid,'Validation failed: This question is no longer active')
Run Code Online (Sandbox Code Playgroud)

失败了

expected ActiveRecord::RecordInvalid with "Validation failed: This question is no longer active", got #<ActiveRecord::RecordInvalid: Validation failed: This question is no longer active.> with backtrace:
Run Code Online (Sandbox Code Playgroud)

这似乎只是我的自定义验证的问题.看到这个型号:

class UserAnswer < ActiveRecord::Base
  belongs_to :user
  belongs_to :question
  validate :questionIsActive?

  private

  def questionIsActive?
    errors.add(:base, "This question is no longer active.") if !self.question.is_active?
  end
end
Run Code Online (Sandbox Code Playgroud)

使用:Rails 3.2.11 Rspec-rails 2.12.2

rspec ruby-on-rails rspec-rails

5
推荐指数
1
解决办法
8775
查看次数

FB.ui发送在回调中的响应变量中返回的变量

我正在使用Facebook SDK FB.ui. 我可以使用FB.ui传递一个参数,以便它与响应对象一起返回吗?

我目前的尝试:

FB.ui({
    method: 'stream.publish',
    message: message,
    display: 'popup', // force popup mode
    data: "shared_item_id=96"
    },    
function(response) {
    alert('Post was published.' + response.share_item_id);
});
Run Code Online (Sandbox Code Playgroud)

有没有把shared_item_id放到响应对象中?

javascript facebook facebook-javascript-sdk

4
推荐指数
1
解决办法
3365
查看次数

ruby on rails 3使用缓存数据重新加载

在我的应用程序中使用activerecord reload命令似乎在调用时使用缓存数据.

我可以通过执行以下操作在调试器中进行复制.

u = User.find(1)
u.first_name
#outputs bob

# manually change first_name for record 1 to jim with PGadmin or with rails console

u.reload
u.valid?
#outputs true
u.first_name
#outputs bob

#if i do this again
u = User.find(1)
#old data again
u.first_name
#outputs bob

#if i load data this way
u = User.where('id = 1').first
#new data
u.first_name 
#outputs jim
Run Code Online (Sandbox Code Playgroud)

在运行重新加载后查看我的日志文件时,它会打印出来

[1m [35mCACHE(0.0ms)[0m SELECT"users".*FROM"users"WHERE("users"."id"= 1)LIMIT 1

所以它似乎在使用缓存

我的环境:Rails 3.0.3,Ruby 1.8.7,Ubuntu 10.04,PostgreSQL 8.4

activerecord ruby-on-rails

3
推荐指数
1
解决办法
2667
查看次数

在环境特定的配置文件中配置未定义

当我在本地启动我的服务器时,我收到以下通知:

please set config.active_support.deprecation to :log at config/environments/development.rb
Run Code Online (Sandbox Code Playgroud)

当我添加config/environments/development.rb时

config.active_support.deprecation = :log 
Run Code Online (Sandbox Code Playgroud)

我明白了:

undefined local variable or method `config' for main:Object (NameError)
Run Code Online (Sandbox Code Playgroud)

我的环境:Rails 3.0.1 Ruby 1.8.7 Ubuntu 10.04

Development.rb文件

# Settings specified here will take precedence over those in config/environment.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 webserver when you make code changes.
config.active_support.deprecation = …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails

2
推荐指数
1
解决办法
1万
查看次数