我收到错误:
<NoMethodError: undefined method `read_attribute_for_serialization' for #<Record::ActiveRecord_Relation:0x007faa7cfe3318>>
Run Code Online (Sandbox Code Playgroud)
该错误位于代码段的第三行.
def artist
@records = Record.where('artist_id = ' + params[:artist_id])
render :json => @records, serializer: RecordSummarySerializer
end
Run Code Online (Sandbox Code Playgroud)
这是控制器RecordsContrller的备用序列化程序.另一个,'RecordsSerializer,工作正常.
对此错误的搜索提出了一些解决方案.有些人不清楚添加代码的位置.另一位建议补充:
alias :read_attribute_for_serialization :send
Run Code Online (Sandbox Code Playgroud)
到发生错误的类.它对我不起作用.我还查看了gem文档.我找到了使用序列化器的一个例子:很明显,任何其他代码都是必需的.
我正在使用Ruby 2.3.0和Rails 5.0.0.
class RecordsController < ApplicationController
...
def index
@records = Record.order('title')
render :json => @records
end
def artist
@records = Record.where('artist_id = ' + params[:artist_id])
render :json => @records, serializer: RecordSummarySerializer
end
...
end
Run Code Online (Sandbox Code Playgroud)
class Record < ActiveRecord::Base
belongs_to :artist
belongs_to :label
belongs_to :style
has_many :tracks …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用bundle install将gem安装到我的新Ruby项目中.我在OS X 10.8.4框中使用rbenv设置了Ruby版本.我收到以下错误:
An error occurred while installing atomic (1.1.13), and Bundler cannot continue.
Make sure that `gem install atomic -v '1.1.13'` succeeds before bundling.
Kikime:jazzcatalog curt$ gem install atomic
Building native extensions. This could take a while...
Successfully installed atomic-1.1.13
1 gem installed
Kikime:jazzcatalog curt$ rbenv rehash
Kikime:jazzcatalog curt$ bundle install
Fetching gem metadata from https://rubygems.org/.........
Fetching gem metadata from https://rubygems.org/..
Using rake (10.1.0)
Using i18n (0.6.5)
Using minitest (4.7.5)
Using multi_json (1.7.9)
Installing atomic (1.1.13)
Gem::Installer::ExtensionBuildError: ERROR: …Run Code Online (Sandbox Code Playgroud) 加载网页时,我收到Phusion发出的以下错误:
There was an error while trying to load the gem 'compass-rails'.
Gem Load Error is: undefined method `has?' for Sass::Util:Module
Did you mean? hash
Hash
Backtrace for gem load error is:
/Volumes/Data/htdocs/zetcho/vendor/bundle/gems/compass-0.12.2/lib/compass/sass_extensions/functions/urls.rb:5:in `has?'
Run Code Online (Sandbox Code Playgroud)
指定位置的代码是:
module Compass::SassExtensions::Functions::Urls
def self.has?(base, instance_method)
Sass::Util.has?(:instance_method, base, instance_method)
end
Run Code Online (Sandbox Code Playgroud)
我的gem文件包含:
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.1.2'
# Use mysql as the database for Active Record
gem 'mysql2', '~> 0.3.18'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0' …Run Code Online (Sandbox Code Playgroud) 我正在使用 css column-count 功能将我的部分分成两列。在一个页面上,我在第一列的底部有一个 h3 标题,在下一列的顶部有下面的 p 段落。我想保留段落的前几句话的标题。我可以将它与整个段落一起包装在一个带有内联块样式的 div 中。这适用于短段落,但不适用于长段落。我也可以随意拆分段落,但如果在标题之前添加了额外的内容,我可能不得不将其重新组合在一起,迫使它进入下一列。如果不可能,因为列数是新的,我不会感到惊讶。
更新
根据下面@Jon 的建议,我尝试从网上找到的示例中闯入,因为我知道了关键字。
CSS:
.heading-with-text {
-webkit-column-break-inside: avoid;
-moz-column-break-inside: avoid;
break-inside: avoid;
}
Run Code Online (Sandbox Code Playgroud)
HTML:
<section class="heading-with-text">
<h3>Blah, Blah</h3>
<p>woof, woof</p>
</section>
Run Code Online (Sandbox Code Playgroud)
在 OS X 平台上,它在 Firefox 24.0 中根本不起作用。在 Safari 6.0.5 和 Chrome 30.0.1599.66 中,它将标题移动到下一列,使其位于文本上方。但是,无论我在段落中添加多少文本,浏览器都不会在段落中打断。它就像内联块一样工作。我猜他们把“避免”理解为不惜一切代价避免。这种方法似乎是正确的方法。只是目前没有得到很好的支持。
在我的一种观点中,我将模态对话框称为:
let application = NSApplication.shared()
application.runModal(for: artistDialogWindow)
Run Code Online (Sandbox Code Playgroud)
当按下“确定”或“取消”按钮时,我将终止模式窗口,如下所示:
let application = NSApplication.shared()
application.stopModal()
Run Code Online (Sandbox Code Playgroud)
调用该对话框的视图重新获得控制权。运行代码后,它退出。在屏幕上,似乎没有窗口具有焦点。如果我单击窗口的标题栏,标题栏左侧的红色、橙色和绿色按钮就会从灰色变为彩色。我怎样才能以编程方式做到这一点?
我尝试过 NSApplication.activate。它没有任何作用。想必我的应用程序已经处于活动状态。它只是没有焦点。我还尝试在视图中的表中选择一行。该行被选中,但窗口未被选中。
我有一个提供MySQL日期的Rails服务器。我的课程是基于AngularDart教程设置的。它似乎无法正确加载。
我的artist_service。飞镖方法:
Future<List<Record>> getArtistsRecords(int id) async {
String url = 'http://catbox.loc/artists/${id.toString()}/records'; // Rails: artists/:id/records
try {
HttpRequest response = await HttpRequest.request(
url, requestHeaders: headers);
List data = JSON.decode(response.responseText);
final records = data
.map((value) => new Record.fromJson(value))
.toList();
return records;
}
catch (e) {
throw _handleError(e);
}
}
Run Code Online (Sandbox Code Playgroud)
我的artist.dart工厂方法:
factory Record.fromJson(Map<String, dynamic> record) =>
new Record(_toInt(record['id']),
record['title'],
record['catalog'],
record['artist_id'],
record['label_id'],
record['style_id'],
record['alternate_catalog'],
record['recording_date'],
record['notes'],
record['penguin'],
record['category']
);
Run Code Online (Sandbox Code Playgroud)
令人反感的元素是recording_date,它声明为DateTime。当我在HTML中包括作为{{recording_date}}我得到1958-03-09的例子。如果我尝试,{{ recording_date | date}}它会以无效格式错误显示。我怀疑我没有 …
升级到 High Sierra 后,我的本地网站访问失败,就像每次升级后一样。这次我以为我已经掌握了它,因为我将所有更改都放入了 /other/overides.conf 中。还是没用。我终于能够通过删除 Listen 80 出现的每个地方来修复它。这个新代码附带了最新的 httpd.conf
<IfDefine SERVER_APP_HAS_DEFAULT_PORTS>
Listen 8080
</IfDefine>
<IfDefine !SERVER_APP_HAS_DEFAULT_PORTS>
Listen 80
</IfDefine>
Run Code Online (Sandbox Code Playgroud)
显然,这一变化与 Apache 的新版本有关。更改的原因是什么?我是否正确修复了它?