你能给我一些例子是值得它使用Rubinius的,就像在这个帖子: http://yehudakatz.com/2009/08/31/simplifying-rails-block-helpers-with-a-side-of-rubinius/
我有一个形式的哈希
{:a => {"aa" => 11,"ab" => 12}, :b => {"ba" => 21,"bb" => 22}}
我如何将其转换为表单 {:a => [["aa",11],["ab",12]],:b=>[["ba",21],["bb",22]]}
我正在尝试将一个类应用于Rails 3中button_to生成的表单.
该:class选项设置提交按钮的类,以便文档告诉我们:form_class将类应用于表单.
例如
<%= button_to 'x', user_contact_path(@user, contact), :method => :delete, :form_class => "delete" %>
Run Code Online (Sandbox Code Playgroud)
这只是将属性添加form_class="delete"到按钮元素.我尝试过使用各种组合:html_options等等.
有人知道怎么做吗?
刚开始学习Rails(3).我正在试图找出如何做一些可能完全无关紧要的事情:从模型中的方法内部访问模型实例的字段的值.
就我而言:
def formal_name
@title + " " + @forename + " " + @surname
end
Run Code Online (Sandbox Code Playgroud)
所有三个@properties(它们都是数据库中表的所有字段)都会返回nil.他们不应该.
令人难以置信的是,http://guides.rails.info /中没有讨论如何访问字段,谷歌也没有任何内容.
顺便说一句,我来自Django,这个东西很明显.
I18n后备加载:
I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
Run Code Online (Sandbox Code Playgroud)
现在有什么想法暂时禁用它吗?我有表单,我想编辑各种语言版本,并且使用后备我得到默认语言的字段,如果给定的翻译还没有.
ruby-on-rails internationalization globalize2 ruby-on-rails-3
我想在验证消息中看不到有效值.
validates_uniqueness_of :event, :scope => :user_id
Run Code Online (Sandbox Code Playgroud)
结果:"已经采取了标题"我想:"#{user}已经采取了#{event}事件"
我正在尝试这样做,发髻不工作:
validates_uniqueness_of :event, :scope => :user_id, :message=>"#{self.event} already has been taken by #{self.user}"
Run Code Online (Sandbox Code Playgroud) 我在一个表单中使用它对一个对象进行了简单的活动记录验证:
form.error_messages({:message => '', :header_message => ''})
Run Code Online (Sandbox Code Playgroud)
这反过来输出类似"FieldName我的自定义消息"的内容
我需要做的是从错误消息中删除字段名称,但保留我的自定义消息.
任何人都可以指出我正确的方向.
我正在为只能通过REST调用访问的Steam游戏编写Rails后端API,因此不需要特定于用户的身份验证.我正在尝试为Authlogic gem 实现authlogic_api插件,该插件使用api_key/signature机制来限制访问.我已经实现了rdocs中概述的ApplicationSession和ApplicationAccount模型,但我不确定如何修改我的ApplicationController以限制访问.
查看源代码,authlogic_api插件似乎修改了Authlogic中的ActsAsAuthentic和Session模块.但由于这实际上是"单一访问"身份验证,要求在每次请求时传递API密钥和签名,我不会看到会话如何成为一个因素.
有没有人在他们的应用程序中成功实现了authlogic_api?如果是这样,您会分享设置ApplicationController的方法吗?
我升级到RoR 3.0.1和Ruby升级到1.9.2. 现在我视图中的所有字符串都是ASCII-8BIT?
我相信我的应用程序设置为使用UTF 8
application.rb中
config.encoding = "utf-8"
Run Code Online (Sandbox Code Playgroud)
database.yml的
development:
adapter: mysql
encoding: utf8
Run Code Online (Sandbox Code Playgroud)
我在跑
OS X
RVM rvm 1.0.16
Ruby ruby-1.9.2-p0
Rails 3.0.1
Run Code Online (Sandbox Code Playgroud)
我希望编码是UTF 8而不是ASCII
business.desc.encoding
# ASCII-8BIT
Run Code Online (Sandbox Code Playgroud)
由于1.9.x可以连接不同编码的字符串,我们会看到很多这样的错误.
<p class="description"><%= truncate(business.desc, :length => 17) %></p>
Run Code Online (Sandbox Code Playgroud)
错误
incompatible character encodings: ASCII-8BIT and UTF-8
activesupport (3.0.1) lib/active_support/core_ext/string/output_safety.rb:74:in `concat'
activesupport (3.0.1) lib/active_support/core_ext/string/output_safety.rb:74:in `concat'
actionpack (3.0.1) lib/action_view/template/handlers/erb.rb:14:in `<<'
app/views/browse/businesses.html.erb:15:in `block in _app_views_browse_businesses_html_erb___1616718260917998189_2173630500__1134905695726531092'
app/views/browse/businesses.html.erb:3:in `each'
app/views/browse/businesses.html.erb:3:in `each_with_index'
app/views/browse/businesses.html.erb:3:in `_app_views_browse_businesses_html_erb___1616718260917998189_2173630500__1134905695726531092'
Run Code Online (Sandbox Code Playgroud)
还有其他人有这个问题吗?ruby-1.9.2-p0是否使用正确的版本?
谢谢!
我与Handelbars的backbone.js应用程序执行以下操作.
代码如下.
(function ($)
{
// model for each article
var Article = Backbone.Model.extend({});
// collection for articles
var ArticleCollection = Backbone.Collection.extend({
model: Article
});
// view for listing articles
var ArticleListView = Backbone.View.extend({
el: $('#main'),
render: function(){
var js = JSON.parse(JSON.stringify(this.model.toJSON()));
var template = Handlebars.compile($("#articles_hb").html());
$(this.el).html(template(js[0]));
return this;
}
});
// main app
var ArticleApp = Backbone.Router.extend({
_index: null,
_articles: null,
// setup routes
routes: {
"" : "index"
},
index: function() {
this._index.render();
},
initialize: function() …Run Code Online (Sandbox Code Playgroud) ruby ×5
actionview ×1
activerecord ×1
authlogic ×1
backbone.js ×1
css ×1
field ×1
globalize2 ×1
helpers ×1
javascript ×1
model ×1
rest ×1
rubinius ×1
ruby-1.9 ×1
security ×1
validation ×1