小编Dar*_*rme的帖子

是否有"width:-moz-fit-content;"的css跨浏览器值?

我需要一些div作为中心位置,同时适合它们的内容宽度.

我现在这样做:

.mydiv-centerer{

  text-align: center;

  .mydiv {
    background: none no-repeat scroll 0 0 rgba(1, 56, 110, 0.7);
    border-radius: 10px 10px 10px 10px;
    box-shadow: 0 0 5px #0099FF;
    color: white;
    margin: 10px auto;
    padding: 10px;
    text-align: justify;
    width: -moz-fit-content;
  }
}
Run Code Online (Sandbox Code Playgroud)

现在,最后一个命令"width:-moz-fit-content;" 正是我所需要的!

唯一的问题是..它只适用于Firefox.

我也试过"display:inline-block;" ,但我需要这些div表现得像div.也就是说,每下一格应,而不是内联,以前的.

你知道任何可能的跨浏览器解决方案吗?

css firefox cross-browser css3

69
推荐指数
4
解决办法
7万
查看次数

如何使用seed.rb有选择地填充开发和/或生产数据库?

我正在使用seed.rb来填充我的开发和生产数据库.我通常使用虚拟数据填充第一个,后者使用我的应用程序需要运行的真实最小数据(例如第一个用户等)填充.

如何在seed.rb中指定每个数据的环境?

鉴于我知道"group"是一个Gemfile方法,我想为seed.rb实现相同的行为.

我想在seed.rb中写这样的东西:

group :development do 
  # development specific seeding code
end

group :production do 
  # production specific seeding code
end

# non-specific seeding code (it always runs) 
Run Code Online (Sandbox Code Playgroud)

这样就可以调用特定于开发的代码和非特定代码

$ rake db:seed
Run Code Online (Sandbox Code Playgroud)

并使用以下命令调用特定于生产的代码和非特定代码:

$ rake db:seed RAILS_ENV=production 
Run Code Online (Sandbox Code Playgroud)

谢谢

environment ruby-on-rails ruby-on-rails-3

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

如何在未选中时使check_box_tag发布'false'或'0'参数?

使用以下check_box_tag:

<%= check_box_tag 'object[boolean_attribute]', 1, object.boolean_attribute %>
Run Code Online (Sandbox Code Playgroud)

我只能在一个方向更新boolean_attribute:从false到true.

如果默认情况下未选中(因为object.boolean_attribute为false)并且我检查它然后提交表单,则发布a:boolean_attribute => 1参数.

但是,当我尝试从true更新为false时,没有传递param,因此boolean_attribute保持为true.

换句话说,默认情况下检查时(因为object.boolean_attribute为true)并且我取消选中它然后提交表单,则不会发布:boolean_attribute => 0 .

如何取消选中此check_box_tag以发布:boolean_attribute => 0参数?

从api我无法弄清楚是否有一些选项可以轻松实现它:http: //api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-check_box_tag

谢谢.

编辑

出于某种原因,我无法理解,在我的实际代码中(使用嵌套的多对多关联),hidden_​​field_tag无效.

<%= hidden_field_tag 'order[preparations_attributes][][cooked]', nil %>
<%= check_box_tag 'order[preparations_attributes][][cooked]', '1', preparation.cooked? %>
Run Code Online (Sandbox Code Playgroud)

现在我遇到了相反的问题:我可以取消选中复选框,并按照预期更新准备工作,但是如果我选中复选框,它会使参数更加混乱.

以下是未选中框的已发布参数:

Parameters: {"utf8"=>"?", "authenticity_token"=>"bGgPGbk+Cuk2q+LEgqetmk4e7xie8dB3iMP9Cj3SUm0=", "order"=>{"customer_name"=>"Duccio Armenise", "duedate"=>"2012-04-25 09:24:00.000000", "preparations_attributes"=>[{"quantity"=>"1", "description"=>"custom recipe", "kind"=>"custom", "cooked"=>"", "recipe_id"=>"9", "id"=>"86", "quantities_attributes"=>[{"ingredient_id"=>"", "qty"=>"", "_destroy"=>"0"}, {"ingredient_id"=>"11", "qty"=>"5.0", "id"=>"193", "_destroy"=>"0"}], "_destroy"=>"0"}], "add_preparation"=>{"recipe_id"=>""}}, "continue"=>"Confirm", "id"=>"31"}
Run Code Online (Sandbox Code Playgroud)

现在看看当我检查复选框时出现了一些混乱,从"cooked"=>""开始,出于某种原因,Rails太早关闭了prepare_attributes哈希!

Parameters: {"utf8"=>"?", "authenticity_token"=>"bGgPGbk+Cuk2q+LEgqetmk4e7xie8dB3iMP9Cj3SUm0=", "order"=>{"customer_name"=>"Duccio Armenise", "duedate"=>"2012-04-25 09:24:00.000000", "preparations_attributes"=>[{"quantity"=>"1", "description"=>"custom recipe", "kind"=>"custom", "cooked"=>""}, …
Run Code Online (Sandbox Code Playgroud)

checkbox ruby-on-rails params ruby-on-rails-3

36
推荐指数
3
解决办法
4万
查看次数

Rails - 强制字段大写并唯一验证

机场有四个字母的ICAO代码.按照惯例,它们总是大写的.我正在创建一个用于接收用户输入的表单,但是此表单需要能够以大小写混合的形式接受用户输入,并防止它们创建欺骗.

:uniqueness当然,默认情况下区分大小写.我想出了如何在保存之前将用户的输入转换为大写,但问题是这似乎是后验证,而不是预验证.

例如,如果已经有ICAO的机场KLAX,用户可以输入klax,它将被验证为唯一,然后转换为大写并存储,从而产生重复.

这是我目前的型号代码.

class Airport < ActiveRecord::Base
  validates :icao, :name, :lat, :lon, :presence => true
  validates :icao, :uniqueness => true

  before_save :uppercase_icao

  def uppercase_icao
    icao.upcase!
  end
end
Run Code Online (Sandbox Code Playgroud)

validation activerecord ruby-on-rails ruby-on-rails-3

10
推荐指数
4
解决办法
9510
查看次数

Paperclip(3.0)和Rails(3.2):f.file_field在验证错误后丢失'new'操作的文件路径

我设置了一个story带有imagePaperclip处理的附件的模型,看起来像:

class Story < ActiveRecord::Base  
  has_attached_file :image # [...]
  attr_accessible :user_id, :title, :image, :image_file_name
  belongs_to: user

  validates_presence_of :user_id
  validates :title,     :length => { :maximum => 50 }
  validates_attachment_size :image, :less_than => 2.megabytes, :unless => Proc.new { |story| story[:image].nil? }
  # [...] 
end
Run Code Online (Sandbox Code Playgroud)

当我填写我的故事表格时,看起来像:

<%= form_for @story, html: { multipart: true } do |f| %>
<% if @story.errors.any? %>
<div id="error-explanation">
    <ul>
        <% @story.errors.full_messages.each do |msg| %>
        <li class="error-mess">Error: <%= msg.downcase %></li>
        <% end %>
    </ul>
</div> …
Run Code Online (Sandbox Code Playgroud)

file-upload ruby-on-rails paperclip

8
推荐指数
1
解决办法
2189
查看次数

使用Rails发送多部分电子邮件:如何在纯文本上支持HTML版本?

我按照官方指南设置了具有多部分视图的标准导轨邮件程序,如下所示:

mail(to: user.email, subject: "Welcome") do |format|
   format.html { render layout: 'my_layout' }
   format.text
end
Run Code Online (Sandbox Code Playgroud)

明确和共同的意图是优先考虑html版本的消息,只是发现,正如本文所指出的那样,在调用format.html之前format.text使很多邮件客户端只显示消息的文本版本.在我的情况下,我使用Gmail和Mozilla Thunderbird验证(并且努力).

是否有可靠的解决方案优先使用html版本?

email ruby-on-rails html-email ruby-on-rails-3

8
推荐指数
1
解决办法
929
查看次数

如何使用"validates:attribute"来引用父对象属性的值来验证属性?

O'Reilly的"Head first Rails"(编辑,2009)的练习中,有2个相关的对象.

"飞行"的对象[我用来注释宝石显示每个属性]:

# == Schema Information
#
# Table name: flights
#
#  id                :integer         not null, primary key
#  departure         :datetime
#  arrival           :datetime
#  destination       :string(255)
#  baggage_allowance :decimal(, )
#  capacity          :integer
#  created_at        :datetime
#  updated_at        :datetime
#

class Flight < ActiveRecord::Base
  has_many :seats
end
Run Code Online (Sandbox Code Playgroud)

Ant "Seat"对象:

# == Schema Information
#
# Table name: seats
#
#  id         :integer         not null, primary key
#  flight_id  :integer …
Run Code Online (Sandbox Code Playgroud)

validation ruby-on-rails customvalidator ruby-on-rails-3

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

RSpec定制匹配Cucumber到DRY实现相关的测试,是否可能?

我正在阅读Michael Hartl的新版"Rails Tutorial",因为我非常喜欢使用Cucumber的BDD,所以我发现自己很担心作者在这里指出的内容:http: //ruby.railstutorial.org/ ?章节/登入-SIGN出的版本= 3.2#秒:rspec_custom_matchers

简而言之,与Cucumber的主要麻烦在于,不可能像以下那样执行依赖于实现的测试:

Then /^he should see an error message$/ do
  page.should have_selector('div.alert.alert-error', text: 'Invalid')
end
Run Code Online (Sandbox Code Playgroud)

写这样的RSpec自定义匹配器:

RSpec::Matchers.define :have_error_message do |message|
  match do |page|
    page.should have_selector('div.alert.alert-error', text: message)
  end
end 
Run Code Online (Sandbox Code Playgroud)

因为这样的自定义匹配器必须放在spec/support/utilities.rb中,并且可以从RSpec集成测试调用,但不能从Cucumber步骤定义调用.

你是积极的/你对此有何看法?

谢谢.

bdd integration-testing rspec ruby-on-rails cucumber

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

如何将remote_form_for的:update =>'div_id'选项从Rails 2升级到Rails 3?

我无法弄清楚如何将此代码从Rails 2升级到Rails 3:

<% remote_form_for(item, :update => 'div_id') do |f| %>
... 
Run Code Online (Sandbox Code Playgroud)

我试过这个:

<%= form_for :item, :remote => true, :url => { :controller => "items", :action => "create" }, :update => 'div_id' do |f| %>
...
Run Code Online (Sandbox Code Playgroud)

它会创建新项目,但无法更新<div id="div_id"></div>标记内的内容.似乎Rails 3不再支持:update遥控器的" "选项form_for.有什么建议吗?

ajax ruby-on-rails upgrade form-for ruby-on-rails-3

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

如何通过url params动态设置Datatables搜索和列过滤器状态?

假设我有两种模式:客户订单.每个订单都属于客户.

我还设置了一个订单(索引)视图,其中Datatable显示了所有订单.如果我想查看给定客户的所有订单,我所要做的就是过滤该客户在"搜索"字段中编写相关客户名称或从其列过滤器字段中选择该客户的结果.

现在,我想实现一个客户订单链接,该链接会自动显示带有这些设置的数据表订单.

换句话说,我希望链接到/ orders?isearch ='customer_name + customer_surname'将显示已在搜索字段中写入客户全名的数据表(或相应的客户列过滤器集).

当然,我可以取@customer从控制器实例变量并将其传递给视图,但然后

ruby-on-rails datatables ruby-on-rails-3

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

给定n个subArrays Sn的数组A,如何在Ruby中选择Sn [i]成员数组?

给定n个subArrays Sn的数组A,如何在Ruby中选择Sn [i]成员数组?

例如,给定一个如下数组languages:

languages = [ ['Italiano', 'it'], ["English", 'en'], ["Française", 'fr' ] ]
Run Code Online (Sandbox Code Playgroud)

我怎样才能获得数组......

locales_in_languages = ['it', 'en', 'fr' ]
Run Code Online (Sandbox Code Playgroud)

...包含所有language[1]对象?

是否有一种简单的'rubysh'方法来实现这一目标?

ruby arrays multidimensional-array

0
推荐指数
1
解决办法
339
查看次数