我需要创建没有跟随链接link_to.
我正在寻找这样的东西:
<%= link_to "example", example_path, :target => "_blank" %>
但是当然没有遵循.
我正在使用Libnotify提供的通知成功运行Guard.
funkdified@funkdified-laptop:~/railsprojects/sample_app$ guard
Guard uses Libnotify to send notifications.
Guard is now watching at '/home/funkdified/railsprojects/sample_app'
Guard::RSpec is running, with RSpec 2!
Running all specs
...
Finished in 0.06053 seconds
3 examples, 0 failures
Run Code Online (Sandbox Code Playgroud)
如果我修改spec文件,我会在终端和弹出通知中提示测试结果.如果我修改控制器文件,再次测试运行正常.但是,当我修改routes.rb时,整个事情就会落在脸上,Guard会停止正常工作并引发错误.有人有主意吗?
错误:
Running: spec/routing
/home/funkdified/.rvm/gems/ruby-1.9.3-p0@rails3tutorial/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `load': cannot load such file -- /home/funkdified/railsprojects/sample_app/spec/routing (LoadError)
from /home/funkdified/.rvm/gems/ruby-1.9.3-p0@rails3tutorial/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `block in load_spec_files'
from /home/funkdified/.rvm/gems/ruby-1.9.3-p0@rails3tutorial/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `map'
from /home/funkdified/.rvm/gems/ruby-1.9.3-p0@rails3tutorial/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `load_spec_files'
from /home/funkdified/.rvm/gems/ruby-1.9.3-p0@rails3tutorial/gems/rspec-core-2.8.0/lib/rspec/core/command_line.rb:22:in `run'
from /home/funkdified/.rvm/gems/ruby-1.9.3-p0@rails3tutorial/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:80:in `run_in_process'
from /home/funkdified/.rvm/gems/ruby-1.9.3-p0@rails3tutorial/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:69:in `run'
from /home/funkdified/.rvm/gems/ruby-1.9.3-p0@rails3tutorial/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:10:in `block in autorun
Run Code Online (Sandbox Code Playgroud)
忘了提一下,如果我杀了Guard并重新启动(在对routes.rb进行更改之后),那么Guard再次正常执行,表明测试现在已经失败:
funkdified@funkdified-laptop:~/railsprojects/sample_app$ guard
Guard uses Libnotify to send notifications. …Run Code Online (Sandbox Code Playgroud) 我正在使用Zurb Ink模板发送电子邮件.当我在mailcatcher(来自开发服务器)中查看电子邮件时,一切看起来都不错,但是当我从生产服务器(到我的Gmail帐户)收到电子邮件时,所有的CSS样式都消失了.
我试过看一些这些答案,但似乎没有任何效果.这是错误.
funk@funktop ~/rails_projects/hearingtracker $ gem install debugger -v '1.6.8'
Fetching: columnize-0.8.9.gem (100%)
Successfully installed columnize-0.8.9
Fetching: debugger-ruby_core_source-1.3.5.gem (100%)
Successfully installed debugger-ruby_core_source-1.3.5
Fetching: debugger-linecache-1.2.0.gem (100%)
Successfully installed debugger-linecache-1.2.0
Fetching: debugger-1.6.8.gem (100%)
Building native extensions. This could take a while...
ERROR: Error installing debugger:
ERROR: Failed to build gem native extension.
/home/funk/.rvm/rubies/ruby-2.1.2/bin/ruby extconf.rb
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You …Run Code Online (Sandbox Code Playgroud) 我有一个工作的twitter bootstrap安装和简单的表单生成以下内容:
<form accept-charset="UTF-8" action="/find_map" class="simple_form form-inline" id="new_location" method="post" novalidate="novalidate"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /><input name="authenticity_token" type="hidden" value="p5CSoidWaoGMfHY0/3ElWi0XJVg6Cqi9GqWRNlJLBQg=" /></div>
<div class="control-group string required"><div class="controls"><input class="string required" id="location_address" name="location[address]" placeholder="Address" size="50" type="text" /></div></div><input class="btn" name="commit" type="submit" value="Find!" />
</form>
Run Code Online (Sandbox Code Playgroud)
不知何故,"寻找!" 按钮不会出现在搜索框的同一行.有任何想法吗?
谢谢!
更新:
对不起我应该提到所有标记都是由simple_form根据以下内容生成的:
<%= simple_form_for @location, :url => find_map_path, :html => { :class => 'form-inline' } do |f| %>
<%= f.input :address, :label => false, :placeholder => "Address" %>
<%= f.submit "Find!", :class => 'btn' %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
所以,实际上,生成的标记似乎存在问题,即使我已经为simple_form运行了bootstrap安装等. …
是的,所以我有一个多态关联,允许不同的对象类型被收藏.所以一个人可以喜欢一个产品,一个人,或其他什么.我想要做的是防止有人使用收藏夹模型中的验证唯一性来复制收藏夹.
class Favorite < ActiveRecord::Base
belongs_to :favoritable, :polymorphic => true
belongs_to :user
attr_accessible :user
validates_presence_of :user
validates :user_id, :uniqueness => { :scope => [:favoritable_type, :favoritable_id] }
end
Run Code Online (Sandbox Code Playgroud)
验证似乎正在起作用,但无论出于何种原因,当尝试复制条目时,仍然使用user_id创建新的Favorite行.

有没有办法阻止这个初始保存?
似乎Rails正在创建数据库条目,然后使用favoritable_id和favoritable_type更新它,如下所示:
SQL (28.3ms) INSERT INTO "favorites" ("created_at", "favoritable_id", "favoritable_type", "updated_at", "user_id") VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["created_at", Tue, 14 Aug 2012 10:26:31 UTC +00:00], ["favoritable_id", nil], ["favoritable_type", nil], ["updated_at", Tue, 14 Aug 2012 10:26:31 UTC +00:00], ["user_id", 23]]
(7.8ms) COMMIT
(0.1ms) BEGIN
Favorite Exists (0.3ms) SELECT 1 AS …Run Code Online (Sandbox Code Playgroud) 我想为下面的表单创建一个编辑页面.问题在于,当用户浏览编辑页面时,brand_name和名称被预先填充,但是图像上载字段显示"没有选择文件",即使存在"样式"的化身也是如此.如果有办法解决这个问题,请告诉我.谢谢!
我的编辑表格:
<%= simple_form_for @style, :html => { :class => 'form-horizontal' }, :remote => true do |m| %>
<%= m.input :brand_name, :label => 'Brand', :placeholder => 'Brand' %>
<%= m.input :name, :label => 'Style', :placeholder => 'Style' %>
<%= m.input :avatar, :label => "Image" %>
<div class="form-actions" style = "background:none">
<%= m.submit nil, :class => 'btn btn-primary' %>
<%= link_to 'Cancel', styles_path, :class => 'btn' %>
</div>
<% end %>
Run Code Online (Sandbox Code Playgroud) 我无法找到执行以下操作的方法:
让我们在我的application.html.erb中说我有以下内容
<div id="one" >
<%= yield %>
</div>
Run Code Online (Sandbox Code Playgroud)
然后我想要另一个布局文件asdf.html.erb
<div id="two">
<%= yield %>
</div>
Run Code Online (Sandbox Code Playgroud)
我想要最终输出
<div id="one>
<div id="two">
<%= yield %>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
可能吗?谢谢.
看看这个小提琴.我究竟做错了什么?是不是响应选项应该强制图表填充它的容器?

<div style="width:800px; height:400px;">
<canvas id="myChart"></canvas>
</div>
<script>
$( document ).ready(function() {
var data = {
labels: ["January", "February", "March", "April", "May", "June", "July"],
datasets: [
{
label: "My First dataset",
fillColor: "rgba(220,220,220,0.2)",
strokeColor: "rgba(220,220,220,1)",
pointColor: "rgba(220,220,220,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(220,220,220,1)",
data: [65, 59, 80, 81, 56, 55, 40]
},
{
label: "My Second dataset",
fillColor: "rgba(151,187,205,0.2)",
strokeColor: "rgba(151,187,205,1)",
pointColor: "rgba(151,187,205,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(151,187,205,1)",
data: [28, 48, 40, 19, 86, 27, 90]
} …Run Code Online (Sandbox Code Playgroud) 我试图将我的应用程序转换为异步javascript加载:
<%= javascript_include_tag "application", async: true %>
Run Code Online (Sandbox Code Playgroud)
问题是在异步加载Jquery之前,正在运行任何特定于页面的脚本.在加载application.js清单文件之前,如何推迟这些操作.
我尝试包装我的页面js $(window).load(function(){});但这没有帮助.我仍然看到以下错误:
Uncaught ReferenceError: $ is not defined
Run Code Online (Sandbox Code Playgroud)
更新:
这似乎对我有用,但我希望有人确认这是正确的方法:
<%= javascript_include_tag "application", async: true, onload: 'pageScripts()' %>
Run Code Online (Sandbox Code Playgroud)
然后页面脚本如:
<script>
function pageScripts() {
// do something
}
</script>
Run Code Online (Sandbox Code Playgroud) javascript ×2
asynchronous ×1
chart.js ×1
charts ×1
email ×1
guard ×1
jquery ×1
layout ×1
mandrill ×1
nested ×1
nofollow ×1
ruby-2.1 ×1
simple-form ×1
zurb-ink ×1