草庐IT

9-bit-serial

全部标签

ruby-on-rails - rails 3.2 : Replace null values with empty string from json serialization

我正在使用Rails3.2serialization将ruby​​对象转换为json。例如,我已经将ruby​​对象序列化为以下json{"relationship":{"type":"relationship","id":null,"followed_id":null}}在我的类RelationshipActiveRecord::Base中使用以下序列化方法defas_json(opts={}){:type=>'relationship',:id=>id,:followed_id=>followed_id}end我需要用空字符串替换空值,即空双引号,以响应json。我怎样才能做到这一

ruby-on-rails - JSONAPI 资源 : serialize a namespaced model

我正在尝试使用JSONAPIResources在Rails引擎中,我定义了DokiCore::Tenant(模型)在doki_core/app/models/tenant.rb和DokiCore::TenantResource在doki_core/app/resources/tenant_resource.rb中。当我尝试序列化为哈希时,遇到以下错误:NoMethodError:undefinedmethodtenant_path'for#from/Users/typeoneerror/.rvm/gems/ruby-2.2.2@doki/gems/jsonapi-resources-0

ruby-on-rails - 在 Rails 中使用 ActiveModel::Serializer - JSON 数据在 json 和索引响应之间不同

我正在使用active_model_serializersgem来控制序列化数据,并看到一些奇怪的行为。我的代码如下所示:模型和序列化器classUserincludeMongoid::Documentfield:first_name,:type=>Stringfield:last_name,:type=>Stringdeffull_namefirst_name+""+last_nameendendclassUserSerializerControllerclassUsersControllerView(app/views/users/index.html.erb)...$(funct

ruby-on-rails - "You are trying to cache a Ruby object which cannot be serialized to memcached."

我在多个站点共享的页脚中遇到了一些缓存问题,我想知道可能是什么原因。这是错误消息和回溯:Cacheread:remote_footer_information({:expires_in=>300seconds})Cachegenerate:remote_footer_information({:expires_in=>300seconds})Cachewrite:remote_footer_information({:expires_in=>300seconds})Marshallingerrorforkey'remote_footer_information':no_dump_dat

ruby-on-rails - 编码::UndefinedConversionError: "\xA8"从 ASCII-8BIT 到 UTF-8 (SFTP)

使用Net-SFTPgem、Ruby2和Rails4我编写的代码在纯ruby​​中运行,但将我的代码复制到rails上,现在我得到:Encoding::UndefinedConversionError:"\xA8"fromASCII-8BITtoUTF-8我可以在我的代码中更改什么以使其正常工作?defself.get_recent_file(ftp_file,local_file)Net::SFTP.start(Config::A_FTP[:domain],Config::A_FTP[:username],:password=>Config::A_FTP[:password])do|

ruby-on-rails - 当我需要 UTF-8 时,Rails 应用程序一直以 ASCII-8BIT 生成 View ?

我正在尝试使我的Rails应用程序成为本地UTF-8。我这样做是因为自升级到Ruby1.9以来,我遇到了这个问题,每次我的网页必须显示一些UTF-8字符时,我得到:incompatiblecharacterencodings:UTF-8andASCII-8BIT作为错误页面。我已经诊断出当我尝试呈现任何UTF-8文本时会出现错误,因为这种网页会失败:%h3.book_title="カタカナ"(要求对上述字符串进行编码将返回UTF-8)然而这个会成功:%h3.book_title="カタカナ".force_encoding("ASCII-8BIT")所以看起来Rails决定在默认情况下使

ruby-on-rails - ActiveRecord::Serializer 中的条件侧载数据(基于 Controller 操作)

我在Rails和构建应用程序方面没有太多经验。我尝试使用ActiveModel::Serializers构建API。为特定事件操作有条件地加载数据的最佳方法是什么?我是否必须通过在每次调用时发送查询参数来做到这一点,或者我可以设置includes:trueonlyforspecificactionoranyothersuggestion?classEventsController[:index,:show]before_filter:locate_collection,:only=>:indexskip_before_filter:verify_authenticity_token,:

ruby-on-rails - 'Encoding::UndefinedConversionError "\xE9"from ASCII-8BIT to UTF-8' 当使用一些在 ruby​​ on rails 中使用 file.open 的 ruby​​ gem 时

我想要什么?我想在Rails3.2中从模板文件生成.docx文件或.odt文件我想在其中使用日语。在ubuntu服务器12.04&ruby​​1.9.3p194&rails3.2.8发生了什么?我尝试了gems'docx-templater'和'serenity'ruby-docx-模板https://github.com/jawspeak/ruby-docx-templater1个sample效果不错2尝试在我的Rails应用程序中做同样的事情在Controller中作为示例defgen_docxinput_file='./app/template/ExampleTemplate.d

ruby-on-rails - ruby rails : serialize Hash incredibly slow

我有一个名为“搜索”的简单模型,用于存储搜索。它捕获URL参数并将它们存储在属性:search_criteria中,该属性被序列化为哈希:serialize:search_criteria,Hash这一切都完美无缺,但表现却很糟糕。对于仅5个对象,以下语句大约需要0.2秒。start=Time.nowSavedSearch.all.map(&:search_criteria)putsTime.now-start但是,如果我删除序列化行(这样search_criteria返回一个字符串),语句只需要0.002秒。这是反序列化哈希的2个数量级的差异!!这里发生了什么?Rails.versi

ruby-on-rails - 发生 fatal error 。请参阅位于 http ://bit. ly/bundler-issues 的 Bundler 故障排除文档

当我进行捆绑安装时,出现以下异常。这是什么?rajesh@rajesh:~/workspace/Cybermedia_Test$bundleinstallFetchinggemmetadatafromhttp://rubygems.org/.Unfortunately,afatalerrorhasoccurred.PleaseseetheBundlertroubleshootingdocumentationathttp://bit.ly/bundler-issues.Thanks!/home/rajesh/.rvm/gems/ruby-1.9.3-p385@global/gems/bu