小编mar*_*ion的帖子

如何将此数字置于圆圈内? - CSS

你可以在这里看到实现

我希望每个方框左上角的数字位于圆圈的中间.

救命!

html css

7
推荐指数
1
解决办法
5902
查看次数

由于我的用户表中的重复列--Rails 3.1,设计rake db:migrate失败

这是我第一次安装Devise并运行时遇到的错误rake db:migrate:

==  AddDeviseToUsers: migrating ===============================================
-- change_table(:users)
rake aborted!
An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: duplicate column name: email: ALTER TABLE "users" ADD "email" varchar(255) DEFAULT '' NOT NULL
Run Code Online (Sandbox Code Playgroud)

鉴于这只是测试数据,我可以删除我的数据库中的那个列并重新运行它,但这似乎不是Railsy - 如果只是因为它将使我的登台服务器(唯一的其他服务器与我的应用程序与我的不同步localhost.

此外,如果与另一列发生冲突,该怎么办?

因此,User在运行迁移之前,这是我的表的模式,我该如何处理?迁移某种重命名的迁移?

# == Schema Information
#
# Table name: users
#
#  id         :integer         not null, primary key
#  email      :string(255)
#  f_name     :string(255)
#  l_name     :string(255)
#  username   :string(255)
#  role_id    :integer
#  picture …
Run Code Online (Sandbox Code Playgroud)

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

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

如何在Ruby(而不是Rails)中排序日期?

我知道Rails有ActiveRecord内置的排序方法,但我只是编写一个普通的ruby脚本,并且希望按日期对数组中的记录进行排序.

日期将存储在多维数组的一个单元格中.

对我来说最好的方法是什么,所以我可以达到我刚刚做的那一点,sort_by_date我指出ASC或者DESC

我不必使用该方法sort_by_date,但我的想法是,我希望能够轻松地调用集合上的方法并获得我想要的结果.

思考?

ruby

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

为什么在OSX中的select选项上使用`-webkit-appearance:none`会使文本消失?

为了在OS X中的Chrome上获得我想要的样式,我必须使用该-webkit-appearance: none;属性.

看到这个问题这个答案.

问题是,现在当我选择一个答案时,它没有显示出来.该领域仍然是空白.

这是没有该属性的外观:

没有属性

这是它与属性的外观:

有了属性

对于它的价值,这就是我创建这个选择菜单的方式 - 使用Simple Form:

<%= f.input_field :country_id, collection: Piggybak::Country.send(type), class: "required" %>
Run Code Online (Sandbox Code Playgroud)

这是它生成的HTML:

<select class="select required required valid" id="piggybak_order_billing_address_attributes_country_id" name="piggybak_order[billing_address_attributes][country_id]"><option value=""></option>
<option value="231" selected="selected">United States</option></select>
Run Code Online (Sandbox Code Playgroud)

我该如何解决?

编辑1

这是CSS:

form.simple_form select {
    padding: 20px;
    -webkit-appearance: none;
}
Run Code Online (Sandbox Code Playgroud)

css ruby-on-rails css3 simple-form

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

尽管路由已声明,但使用Rails 5(API标志)并且没有路由错误

这是我的控制器:

class Api::V1::UsersController < ApplicationController
  respond_to :json

  def show
    respond_with User.find(params[:id])
  end
end
Run Code Online (Sandbox Code Playgroud)

这是我的 routes.rb

require 'api_constraints'

Rails.application.routes.draw do
  devise_for :users
  # Api definition
  namespace :api, defaults: { format: :json }, constraints: { subdomain: 'api' }, path: '/' do
    scope module: :v1, constraints: ApiConstraints.new(version: 1, default: true) do
      resources :users, :only => [:show]
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

这是我的 lib/api_constraints.rb

class ApiConstraints
  def initialize(options)
    @version = options[:version]
    @default = options[:default]
  end

  def matches?(req)
    @default || req.headers['Accept'].include?("application/vnd.myapp.v#{@version}")
  end
end
Run Code Online (Sandbox Code Playgroud)

我在我的数据库中添加了一条记录,如下所示:

[3] pry(main)> User.all …
Run Code Online (Sandbox Code Playgroud)

routing ruby-on-rails rails-api ruby-on-rails-5

7
推荐指数
1
解决办法
1929
查看次数

如何在simple_form中处理人员身高?

我有一个Profile具有height属性的模型.

我需要存储用户的高度(也就是配置文件),但我不太清楚如何做到这一点.我认为最好的方法是将选择下拉列表分解为英寸(即4'0",4'1"...... 6'5"等).但我不太确定最好的方法将其存储在数据库中.

我认为最简单的存储英寸,但如果我这样做,我如何以我上面指定的格式在我的选择中显示高度.

现在,我只有一个整数字段:

<%= f.input_field :height, placeholder: "176", class: 'col-lg-9 form-control' %>
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails simple-form ruby-on-rails-5

7
推荐指数
1
解决办法
501
查看次数

如何计算具有一个或多个关联对象的记录数?

我有一个Property模特has_many :photos。我想计算properties一张或多张照片的数量。

我怎么做?

我尝试了简单的方法:

> Property.where('properties.photos.count > ?', 0).count

   (3.1ms)  SELECT COUNT(*) FROM "properties" WHERE (properties.photos.count > 1)
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  missing FROM-clause entry for table "photos"
LINE 1: SELECT COUNT(*) FROM "properties"  WHERE (properties.photos....
                                                  ^
: SELECT COUNT(*) FROM "properties"  WHERE (properties.photos.count > 0)
from /ruby-2.3.0@myproject/gems/activerecord-3.2.22.5/lib/active_record/connection_adapters/postgresql_adapter.rb:1163:in `async_exec'
Caused by PG::UndefinedTable: ERROR:  missing FROM-clause entry for table "photos"
LINE 1: SELECT COUNT(*) FROM "properties"  WHERE (properties.photos....
Run Code Online (Sandbox Code Playgroud)

至:

> Property.joins(:photos).where('photos.count > ?', 0).count

   (3.7ms)  SELECT …
Run Code Online (Sandbox Code Playgroud)

join ruby-on-rails associations ruby-on-rails-3.2

7
推荐指数
1
解决办法
261
查看次数

如何使用每个元素从第二个元素开始在数组中循环? - Ruby

说我有这样的数组:

["auburn", "http://auburn.craigslist.org/web/", "http://auburn.craigslist.org/cpg/", "http://auburn.craigslist.org/eng/", "http://auburn.craigslist.org/sof/", "http://auburn.craigslist.org/sad/"]
Run Code Online (Sandbox Code Playgroud)

我想要做的只是处理这个数组中的URL - 它总是从起点开始element[1].

我怎么做?

ruby

6
推荐指数
2
解决办法
3660
查看次数

为什么Pygment.rb没有突出显示<pre class ="lang">中的<code>标签-ie Google Prettify友好标签?

我在我看来是这样称呼它:

<%= markdown question.body %>
Run Code Online (Sandbox Code Playgroud)

这就是我的ApplicationHelper样子:

module ApplicationHelper
    class HTMLwithPygments < Redcarpet::Render::HTML
      def block_code(code, language)
        Pygments.highlight(code, lexer:language)
      end
    end

    def markdown(text)
        renderer = HTMLwithPygments.new(hard_wrap: true)
        options = {
          autolink: true,
          no_intra_emphasis: true,
          fenced_code_blocks: true,
          lax_html_blocks: true,
          strikethrough: true,
          superscript: true
        }
        Redcarpet::Markdown.new(renderer, options).render(text).html_safe
    end
end
Run Code Online (Sandbox Code Playgroud)

但是,当遇到这样的标签时:

<pre class="lang-cpp prettyprint-override">
Run Code Online (Sandbox Code Playgroud)

它不会将颜色突出显示应用于该代码.这是为什么?

PS这是由Stack Overflow生成的,例如: <!-- language: lang-cpp -->

编辑1

或者更具体地说,它似乎不会格式化<code>标签内的<pre>标签.一旦<code>不在<pre>其中似乎格式化它.我该如何解决这个问题?

编辑2

问题似乎Pygment.rb是正在采取行动的数据.它是HTML,可以在这个要点中看到 - https://gist.github.com/marcamillion/14fa121cf3557d38c1a8.所以我想要做的是让Pygment body在我的要点中正确格式化该对象的属性中返回的代码.

我怎么做?

编辑3

这是我想要的HTML代码, …

markdown ruby-on-rails pygments redcarpet

6
推荐指数
1
解决办法
818
查看次数

如何使用lookup_context将此视图视为DRY?

对于初学者来说,这是我试图复制的观点:

成绩布局的截图

这是来自该布局的HTML(无论如何,您可以从SAT部分推断其余部分):

<table class="table table-hover table-bordered">
                        <thead>
                        <td colspan="2" class="text-center">
                          <strong>SAT</strong>
                        </td>
                        <tr>
                            <th>Subject</th>
                            <th>Grade</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr>
                            <td>Reading</td>
                            <td>900</td>
                        </tr>
                        <tr>
                            <td>Math</td>
                            <td>700</td>
                        </tr>
                        <tr>
                            <td>Writing</td>
                            <td>800</td>
                        </tr>
                        <tr>
                            <td><strong>Total</strong></td>
                            <td><strong>2,400</strong></td>
                        </tr>
                        </tbody>
Run Code Online (Sandbox Code Playgroud)

这就是我的Grade.rb模型:

# == Schema Information
#
# Table name: grades
#
#  id         :integer          not null, primary key
#  subject    :string
#  result     :string
#  grade_type :integer
#  profile_id :integer
#  created_at :datetime         not null
#  updated_at :datetime         not null
#

class Grade …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails erb actionview ruby-on-rails-5

6
推荐指数
1
解决办法
538
查看次数