小编Vic*_*tor的帖子

在自动完成选项中解析Google地图中的address_components

我有以下代码来解析country选择自动完成列表的时间:

$('#spot_address').autocomplete({
  // This bit uses the geocoder to fetch address values
  source: function(request, response) {
    geocoder.geocode( {'address': request.term }, function(results, status) {
      // Get address_components
      for (var i = 0; i < results[0].address_components.length; i++)
      {
        var addr = results[0].address_components[i];
        var getCountry;
        if (addr.types[0] == 'country') 
          getCountry = addr.long_name;
      }
      response($.map(results, function(item) {
        return {
          label: item.formatted_address,
          value: item.formatted_address,
          latitude: item.geometry.location.lat(),
          longitude: item.geometry.location.lng(),
          country: getCountry
        }
      }));
    })
  },

  // This bit is executed upon selection of an …
Run Code Online (Sandbox Code Playgroud)

javascript jquery google-maps google-maps-api-3

13
推荐指数
6
解决办法
3万
查看次数

在Rails中关联标签和单选按钮

我正在使用Rails 2.3.8.我的代码:

<%= f.radio_button :status, "draft" %>
<%= f.label :status, "Draft" %>
<%= f.radio_button :status, "published" %>
<%= f.label :status, "Published" %>
Run Code Online (Sandbox Code Playgroud)

输出:

<input id="shop_status_draft" name="shop[status]" type="radio" value="draft" />
<label for="shop_status">Draft</label>
<input checked="checked" id="shop_status_published" name="shop[status]" type="radio" value="published" />
<label for="shop_status">Published</label>
Run Code Online (Sandbox Code Playgroud)

显然,label没有正确地关联我的单选按钮.我想label和单选按钮一样id.我怎么能纠正这个?

谢谢.

forms ruby-on-rails

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

Rails 4范围与参数

升级Rails 3.2.到Rails 4.我有以下范围:

# Rails 3.2
scope :by_post_status, lambda { |post_status| where("post_status = ?", post_status) }
scope :published, by_post_status("public")
scope :draft, by_post_status("draft")

# Rails 4.1.0
scope :by_post_status, -> (post_status) { where('post_status = ?', post_status) }
Run Code Online (Sandbox Code Playgroud)

但我无法找到如何做第2和第3行.如何从第一个范围创建另一个范围?

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

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

TypeError:abc.getAttribute不是函数

对于以下代码:

  <span class="map-marker" data-lng="101.7113506794"></span>
  <span class="map-marker" data-lng="101.6311097146"></span>

  var abc = $('.map-marker:first');
  var xyz = abc.getAttribute("data-lat");
  console.log(xyz);
Run Code Online (Sandbox Code Playgroud)

我收到错误消息:TypeError: abc.getAttribute is not a function.我做错了什么?

javascript jquery

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

前端设计第一,还是后端开发第一?对于Ruby on Rails站点

我自己做的就是:前端和后端.我精通HTML和CSS,但是Ruby on Rails中的菜鸟.既然我想开发这个网站,我想知道我是应该从前端开始还是从后端开始.我现在为前端做的事情都是静态的.当我做后端时,我担心我必须改变很多前端编码.

frontend ruby-on-rails backend

10
推荐指数
1
解决办法
3153
查看次数

我们应该何时考虑使用私人或受保护?

只是想知道,我们何时应该使用privateprotected模型中的某些方法?

有时候,我不能没有在打扰我的组的方法private,也没有protected.我只是保持原样.但我知道这一定是一种不好的做法,否则这两个分组将不会在编程中创建.

谢谢.

ruby ruby-on-rails access-specifier

10
推荐指数
1
解决办法
4251
查看次数

按比例减少twitter bootstrap标题大小

不确定这是否可行.我认为Twitter Bootstrap标题大小太大了.h136px; h230px,依此类推.

有没有办法按比例减少标题大小?假设我只想要每个标题的90%.我不想逐个声明每个标题的字体大小.

谢谢.

css twitter-bootstrap

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

Rails复杂查询根据真值表计算唯一记录

使用Rails.我有以下代码:

class TypeOfBlock < ActiveRecord::Base
  has_and_belongs_to_many :patients
end

class Patient < ActiveRecord::Base
  has_and_belongs_to_many :type_of_blocks, dependent: :destroy
end
Run Code Online (Sandbox Code Playgroud)

使用这些表格:

????????????????
?type_of_blocks?
????????????????
? id   ? name  ?
????????????????
?  1   ? UP    ?
?  2   ? LL    ?
?  3   ? T     ?
????????????????

?????????????????????????????????
?    patients_type_of_blocks    ? 
?????????????????????????????????
? type_of_block_id ? patient_id ?
?????????????????????????????????
?                1 ?          1 ?
?                1 ?          2 ?
?                2 ?          2 ?
?                3 ?          3 ?
?                2 ?          4 ?
? …
Run Code Online (Sandbox Code Playgroud)

mysql sql ruby-on-rails

8
推荐指数
2
解决办法
212
查看次数

Rails中的database.yml重新连接设置为true或false

database.yml,reconnectRails 3和4 的默认设置是false.什么是共同的设置,在什么情况下我们应该设置它true?谢谢.

ruby-on-rails

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

思考Sphinx Rake中止,searchd在重建或启动/停止ts时运行.索引工作正常

当我调用时rake ts:rebuild RAILS_ENV=production,我得到以下内容:

(in /var/www/abc.com/public/abc/releases/20101008073517)
** Erubis 2.6.6
Stopped search daemon (pid 22531).
Generating Configuration to /var/www/abc.com/public/abc/releases/20101008073517/config/production.sphinx.conf
Sphinx 1.10-beta (r2420)
Copyright (c) 2001-2010, Andrew Aksyonoff
Copyright (c) 2008-2010, Sphinx Technologies Inc (http://sphinxsearch.com)

using config file '/var/www/abc.com/public/abc/releases/20101008073517/config/production.sphinx.conf'...
indexing index 'spot_core'...
collected 6 docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total 6 docs, 4622 bytes
total 0.016 sec, 278316 bytes/sec, 361.29 docs/sec
skipping non-plain index 'spot'...
indexing index 'trip_core'...
collected 3 docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done …
Run Code Online (Sandbox Code Playgroud)

indexing sphinx thinking-sphinx

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