我想打一个UILabel
或UITextView
一些文字在它2个可点击的链接.不是指向网页的链接,但我希望将这两个链接与我将使用的操作相关联UIButton
.我见过的所有例子都是webviews的链接,但我不想这样.同样,文本将以其他语言翻译,因此位置必须是动态的.
想要这样做:
我使用Ruby 1.9.2和Rails 3.0.5
我有以下错误:
不兼容的字符编码:ASCII-8BIT和UTF-8
它与我认为的数据库无关.
错误是在视图中惹恼这一行(只是一个div haml调用):
#content
Run Code Online (Sandbox Code Playgroud)
全栈:
ActionView::Template::Error (incompatible character encodings: ASCII-8BIT and UTF-8):
21: -flash.each do |name, msg|
22: =content_tag :div, msg, :id => "flash_#{name}"
23: %div.clear
24: #content
25: = yield
26: = render :partial => "layouts/grid_right" if render_grid_right?
27: = render :partial => "layouts/footer"
app/views/layouts/application.html.haml:24:in `_app_views_layouts_application_html_haml___4380000789490545718_2180251300_2717546578298801795'
actionpack (3.0.5) lib/action_view/template.rb:135:in `block in render'
activesupport (3.0.5) lib/active_support/notifications.rb:54:in `instrument'
actionpack (3.0.5) lib/action_view/template.rb:127:in `render'
actionpack (3.0.5) lib/action_view/render/layouts.rb:80:in `_render_layout'
actionpack (3.0.5) lib/action_view/render/rendering.rb:62:in `block in _render_template'
activesupport (3.0.5) lib/active_support/notifications.rb:52:in `block …
Run Code Online (Sandbox Code Playgroud) 浮动圆形向上或向下.我总是需要它来向下舍入.
我有解决方案,但我真的不喜欢它...也许有更好的方法.
这就是我要的:
1.9999.round_down(2)
#=> 1.99
1.9901.round_down(2)
#=> 1
Run Code Online (Sandbox Code Playgroud)
我想出了这个解决方案,但我想知道是否有更好的解决方案(我不喜欢我转换浮动两次).有没有这方法?因为我觉得很难找到它.
class Float
def round_down(n=0)
((self * 10**n).to_i).to_f/10**n
end
end
Run Code Online (Sandbox Code Playgroud)
谢谢.
我对此查询有点麻烦,谷歌今天不是我的朋友
我包含一个或多个大写字母的表的所有结果.像这样的东西:
SELECT * FROM personal_urls WHERE CONTAINS_UPCASE(vanity_url)
Run Code Online (Sandbox Code Playgroud)
有人知道一个简单的解决方案吗?
谢谢!
我有一个包含7000万条记录的表格,并且缺少索引.我想计算添加索引的时间,而不需要备份表并在备份表上执行索引.
我只是想知道它是慢两倍(线性)还是指数.
数据库:mysql 5.0
非常感谢
我对backbone.js有点新意,我正在努力寻找带有belongs_to关系的集合.
我想获取一个用户列表(用户/ GET),我想显示所有用户,但有一个belongs_to关联.
例如,显示用户的公司名称.有人知道解决方案吗?
我在CouchDB上使用Ruby on Rails 3
def index
User.all
end
Run Code Online (Sandbox Code Playgroud)
class UserCollection extends Backbone.Collection
url: ->
app.routes.users_url
model: User
Run Code Online (Sandbox Code Playgroud)
class User extends Backbone.Model
idAttribute: '_id'
defaults: {
"email": null
"mobile": null
"loc": null
}
url: ->
app.routes.users_url + '/' + (@id || '')
Run Code Online (Sandbox Code Playgroud)
我想像这样展示公司名称......
%script{:id => "user-resource-template", :type => "text/template"}
%td= check_box_tag "select", 1, false, :class => "checkbox", "data-id" => raw("<%= _id %>")
%td <%= name %>
%td <%= email %>
%td <%= company.name %>
Run Code Online (Sandbox Code Playgroud) 我对acts_as_paranoid对象有问题.现在我想真正破坏对象,但我找不到一个简单的方法.
我不喜欢使用硬编码的SQL来解决这个问题.
有人知道一个快速好的解决方案吗?
UPDATE
我提出了以下解决方案.我不喜欢这么多,但它有效....
# Use this function wisely
def really_destroy
ActiveRecord::Base.connection.execute("DELETE FROM user_widgets WHERE id = #{self.id}")
end
Run Code Online (Sandbox Code Playgroud) 迁移到Heroku时,我收到以下错误.
Installing hoe (2.9.4) /usr/ruby1.9.2/lib/ruby/1.9.1/rubygems/installer.rb:170:in >
install':hoe需要RubyGems版本> = 1.4.尝试'gem update --system'来更新RubyGems本身.(宝石:: InstallError)`
这就是红宝石宝石版已经过时了.有人知道我怎么能解决这个问题?
使用rails 3.0.5和ruby 1.9.2
bundler
Using rake (0.8.7)
Using RedCloth (4.2.2)
Using abstract (1.0.0)
Using activesupport (3.0.5)
Using builder (2.1.2)
Using i18n (0.5.0)
Using activemodel (3.0.5)
Using erubis (2.6.6)
Using rack (1.2.2)
Using rack-mount (0.6.14)
Using rack-test (0.5.7)
Using tzinfo (0.3.26)
Using actionpack (3.0.5)
Using mime-types (1.16)
Using polyglot (0.3.1)
Using treetop (1.4.9)
Using mail (2.2.17)
Using actionmailer (3.0.5)
Using arel (2.0.9)
Using activerecord (3.0.5)
Using activeresource (3.0.5) …
Run Code Online (Sandbox Code Playgroud) 没有在Rails 3.1.3中设置default_locale
application.rb中:
config.i18n.default_locale = :en
Run Code Online (Sandbox Code Playgroud)
我有3个语言环境(en,es和ca)当我去我的控制台时:
I18n.locale => :ca # I guess the first one in the array
Run Code Online (Sandbox Code Playgroud)
我正在使用Gettext.有人知道它可能是什么?
束:
Using rake (0.9.2.2)
Using Ascii85 (1.0.1)
Using ZenTest (4.5.0)
Using multi_json (1.0.4)
Using activesupport (3.1.3)
Using builder (3.0.0)
Using i18n (0.6.0)
Using activemodel (3.1.3)
Using erubis (2.7.0)
Using rack (1.3.6)
Using rack-cache (1.1)
Using rack-mount (0.8.3)
Using rack-test (0.6.1)
Using hike (1.2.1)
Using tilt (1.3.3)
Using sprockets (2.0.3)
Using actionpack (3.1.3)
Using mime-types (1.17.2)
Using polyglot (0.3.3)
Using treetop …
Run Code Online (Sandbox Code Playgroud) 我有一个带字符串的数组,我想按字母顺序排列,但有一些默认值在顶部.例如:
["a", "b", "default1", "d", "default2", "c", "e"]
Run Code Online (Sandbox Code Playgroud)
我希望结果如下:
["default1", "default2", "a", "b", "c", "d", "e"]
Run Code Online (Sandbox Code Playgroud)
有人知道如何轻松完成这项工作?
UPDATE
默认值也包含在数组中,数组按字母顺序排列.