我正在使用Rails助手来生成按钮,我正在尝试使用按钮的Twitter引导样式来设置按钮样式.我添加了带有:html选项的类.页面没有破坏,但样式没有显示.
<%= button_to('Sign Up', new_user_registration_path, :html => {:class => 'btn.btn-large.btn-primary'}) %>
<%= button_to "Sign Up", user_omniauth_authorize_path(:facebook), :html => {:class => 'btn.btn-large.btn-primary'} %>
Run Code Online (Sandbox Code Playgroud)
这是facebook按钮的页面源
<form action="/users/sign_up" class="button_to" method="post"><div><input html="{:class=>"btn.btn-large.btn-primary"}" type="submit" value="Sign Up" /><input name="authenticity_token" type="hidden" value="QIvZqd9BRV8TMspMvckAUjhC68nm3NTyQCxVRHFA4PE=" /></div></form>
<form action="/users/auth/facebook" class="button_to" method="post"><div><input html="{:class=>"btn.btn-large.btn-primary"}" type="submit" value="Sign Up" /><input name="authenticity_token" type="hidden" value="QIvZqd9BRV8TMspMvckAUjhC68nm3NTyQCxVRHFA4PE=" /></div></form>
Run Code Online (Sandbox Code Playgroud)
知道我做错了什么吗?

我使用Rails 3.1.3克隆了我自己的一个应用程序,在堆栈雪松上的Heroku上创建了一个应用程序,将其推送到Heroku,然后尝试运行
heroku run rake db:migrate 并收到此错误消息
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb, Rakefile.rb)
/usr/local/lib/ruby/1.9.1/rake.rb:2367:in `raw_load_rakefile'
/usr/local/lib/ruby/1.9.1/rake.rb:2007:in `block in load_rakefile'
/usr/local/lib/ruby/1.9.1/rake.rb:2058:in `standard_exception_handling'
/usr/local/lib/ruby/1.9.1/rake.rb:2006:in `load_rakefile'
/usr/local/lib/ruby/1.9.1/rake.rb:1991:in `run'
/usr/local/bin/rake:31:in `<main>
Run Code Online (Sandbox Code Playgroud)
我跑的时候,我在应用程序的根目录中rake db:migrate.该应用程序适用于localhost.
我有什么想法可能做错了吗?
我注意到的唯一奇怪的是,在错误信息中,它指的是 ruby/1.9.1/
但是,我使用rvm和ruby 1.9.2创建了应用程序 ruby -v
ruby -v
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.8.0]
Run Code Online (Sandbox Code Playgroud)
我的Gemfile
source 'http://rubygems.org'
gem 'rails', '3.1.3'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
group …Run Code Online (Sandbox Code Playgroud) 在我的Rails 4应用程序的home_controller中,我执行自定义SQL查询并将结果保存到实例变量
@studentscoring = ActiveRecord::Base.connection.execute sql_string_student
Run Code Online (Sandbox Code Playgroud)
然后,在配置开发中将缓存设置为true config.action_controller.perform_caching = true并重新启动应用程序之后,在视图中围绕相关变量设置缓存.
<% cache @studentscoring do%>
<% for lawyer in @studentscoring %>
<div class="span2">
<div class="row">
<%= tiny_gravatar_for lawyer['name'], lawyer['email'] %>
</div>
...... #code ommitted
</div>
<% end %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
刷新浏览器三次显示查询分别运行三次,查询的最后一次运行实际上比第一次运行时长.7ms,所以我假设缓存不起作用或者我没有正确执行:) 你能告诉我我做错了什么吗?
不是任何标准的专家,我不明白如何使用<%cache ... do%>语法从视图中触发缓存,因为在加载视图时,控制器查询已经没有了因此,告诉Rails使用缓存副本为时已晚?
从服务器日志...
第一
(1.1ms) with cte_scoring as (
select
users.id, users.name, users.email,
(select Coalesce(sum(value),0) from answer_votes where (answer_votes.user_id = users.id) AND (created_at >= Current_Date - interval '7 day')) +
(select Coalesce(sum(value),0) from best_answers where (best_answers.user_id …Run Code Online (Sandbox Code Playgroud) 我正在尝试生成一个随机令牌,我可以在实现重置密码功能时使用它.这个(http://play.golang.org/p/mmAzXLIZML)是令人眼花缭乱且不起作用的:(我第一次尝试的代码.它不起作用,因为它产生了反复使用相同的标记(我假设它是时间不变的函数).如何使用md5生成随机标记,每次都会更改?
package main
import "fmt"
import "strconv"
import "time"
import "crypto/md5"
import "io"
func main() {
time := strconv.FormatInt(time.Now().Unix(), 10)
fmt.Println(time)
h := md5.New()
io.WriteString(h, time)
fmt.Printf("%x", h.Sum(nil))
}
Run Code Online (Sandbox Code Playgroud)
tldr:我能够require运行应用程序的所有内容,但如果我require在测试中的模块(在应用程序中 - 参见下面的dir结构)文件中,整个依赖关系链就会中断.
我在require我的app/test目录(在我的webpack React.js应用程序中)有一些困难的组件,我没有任何困难 - require从文件/app夹中的任何其他文件.这是目录结构
app
/components/checkout.jsx
/components/button.jsx
/test/test.js
index.jsx
dist
node_modules
webpack.config.js
package.json
Run Code Online (Sandbox Code Playgroud)
在我的webpack.config.js中,我设置为像我这样使用jsx-loader作为我的React应用程序
entry: {
app: "./app/index"
},
module: {
loaders: [
{
test: /\.jsx$/,
loader: 'jsx-loader?insertPragma=React.DOM&harmony',
}
]
},
resolve: {
extensions: ['', '.js', '.jsx']
}
Run Code Online (Sandbox Code Playgroud)
这允许我要求以扩展名.jsx结尾的文件.例如,在/app/index.jsx我要求/app/components/checkout.jsx的时候
var Checkout = require('./components/Checkout')
Run Code Online (Sandbox Code Playgroud)
在里面/app/components/checkout.jsx,我需要按钮
var Button = require('./components/Button')
Run Code Online (Sandbox Code Playgroud)
因此,当我需要Checkout来自index.jsx时,它处理Button的要求没有任何问题.
但是,从app/test/test.js,我做到了
var Checkout = require('../components/Checkout')
Run Code Online (Sandbox Code Playgroud)
和webpack找不到Checkout组件.当我在webpack dev服务器中查看测试时,它没有显示查找.jsx文件扩展名.它搜索了
app/components/Checkout …Run Code Online (Sandbox Code Playgroud) 在这个小提琴http://jsfiddle.net/mjmitche/qVdEy/6/,您可以看到弹出框内文本的对齐是完美的,但是,当我在我的网站上放置完全相同的css/js/html时,文字大于容器!

我试图弄清楚使用萤火虫发生了什么,但我必须将光标从弹出窗口移开以使用萤火虫,然后萤火虫消失.我无法弄清楚我的代码中的哪些设置正在改变演示文稿.弹出窗口是使用Twitter Bootstrap.js创建的(你可以看到小提琴中的资源)
我能够预先编译资产以推送到Enki博客的Heroku,我成功地迁移了数据库.但是当我试图运行时,我heroku open在Heroku上获得了错误消息页面(该应用程序在本地工作).然后我跑了heroku logs,看到了这个错误
Errno::ECONNREFUSED (Connection refused - connect(2)):
Run Code Online (Sandbox Code Playgroud)
任何人都可以解释问题可能是什么?
Processing by HomesController#index as HTML
2012-07-12T06:14:38+00:00 app[web.1]: Rendered homes/index.html.erb within layouts/application (2.1ms)
2012-07-12T06:14:38+00:00 app[web.1]: Completed 500 Internal Server Error in 7ms
2012-07-12T06:14:38+00:00 app[web.1]: Rendered vendor/bundle/ruby/1.9.1/gems/exception_notification-2.5.2/lib/exception_notifier/views/exception_notifier/_request.text.erb (0.2ms)
2012-07-12T06:14:38+00:00 app[web.1]: Rendered vendor/bundle/ruby/1.9.1/gems/exception_notification-2.5.2/lib/exception_notifier/views/exception_notifier/_title.text.erb (0.1ms)
2012-07-12T06:14:38+00:00 app[web.1]: Rendered vendor/bundle/ruby/1.9.1/gems/exception_notification-2.5.2/lib/exception_notifier/views/exception_notifier/_session.text.erb (0.3ms)
2012-07-12T06:14:38+00:00 app[web.1]: Rendered vendor/bundle/ruby/1.9.1/gems/exception_notification-2.5.2/lib/exception_notifier/views/exception_notifier/_title.text.erb (0.0ms)
2012-07-12T06:14:38+00:00 app[web.1]: Rendered vendor/bundle/ruby/1.9.1/gems/exception_notification-2.5.2/lib/exception_notifier/views/exception_notifier/_environment.text.erb (13.9ms)
2012-07-12T06:14:38+00:00 app[web.1]: Rendered vendor/bundle/ruby/1.9.1/gems/exception_notification-2.5.2/lib/exception_notifier/views/exception_notifier/_title.text.erb (0.0ms)
2012-07-12T06:14:38+00:00 app[web.1]: Rendered vendor/bundle/ruby/1.9.1/gems/exception_notification-2.5.2/lib/exception_notifier/views/exception_notifier/_backtrace.text.erb (0.1ms)
2012-07-12T06:14:38+00:00 app[web.1]: Rendered vendor/bundle/ruby/1.9.1/gems/exception_notification-2.5.2/lib/exception_notifier/views/exception_notifier/_title.text.erb (0.1ms)
2012-07-12T06:14:38+00:00 app[web.1]: Rendered vendor/bundle/ruby/1.9.1/gems/exception_notification-2.5.2/lib/exception_notifier/views/exception_notifier/exception_notification.text.erb (18.4ms)
2012-07-12T06:14:41+00:00 …Run Code Online (Sandbox Code Playgroud) 我正在进行一个codecademy.com练习,我们使用for-in语句循环一个对象并通过检查语言对象中属性的值是否是字符串来打印不同语言的hello typeof
我查看该值是否为字符串不起作用.我的循环给了我这个结果
english
french
notALanguage
spanish
Run Code Online (Sandbox Code Playgroud)
代码
var languages = {
english: "Hello!",
french: "Bonjour!",
notALanguage: 4,
spanish: "Hola!"
};
// print hello in the 3 different languages
for(var hello in languages){
var value = hello;
if (typeof value === "string"){
console.log(value);
}
}
Run Code Online (Sandbox Code Playgroud)
这些是练习的说明
如果你真的想到它,对象就不那么陌生了!
请记住,您可以使用typeof myVariable来计算变量的类型.我们现在关注的类型是"对象","字符串"和"数字".
回想一下for-in循环:
for(var x in obj){executeSomething(); }
这将逐个遍历obj的所有属性,并在每次循环运行时将属性名称分配给x.
让我们结合我们对这两个概念的了解.
检查语言对象.三个属性是字符串,而一个是数字.
使用for-in循环打印出三种打招呼方式.在循环中,您应该检查属性值是否为字符串,这样您就不会意外地打印数字.
这个带有随附博客文章的项目演示了如何将Karma与React.js一起使用,但是当你运行npm run testKarma 时,很快就会打开浏览器并快速关闭它,不允许你调试应用程序(它应该这样做).我将配置更改为singleRun: false,认为它可能会singleRun关闭应用程序.
我还补充说autoWatch: true希望它可以保持测试结果可见,但这也不起作用.
问题:如何获得业力以保持浏览器打开足够长的时间来查看测试结果并调试应用程序?
这是karma.config.js文件
var webpack = require('webpack');
module.exports = function (config) {
config.set({
// browsers: [ process.env.CONTINUOUS_INTEGRATION ? 'Firefox' : 'Chrome' ],
browsers: [ 'Chrome' ],
singleRun: true,
// autoWatch: true,
frameworks: [ 'mocha' ],
files: [
'tests.webpack.js'
],
preprocessors: {
'tests.webpack.js': [ 'webpack', 'sourcemap' ]
},
reporters: [ 'dots' ],
webpack: {
devtool: 'inline-source-map',
module: {
loaders: [
{ test: /\.js$/, …Run Code Online (Sandbox Code Playgroud) 我正在使用Ryan Bates在第273集中介绍的Ruby的地理编码器宝石http://railscasts.com/episodes/273-geocoder?view=asciicast.在那一集中,他使用以下内容搜索半径50公里范围内的对象(尽管他使用的是位置模型,我使用的是用户模型).
@users = User.near(params[:search], 50, :order => :distance)
Run Code Online (Sandbox Code Playgroud)
当我在带有postgres的Rails 4应用程序上运行此代码时,它说
PG::Error: ERROR: column users.distance does not exist
Run Code Online (Sandbox Code Playgroud)
在Ryan的演示应用程序(代码https://github.com/railscasts/273-geocoder/tree/master/siteseer-after)中,他的位置模型上没有距离列(因为我没有它我的用户模型)所以我认为这distance是由Geocoder gem提供的东西.但是,查看地理编码器的文档http://rdoc.info/github/alexreisner/geocoder/master/frames,没有distance方法,所有其他类似距离的方法都会产生相同的错误.
有谁知道我如何通过距离在该查询中订购结果?
更新在地理编码器主页http://www.rubygeocoder.com/上给出了这个使用示例distance,但是当我尝试它时它说用户不存在.
nearbys = Place.near("Omaha, NE", 50,
:order => "distance")
bearing = nearbys.first.bearing # => 46.12
Geocoder::Calculations.compass_point(
bearing) # => "NE"
Run Code Online (Sandbox Code Playgroud)
更新
这是生成的sql
ActionView::Template::Error (PG::Error: ERROR: column users.distance does not exist
LINE 1: ...ngitude) * PI() / 180 / 2), 2))) <= 50) ORDER BY "users".di... …Run Code Online (Sandbox Code Playgroud)