小编mar*_*ion的帖子

什么可以使复选框不显示在页面上?

我在3.2应用程序中使用Twitter Bootstrap for Rails,但没有看到复选框出现.

如果我只用直接的HTML(带有硬编码的复选框,并使用常规的Bootstrap资产)查看同一页面,它可以正常工作.

HTML代码生成正确,我相信......例如:

<div class="field">
    <div class="control-group check_boxes optional"><label class="check_boxes optional control-label">Listing Type</label><div class="controls"><label class="checkbox"><input class="check_boxes optional" id="search_listing_type_id_1" name="search[listing_type_id][]" type="checkbox" value="1" />For Sale</label><input name="search[listing_type_id][]" type="hidden" value="" /></div></div>
  </div>
Run Code Online (Sandbox Code Playgroud)

这是Rails代码:

<%= f.input :listing_type_id, collection: ListingType.order(:name), as: :check_boxes, label: "Listing Type" %>
Run Code Online (Sandbox Code Playgroud)

这是一个实例.在文本"列出平方英尺"旁边,应该是一个复选框.向下滚动到设施,在那里你会看到一个显然应该有复选框的列表.

这在开发中也不起作用.

不太清楚为什么它没有出现.

思考?

css html5 ruby-on-rails ruby-on-rails-3 twitter-bootstrap

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

使用partials,如何以DRY方式呈现`striped`表格行?

所以我有一些看起来像这样的视图代码:

<div class="box-content">
    <table class="table table-properties">
        <tbody>             
            <%= render :partial => 'property', collection: @search.listings, as: :listing %>
        </tbody>
    </table>                                
</div>
Run Code Online (Sandbox Code Playgroud)

在那_property.html.erb,我有这个:

<tr>
    <td class="span2">
        <%= link_to listing_path(listing), :class => "thumbnail thumb2" do %>
            <%= image_tag "room_1.jpg", :alt => "Lucas" %>
        <% end %>
    </td>
    <td>
        <h2><%= link_to listing.headline, listing_path(listing) %></h2>
        <h5><%= listing.listing_type.name if listing.listing_type "#{listing.neighborhood.name.capitalize}" %></h5>
        <h5>Maintenance <%= number_to_currency(listing.maintenance) %></h5>
    </td>
    <td class="span1">
        <h2 class="price"><%= number_to_currency(listing.price)%></h2>
        <h5><%= "#{listing.num_bedrooms} bed, #{listing.num_bathrooms} bath" %></h5>
    </td>
</tr>
Run Code Online (Sandbox Code Playgroud)

基本上,我想准确地生成上面的代码,对于每一行,唯一的区别是我希望每第2行(即所有偶数行)都具有class=striped..ie <tr …

ruby-on-rails partial-views ruby-on-rails-3

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

设计问题:TypeError - [17]不是符号

我最近跑了一个bundle update,现在我变得很奇怪了

Type - [17] is not a symbol 错误.

这是完整的错误消息:

Started GET "/" for 127.0.0.1 at 2013-05-14 03:46:35 -0500

TypeError - [17] is not a symbol:
  (gem) activesupport-3.2.13/lib/active_support/inflector/methods.rb:230:in `block in constantize'
  (gem) activesupport-3.2.13/lib/active_support/inflector/methods.rb:229:in `constantize'
  (gem) devise-2.2.3/lib/devise/rails/warden_compat.rb:27:in `deserialize'
  (gem) warden-1.2.1/lib/warden/session_serializer.rb:35:in `fetch'
  (gem) warden-1.2.1/lib/warden/proxy.rb:212:in `user'
  (gem) warden-1.2.1/lib/warden/proxy.rb:318:in `_perform_authentication'
  (gem) warden-1.2.1/lib/warden/proxy.rb:104:in `authenticate'
  (gem) warden-1.2.1/lib/warden/proxy.rb:114:in `authenticate?'
  (gem) devise-2.2.3/lib/devise/rails/routes.rb:286:in `block in authenticated'
  (gem) actionpack-3.2.13/lib/action_dispatch/routing/mapper.rb:31:in `block in matches?'
  (gem) actionpack-3.2.13/lib/action_dispatch/routing/mapper.rb:28:in `matches?'
  (gem) actionpack-3.2.13/lib/action_dispatch/routing/mapper.rb:42:in `call'
  (gem) journey-1.0.4/lib/journey/router.rb:68:in `block in call'
  (gem) journey-1.0.4/lib/journey/router.rb:56:in `call'
  (gem) …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails devise ruby-on-rails-3

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

如何在选择下拉框中应用填充?

我有两种类型的输入.一个select下拉框和一个常规input.

在上面input,我添加了一个padding: 10px;让它看起来很大的东西.

问题是,一旦我把选择框放在它旁边,它们都是不同的高度.

如何将填充应用于选择,或使其与高度相同input.

这是一个实例.

编辑1

这就是我的看法: 在此输入图像描述

html css css3

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

如何使用Font Awesome字体实现基本的共享社交按钮?

这似乎是一个简单的问题,但是如何在Rails应用程序中使用Font Awesome实现基本的社交共享按钮。

我想在我的计算机上实现它们PostsController#Show

我开始研究它,以为它就像添加一个a一样简单,link_to但是很快意识到它并不那么简单。

对于Twitter,您希望帖子的标题与URL一起包含在推文的正文中。我想Facebook也很相似。

奖励积分给任何人,也可以给每篇文章都提供有关如何包括WhatsApp共享的提示(每个链接:http ://whatsapp-sharing.com/)。

css twitter facebook ruby-on-rails ruby-on-rails-4

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

如何检查模特是否有 Carrierwave 的照片?

我有一个模型——Post可以将图像和文件上传到它们。Carrierwave 中有两个不同的上传器。

我想要做的是,简单检查对象上是否存在上传的照片,如果检测到,我将显示图像标签。但如果不是,那么它什么也不显示。

我试过这个:

<% if post.photo %>
    <%= image_tag post.photo, size: "52", :class => 'entry-avatar' %>
<% end %>
Run Code Online (Sandbox Code Playgroud)

但这不起作用,它总是显示:

<img class="entry-avatar" height="52" src width="52">
Run Code Online (Sandbox Code Playgroud)

当它不为空时,它会将文件路径正确地添加到src属性中。

如果我尝试检查photo.nil?它不起作用,即使它看起来应该:

 > a 
 => #<Post id: 1, title: "Fire at Bible College in Christian", photo: nil, body: "A massive fire is now raging at the Bible College ...", created_at: "2014-08-28 08:06:19", updated_at: "2014-09-18 23:35:04", user_id: 1, ancestry: nil, file: nil, status: nil, slug: "fire-at-bible-college-in-christian", publication_status: 1, has_eyewitness: …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails carrierwave ruby-on-rails-4

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

如何将Simple_Form与嵌套资源一起使用?

我有3个型号:FamilyTree,Node,Comment.

FamilyTree上的每个条目都是一个节点.节点可以是注释.

模型如下:

FamilyTree.rb

# == Schema Information
#
# Table name: family_trees
#
#  id         :integer          not null, primary key
#  name       :string(255)
#  user_id    :integer
#  created_at :datetime
#  updated_at :datetime
#

class FamilyTree < ActiveRecord::Base
  attr_accessible :name
  belongs_to :user
  has_many :memberships, dependent: :destroy
  has_many :members, through: :memberships, source: :user, dependent: :destroy
  has_many :nodes, dependent: :destroy
end
Run Code Online (Sandbox Code Playgroud)

Node.rb

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

ruby-on-rails rails-routing simple-form ruby-on-rails-4

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

为什么这个JS会在一页上部分呈现而不是另一页?

我有一个posts.js看起来像这样的文件:

var ready;
ready = function() {

    var toggleSidebar = $(".togglesidebar");
    var primary = $("#primary");
    var secondary = $("#secondary");

    toggleSidebar.on("click", function(){

        if(primary.hasClass("col-sm-9")){
            primary.removeClass("col-sm-9");
            primary.addClass("col-sm-12");
            secondary.css('display', 'none');
        }
        else {
            primary.removeClass("col-sm-12");
            primary.addClass("col-sm-9");
            secondary.css('display', 'inline-block');
        }
    }); 
};

var counter = function(event) {
    var fieldValue = $(this).val();
    var wc = fieldValue.trim().replace(regex, ' ').split(' ').length;
    var regex = /\s+/gi;
    var $wcField;
    var maxWc;

    if ($(this)[0] === $('#post_title')[0]) {
      $wcField = $('#wordCountTitle');
      maxWc = 7;
    } else {
      $wcField = $('#wordCountBody');
      maxWc …
Run Code Online (Sandbox Code Playgroud)

javascript jquery ruby-on-rails asset-pipeline ruby-on-rails-4

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

ActiveRecord :: ReadOnlyRecord:Diff在destroy_all上标记为只读

我有一个rake任务,看起来像这样:

desc "Cleanup Snippets with Empty Diffs"

task cleanup_snippets_with_empty_diffs: :environment do
  Snippet.includes(:diffs).where(diffs: { body: "<div class=\"diff\"></div>"}).destroy_all
end
Run Code Online (Sandbox Code Playgroud)

然而,当我运行它时,我得到了这个:

$ rake cleanup_snippets_with_empty_diffs
rake aborted!
ActiveRecord::ReadOnlyRecord: Diff is marked as readonly
Run Code Online (Sandbox Code Playgroud)

可能是什么原因造成的?

编辑1

请注意,我的Snippet.rb模型如下所示:

class Snippet < ApplicationRecord
  has_many :diffs, dependent: :destroy
end
Run Code Online (Sandbox Code Playgroud)

Diff.rb像这样:

class Diff < ApplicationRecord
  belongs_to :snippet
end
Run Code Online (Sandbox Code Playgroud)

rake activerecord ruby-on-rails ruby-on-rails-5

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

为什么这个rake任务会运行两次?

我有一个主要的rake任务setup_a_new_set_of_snippets.rake,我调用,然后调用其他任务.所以主要看起来像这样:

load './lib/tasks/fetch_and_create_snippets.rake'
load './lib/tasks/generate_diffs_for_snippets.rake'
load './lib/tasks/cleanup_snippets_with_empty_diffs.rake'

desc "Setup a new set of Snippets"
task :setup_a_new_set_of_snippets, [:repo, :path, :entry_id, :framework_id, :method_name] => :environment do |task, args|
  repo = args[:repo]
  path = args[:path]
  entry_id = args[:entry_id]
  framework_id = args[:framework_id]
  method_name = args[:method_name]
  Rake::Task["fetch_and_create_snippets"].invoke(repo,path,entry_id,framework_id,method_name)
  Rake::Task["generate_diffs_for_snippets"].invoke
  Rake::Task["cleanup_snippets_with_empty_diffs"].invoke(framework_id)
end
Run Code Online (Sandbox Code Playgroud)

出于某种原因,fetch_and_create_snippets像这样运行的耙子Rake::Task["fetch_and_create_snippets"].invoke(repo,path,entry_id,framework_id,method_name)似乎运行了两次.

这是任务 - fetch_and_create_snippets.rake:

desc 'Fetch and Create Snippets from Github'

task :fetch_and_create_snippets, [:repo, :path, :entry_id, :framework_id, :method_name] => :environment do |task, args|
  repo = args[:repo]
  path = …
Run Code Online (Sandbox Code Playgroud)

ruby rake ruby-on-rails rake-task

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