我在这里发了一个类似的问题
但我决定放弃这项服务,因为我无法让它发挥作用.
我在我的网站上运行了PageSpeed Insights来确定我网站的速度.
我收到的最重要的建议是启用压缩.
Compressing resources with gzip or deflate can reduce the number of bytes sent over the network.
Enable compression for the following resources to reduce their transfer size by 191.2KiB
(74% reduction).
Run Code Online (Sandbox Code Playgroud)
我按照本网站上的说明操作
https://developers.google.com/speed/docs/insights/EnableCompression
它说要查看有关如何启用压缩的Web服务器的文档:
我用这个网站找出了我的网络服务器
http://browserspy.dk/webserver.php
事实证明我的网络服务器是WEBrick.
PageSpeed Insights页面仅列出以下3个服务器
Apache: Use mod_deflate
Nginx: Use ngx_http_gzip_module
IIS: Configure HTTP Compression
Run Code Online (Sandbox Code Playgroud)
我搜索了有关WEBrick服务器的gzip压缩文档,但找不到任何东西.
我已经搜索了如何在Rails中启用压缩,但找不到任何东西.这就是我在这里问的原因.
我尝试过使用Rack Zippy,但放弃了它.
现在,我甚至不知道从哪里开始.我的第一步是找出我应该做的事情.
编辑
我按照艾哈迈德的建议使用Rack :: Deflator
我确认通过跑步得到了它
rake middleware
=> use Rack::Deflator
Run Code Online (Sandbox Code Playgroud)
然后
git add .
git commit -m '-'
git push …Run Code Online (Sandbox Code Playgroud) 我克隆了一个 GitHub 目录,因为我想帮助一个开源项目。
下面列出了该项目的链接,因此您可以随意尝试一下。
https://github.com/tupini07/RubyMan
根据自述文件,我做了以下
git clone https://github.com/tupini07/RubyMan
cd projects/RubyMan
ruby main.rb
Run Code Online (Sandbox Code Playgroud)
编辑
我通过运行 gem install win32console 解决了第一个问题,但我仍然遇到了同样的问题。
错误信息
C:\Users\darkmouse\Documents\Projects\RubyMan>ruby main.rb
C:/Ruby200/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:54:in
`require': cannot load such file -- 2.0/Console_ext (LoadError)
from C:/Ruby200/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/win32console-1.3.2-x86-mingw32/
lib/Win32/Console.rb:12:in `rescue in <top (required)>'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/win32console-1.3.2-x86-mingw32/
lib/Win32/Console.rb:8:in `<top (required)>'
from C:/Ruby200/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby200/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/win32console-1.3.2-x86-mingw32/
lib/Win32/Console/ANSI.rb:13:in `<top (required)>'
from C:/Ruby200/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby200/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/win32console-1.3.2-x86-mingw32/
lib/win32console.rb:1:in `<top (required)>'
from C:/Ruby200/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:128:in `require'
from C:/Ruby200/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:128:in `rescue in require'
from C:/Ruby200/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:39:in `require'
from …Run Code Online (Sandbox Code Playgroud) 我有一个非常复杂的模型,有许多字段,has_many关联,图像image_column等等...
New对象将通过多页表单添加(8个步骤) - 如何在这些步骤之间完成验证和传播?
我认为validation_group可以用于定义每个步骤的验证,整体设计呢?
我试图替换一个表达式,除非该表达式是两个值之一。
def substitute_string (string)
string.gsub('abc', 'xyz') unless string == ('dabc' || 'eabc')
end
substitute_string('jjjjjabc')
=> 'jjjjjxyz'
substitute_string('dabc')
=> 'dabc'
substitute_string('eabc')
=> 'exyz'
Run Code Online (Sandbox Code Playgroud)
我希望replace_string('eabc')返回('eabc'),因为我在除非块中声明了该值,并传递了两个值。
我不明白为什么这行不通,并且我可以做些什么来使'eabc'返回'eabc'。
我最近升级到了最新版本的Rails,但我不知道如何将应用程序部署到Heroku。
这是我的database.yml档案
default: &default
adapter: postgresql
pool: 5
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
test:
<<: *default
database: db/test.sqlite3
production:
<<: *default
database: db/production.sqlite3
Run Code Online (Sandbox Code Playgroud)
我以前从未在database.yml中看到此语法。有人知道如何配置吗?
看起来和我习惯的有很大不同
development:
adapter: mysql2
encoding: utf8
database: my_app_development
pool: 5
username: root
password:
test:
adapter: mysql2
encoding: utf8
database: my_app_test
pool: 5
username: root
password:
production:
adapter: mysql2
encoding: utf8
database: ymca_gym_production
pool: 5
username: root
password:
Run Code Online (Sandbox Code Playgroud)
谢谢
在编码布局中,链接的样式就像
<a href="#" class="class1 class2 class3"><span>Previous</span></a>
<a href="#" class="class1 class2 class3"><span>Next</span>
Run Code Online (Sandbox Code Playgroud)
我试图搜索,我发现这两个链接的形状可能有一些修改.它的:
<div class="pag">
<%= will_paginate @data, :page_links => false, :next_label => '' %>
</div>
<div class="pag">
<%= will_paginate @data, :page_links => false, :previous_label => '' %>
</div>
Run Code Online (Sandbox Code Playgroud)
我的问题:如何将第二个示例更新为第一个示例的形状?我的问题是这两个span要素......
谢谢
我知道你可以使用复数特征在Rails中复数一个单词.
pluralize (3, 'cat')
=> 3 cats
Run Code Online (Sandbox Code Playgroud)
但我想要做的是复数一个需要复数多个单词的句子.
There are <%= Cat.count %> cats
Run Code Online (Sandbox Code Playgroud)
问题是,如果只有一只猫.它会回来
There are 1 cats
Run Code Online (Sandbox Code Playgroud)
哪个没有意义.
应该说
There are x cats (if x is not 1)
There is 1 cat (if there is only 1)
Run Code Online (Sandbox Code Playgroud)
问题是,我无法弄清楚如何将其复数化,因为我们在这里有两个参数(是和猫).
任何帮助将不胜感激.
也许是这样的?
if Cat.count == 1
puts "There is 1 cat"
else
puts "There are #{Cat.count} cats"
end
Run Code Online (Sandbox Code Playgroud) 背景
我正在我的应用程序中实现一项功能,允许用户评价和查看图片.
我的问题源于嵌套审查图片资源中的资源,特别是在我的Review#Edit函数中.错误消息明确声明缺少必需的键:[:id]
错误信息
ActionController::URLGenerationError in Reviews#Edit
No route matches {:action=>"show", :controller=>"reviews", :format=>nil, :picture_id=>#<Review id: 4, username: "DarkMouse", body: "Updating review", picture_id: 11, created_at: "2014-08-14 03:26:52", updated_at: "2014-08-14 03:55:29">, :id=>nil} missing required keys: [:id]
Undefined method 'reviews_path' for #<#<Class:0x45c1b00>:0x39ae810>
Extracted source (Around line #7):
4 <div class = 'center'>
5 <div class = 'center'>
6
7 <% form_for [:picture, @review] do |f| %>
8
9 <p>
10 <%= f.label :username, :class => 'marker' %><br />
Run Code Online (Sandbox Code Playgroud)
我在Stack Overflow.com上搜索了答案(我的参考文献在底部给出)并被建议这样做.
<td><%= link_to 'Edit', …Run Code Online (Sandbox Code Playgroud) 我创建了一个网页,其中包含有两个数字输入域的表单field1和field2.我正在对这些领域进行验证.field1具有min值1和max值10万,但field2应该有min值max的field1或者1,什么是更大,max是100000我试图指定ng-model的field1作为min的field2,但它不能正常工作.
<div class="row">
<div>
<input ng-model="priceminrange" name="priceminrange" type="number"
class="form-control" value="" placeholder="MinRange" min="1" max="100000">
<span ng-show="form.priceminrange.$error.number">The value is not a valid number</span>
<span ng-show="form.priceminrange.$error.min || form.priceminrange.$error.max">
The value must be in range 1 to 100000</span>
</div>
<div>
<input ng-model="pricemaxrange" name="pricemaxrange" type="number"
class="form-control" value="" placeholder="MaxRange" min={{priceminrange}} max="100000">
<span ng-show="form.pricemaxrange.$error.number">The value is not a valid …Run Code Online (Sandbox Code Playgroud) 给定一个Ruby数组,我需要找到是否存在一个元素,其中元素左边的元素总和等于它右边元素的总和.
例
[1,2,3,3]
Run Code Online (Sandbox Code Playgroud)
元素是3,因为3 [1,2]左边的元素之和等于3右边元素的总和.
我不知道如何解决这个问题,但我会试一试.
def left_equal_right(array)
array.any? do |x|
index = array.index(x)
array[0..index-1].inject(:+) == array[index+1..-1].inject(:+)
end
end
array.any?([1,2,3,3])
=> returns true, but I'm not sure this method works for larger arrays.
Run Code Online (Sandbox Code Playgroud)