我的 User 模型有一个多态关系。我正在使用设计。
当我尝试编辑用户的详细信息时,出现以下错误:
undefined method `primary_key' for ActiveSupport::HashWithIndifferentAccess:Class
Run Code Online (Sandbox Code Playgroud)
通过表单提交的数据为:
{"utf8"=>"?",
"_method"=>"put",
"authenticity_token"=>"Ap0JP2bs/w9J6iI9rZahiKR1K8UEIi7rp33a4OutMbo=",
"user"=>{"email"=>"some_email@yahoo.com",
"rolable"=>{"first_name"=>"Cristian",
"last_name"=>"Gavrila",
"city"=>"16"}},
"commit"=>"Update"}
Run Code Online (Sandbox Code Playgroud)
控制器方法是:
def update
@user = User.find(current_user.id)
if @user.update_attributes(params[:user])
redirect_to edit_user_registration_path, notice: 'Your profile was successfully updated.'
else
redirect_to edit_user_registration_path, error: "Something went wrong, couldn't update your profile!."
end
end
Run Code Online (Sandbox Code Playgroud)
型号:
1. 用户
class User < ActiveRecord::Base
belongs_to :rolable, :polymorphic => true
# Devise business
devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :remote_avatar_url, …Run Code Online (Sandbox Code Playgroud) 我正在尝试启动一个模拟 HTTP 服务器进行测试,但我无法让 Wiremock 工作。
网站上mvnrepository.com是这样建议的:
<!-- https://mvnrepository.com/artifact/com.github.tomakehurst/wiremock -->
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId>
<version>2.9.0</version>
<type>pom</type>
<scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
然而,当尝试像这样导入它时,这并不使它可用于我的测试类:
import static com.github.tomakehurst.wiremock.client.WireMock.*;
Run Code Online (Sandbox Code Playgroud)
如果删除该<type>pom</type>标签,我可以导入它,但它会在运行时失败,因为它没有引入它需要的所有传递依赖项(例如 Apache Httpclient)。
我不太确定是<type>pom</type>什么,因为从其他解释中还不清楚,所以我不知道如何克服这个问题。
完整的 Maven 配置:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>-----</groupId>
<artifactId>---------</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>-----------</name>
<description>----------</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.rabbitmq</groupId>
<artifactId>amqp-client</artifactId>
<version>4.0.2</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
<type>jar</type> …Run Code Online (Sandbox Code Playgroud) 我有一个选定的公司列表,如下所示:
<div id="selected_companies">
<div class="company">
<a>
<div class="delete_company"></div>
Company One
</a>
</div>
<div class="company">
<a>
<div class="delete_company"></div>
Company Two
</a>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我希望在点击其中一家公司时将每个.companydiv "移动" 到一个单独的#deleted_companiesdiv中.我用jQuery做这个:
$('#selected_companies .company a').on('click', function (e) {
/* Getting the company */
var company_id = $(this).prev().prop('value');
$('.form').append('<input type="hidden" name="deleted_companies[]" value="'+ company_id +'" />');
var parent = $(this).parent();
parent.appendTo('#deleted_companies');
$('#deleted_companies').slideDown(300);
});
Run Code Online (Sandbox Code Playgroud)
当我点击其中一个公司时,.companydiv移动到所需的div(#deleted_companies),但是当我尝试在该div中达到它时,它没有按预期执行.例如,此代码不起作用:
$('#deleted_companies .company a').on('click', function (e) {
alert('This should work.');
});
Run Code Online (Sandbox Code Playgroud)
那么如何使该警报工作?
javascript jquery dom-manipulation jquery-selectors jquery-events
我有一个几十万行的文件,看起来像这样:
01,T,None,Red,Big
02,F,None,Purple,Small
03,T,None,Blue,Big
.......
Run Code Online (Sandbox Code Playgroud)
我想要从整个文件中检索第n列的东西.例如,第4列将是:
Red
Purple
Blue
Run Code Online (Sandbox Code Playgroud)
由于文件非常大,我有兴趣了解最有效的方法.
显而易见的解决方案是逐行浏览文件,然后应用split(',')并获取数组中的第4项,但我想知道是否有更好的东西.
我想在这里运行第一个例子,但是我收到了这个错误.我正在使用Ubuntu 13.10.
Failed to load OpenCL runtime
OpenCV Error: Unknown error code -220 (OpenCL function is not available: [clGetPlatformIDs]) in opencl_check_fn, file /home/cristi/opencv/modules/core/src/opencl/runtime/opencl_core.cpp, line 204
OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /home/cristi/opencv/modules/imgproc/src/color.cpp, line 3159
Traceback (most recent call last):
File "/home/cristi/opencv1/src/video.py", line 11, in <module>
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.error: /home/cristi/opencv/modules/imgproc/src/color.cpp:3159: error: (-215) scn == 3 || scn == 4 in function cvtColor
Process finished with exit code 1
Run Code Online (Sandbox Code Playgroud)
此外,这是引起麻烦的行(我的代码中的第11行): …
我使用的是Rails 3.2和Ruby 1.9.3.
我知道这已被一次又一次地问过,但我找不到任何关于我的特殊情况,即使它确实是一些非常愚蠢的东西,我也无法弄明白.
我的关系是这样的:一个产品有很多类别,一个类别有很多属性.
我想在我的视图中创建一个嵌套的表单,所以我正在使用
= f.fields_for :categories do |category|
= render 'category_fields', :f => category
Run Code Online (Sandbox Code Playgroud)
为了将类别字段"附加"到产品表单中.
问题是,当它将其转换为HTML时,类别输入的名称是"categories_attributes",如下所示:
<label for="product_categories_attributes_0_name">Name</label>
<input id="product_categories_attributes_0_name" type="text" size="30" name="product[categories_attributes][0][name]">
Run Code Online (Sandbox Code Playgroud)
我是rails的新手,但我想它应该是product[categories][0][name]而不是categories_attributes.
提交表格后,我明白了
Can't mass-assign protected attributes: categories_attributes
Run Code Online (Sandbox Code Playgroud)
另外,我的模特:
class Product < ActiveRecord::Base
belongs_to :company
belongs_to :product_type
has_many :categories, :dependent => :destroy
accepts_nested_attributes_for :categories
attr_accessible :comments, :name, :price
end
class Category < ActiveRecord::Base
belongs_to :product
has_many :attributes, :dependent => :destroy
attr_accessible :name
accepts_nested_attributes_for :attributes
end
class Attribute < ActiveRecord::Base
belongs_to :category …Run Code Online (Sandbox Code Playgroud) 我对Haskell很新.所以这可能有点傻.
我想要的是做一些像:
map (\x -> x + **position in list**) [0, 0, 0] => [1, 2, 3]
Run Code Online (Sandbox Code Playgroud)
如何才能做到这一点?
我使用的是Ruby 1.9.3.
这是控制台中发生的事情:
1.9.3-p392 :028 > p = Product.find(1)
Product Load (0.4ms) SELECT `products`.* FROM `products` WHERE `products`.`id` = 1 LIMIT 1
=> #<Product id: 1, name: "Product 4", image: nil, available: true>
1.9.3-p392 :029 > p.image
=>
1.9.3-p392 :030 > p.image.nil?
=> false
Run Code Online (Sandbox Code Playgroud)
返回产品时,图像显然为零,但是当我尝试获取值(p.image)时,它没有显示任何内容.
为什么p.image.nil?命令没有返回true?
我有一个RDFS本体,有两个完全独立的类:User和Venue.我希望它们都具有通过被称为属性提供的名称hasName,对于a User应该看起来类似于:
<rdf:Property rdf:ID="hasName">
<rdfs:comment>
Comment here. Blah blah blah.
</rdfs:comment>
<rdfs:domain rdf:resource="#user"/>
<rdfs:range rdf:resource="Literal"/>
</rdf:Property>
Run Code Online (Sandbox Code Playgroud)
但是,如果我也想要它Venue,它不会验证.
我该怎么做呢?
有没有办法在moment.js 中轻松正确地解析这样的链接?
August 21, 2015: 11:40 AM ET
Run Code Online (Sandbox Code Playgroud)
除了ET以下格式的位(代表东部时间,它是 UTC-4)之外,我设法正确解析了它:
MMMM DD, YYYY: hh:mm tt ET
Run Code Online (Sandbox Code Playgroud)