我postgresql-9.2.4
从源代码安装,现在在执行时使用rails app:
rake db:create
命令我得到:
$ bin/rake db:create RAILS_ENV="test"
PG::Error: ERROR: new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII)
HINT: Use the same encoding as in the template database, or use template0 as template.
: CREATE DATABASE "verticals_test" ENCODING = 'unicode'
/home/vagrant/my-project/.gems/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/postgresql_adapter.rb:652:in `exec
....
bin/rake:16:in `load'
bin/rake:16:in `<main>'
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "database"=>"my_db", "host"=>"localhost", "pool"=>5, "username"=>"my_user", "password"=>"my_password"}
Run Code Online (Sandbox Code Playgroud)
任何的想法?
有没有办法告诉curl命令不要使用服务器端缓存?例如; 我有这个curl命令:
curl -v www.example.com
我怎么能请求curl发送一个不使用缓存的新请求?
注意:我在终端中寻找可执行命令.
删除文件扩展名的最短方法是什么?这是我试过的:
file = "/home/usr/my_file.xml"
file = File.basename(file)
file.slice! File.extname(file) #=> my_file
Run Code Online (Sandbox Code Playgroud) 我Client
通过以下方法获取IP地址:
public static String getClientIpAddr(HttpServletRequest request) {
String ip = request.getHeader("X-Forwarded-For");
...
return ip
}
Run Code Online (Sandbox Code Playgroud)
现在我想检测它是一个IPV4
还是一个IPV6
.
我正在尝试解析json
文件:
{"units":[{"id":42,
"title":"Hello World",
"position":1,
"v_id":9,
"sites":[[{"id":316,
"article":42,
"clip":133904
}],
{"length":5}]
}, ..]}
Run Code Online (Sandbox Code Playgroud)
这是我尝试过的:
Object obj = null;
JSONParser parser = new JSONParser();
Object unitsObj = parser.parse(new FileReader("file.json");
JSONObject unitsJson = (JSONObject) unitsObj;
JSONArray units = (JSONArray) unitsJson.get("units");
Iterator<String> unitsIterator = units.iterator();
while(unitsIterator.hasNext()){
Object uJson = unitsIterator.next();
JSONObject uj = (JSONObject) uJson;
obj = parser.parse(uj.get("sites").toString());
JSONArray jsonSites = (JSONArray) obj;
for(int i=0;i<jsonSites.size();i++){
JSONObject site = (JSONObject)jsonSites.get(i); // Exception happens here.
System.out.println(site.get("article");
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试解析内部时json array
,代码不起作用,所以我得到:
Exception …
Run Code Online (Sandbox Code Playgroud) 为什么在下面的代码片段foo取代了它的定义?
def foo
def foo
1
end
end
Run Code Online (Sandbox Code Playgroud)
这是第一次foo
没有
foo
=> nil
foo.foo
=> 1
Run Code Online (Sandbox Code Playgroud)
现在,如果我foo
再次打电话:
foo
=> 1
Run Code Online (Sandbox Code Playgroud)
你可以看到foo
不再是零了.谁可以给我解释一下这个?谢谢.
我有一个file.dat
在src/main/resources
.
当我尝试通过jar文件测试加载此文件的类时,测试失败,因为它无法在path(I/O Exception
)中找到该文件.我通过测试获得的路径是:
/home/usr/workspace/project/target/test-classes/file.dat
但文件不存在于target/test-classes
任何想法?
我已经variables
在我的jsp
页面中声明了一些taglib,如下所示:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<c:set var="site" scope="session" value="${site}"/>
<c:set var="thumb" scope="session" value="${thumbnail}"/>
<c:set var="geoCode" scope="session" value="${geoCode}"/>
...
<fmt:setLocale value="${local}" />
<fmt:setBundle basename="MessagesBundle" />
<!DOCTYPE html>
<head>
<meta charset="utf-8">
...
Run Code Online (Sandbox Code Playgroud)
当我运行应用程序然后查看源代码时,我在源页面顶部看到空白的新行:
.
<!DOCTYPE html>
<head>
<meta charset="utf-8">
Run Code Online (Sandbox Code Playgroud)
我只是放了一个dot
来展示空行.关于如何删除这些空行的任何想法?
我在pom.xml
文件中添加了以下依赖项:
<dependency>
<groupId>org.tuckey</groupId>
<artifactId>urlrewritefilter</artifactId>
<version>4.0.4</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我有很多maven依赖项,但当我添加上面的一个时,我得到:
Failed to read artifact descriptor for org.tuckey:urlrewritefilter:jar:4.0.4: Could not transfer artifact org.tuckey:urlrewritefilter:pom:4.0.4 from/to central (http://app1.stage.server.net/artifactory/libs-release): Not authorized, ReasonPhrase:Unauthorized. -> [Help 1]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
Run Code Online (Sandbox Code Playgroud)
这是settings.xml
文件的外观:
..
<servers>
<server>
<username>user</username>
<id>central</id>
<password>my-password</password>
</server>
<server>
<username>user</username>
<id>snapshots</id>
<password>my-password</password>
</server>
</servers>
<profiles>
...
</profiles>
<activeProfiles>
<activeProfile>artifactory</activeProfile>
</activeProfiles>
..
Run Code Online (Sandbox Code Playgroud)
任何帮助?TNX.
在下面的代码中,方法roar
没有在类中定义Lion
,但仍然可以使用method_missing
.
class Lion
def method_missing(name, *args)
puts "Lion will #{name}: #{args[0]}"
end
end
lion = Lion.new
lion.roar("ROAR!!!") # => Lion will roar: ROAR!!!
Run Code Online (Sandbox Code Playgroud)
在哪些情况下我应该如何使用它method_missing
?使用安全吗?