小编lea*_*ner的帖子

Welcome#index中的ExecJS :: ProgramError TypeError:Object不支持此属性或方法

我是Ruby on Rails的新手,我很难在Windows 8机器上安装该软件.现在我只是按照本指南创建示例Hello World示例.

当我尝试按照4.3设置应用程序主页中给出的步骤进行操作时,我开始面临问题.

这是我做的:

1)在编辑器中打开文件config/routes.rb.

2)取消注释该行 root 'welcome#index'

3)重启服务器.

现在,当我访问URL时,localhost:3000我开始在浏览器上收到以下错误:

ExecJS::ProgramError in Welcome#index 

 Showing E:/Rails/blog/app/views/layouts/application.html.erb where line #6 raised:

TypeError: Object doesn't support this property or method
  (in C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/turbolinks-2.5.3/lib/assets/javascripts/turbolinks.js.coffee)

Extracted source (around line #6):
<head>
<title>Blog</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
<body>

Rails.root: E:/Rails/blog
Run Code Online (Sandbox Code Playgroud)

你能告诉我为什么我会遇到这个问题吗?

还在使用Ruby On Rails开发应用程序是非常的?因为我尝试已经有2天了,但在我看到Hello World示例之前,我遇到了很多问题.我已经研究过基于Java的框架,但我从未在安装或创建基本应用程序时遇到太多困难.

ruby windows ruby-on-rails

7
推荐指数
1
解决办法
9446
查看次数

与Statement相比,使用Preparedstatement是否有任何缺点

我正想通过JDBC Statement和PreparedStatement之间的差异,看到如此多的优势在这里,并在这里与报表比较的PreparedStatement.

我的一些同事问我们为什么仍然需要Statement以及为什么不考虑PreparedStatement的优点而弃用它.

那么我们还有什么理由在JDBC API中使用Statement吗?

java jdbc prepared-statement

7
推荐指数
1
解决办法
1362
查看次数

从数组的子数组中计算数组中所有可能的和

我有一个数字数组,现在我必须通过生成给定数组的所有可能的子数组并应用一些条件来查找元素之和。

\n

条件是对每个子数组获取minimum并在其中找到total of elements并将两者相乘(minimum * total)。最后,add所有子数组的所有这些相乘值。

\n

这是问题陈述:

\n

使用以下公式查找所有可能子数组的总和:

\n
\n

Sum(left, right) = (min of arr[i]) * (\xe2\x88\x91 arr[i]),其中 i 的范围从左到右。

\n
\n

例子:

\n
Array = [2,3,2,1]\n
Run Code Online (Sandbox Code Playgroud)\n

子数组是:[start_index, end_index]

\n
 [0,0] subarray = [2], min is 2 and total of items = 2. min * total = 2*2=4\n [0,1] subarray = [2,3], min is 2 and total of items = 5. min * total = 2*5=10\n [0,2] …
Run Code Online (Sandbox Code Playgroud)

java algorithm

7
推荐指数
2
解决办法
2866
查看次数

Hibernate throws无法删除或更新父行:外键约束失败

我正在研究一个测试cascade delete操作的基本示例,但我得到了例外.

我有以下实体:

Employee.java

@Entity
public class Employee {
    @Id
    @Column(name = "EMP_ID")
    private long id;

    private String name;

    @OneToMany(mappedBy = "employee")
    @Cascade(value = { CascadeType.REMOVE, CascadeType.SAVE_UPDATE })
    private List<EmpDetails> details = new ArrayList<EmpDetails>();

}
Run Code Online (Sandbox Code Playgroud)

EmpDetails.java

@Entity
public class EmpDetails {
    @Id
    private long id;
    private int info;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "EMP_ID")
    private Employee employee;
}
Run Code Online (Sandbox Code Playgroud)

现在我在数据库中有员工ID为10的记录以及员工详细信息表中的相应记录.

现在当我运行以下查询时:

    session.beginTransaction();

    session.delete(new Employee(10)); // here 10 is the ID of the employee

    session.getTransaction().commit();
    session.close();
Run Code Online (Sandbox Code Playgroud)

我认为hibernate将删除员工记录和相应的员工详细信息记录,因为我已设置要删除的级联类型.但我得到例外:

引起:com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException:无法删除或更新父行:外键约束失败

有人可以帮我在这里测试级联删除选项吗?

java mysql hibernate

6
推荐指数
1
解决办法
2万
查看次数

Gem :: RemoteFetcher :: FetchError:SSL_connect返回= 1 errno = 0 state = SSLv3 read

我正在尝试在rails上安装ruby,但是当我尝试创建应用程序时,我仍然遇到很多错误.

这是我在Windows机器上所做的:

1)下载的railsinstaller-3.0.0.exe软件2)在我的机器上安装了Rails.3)验证安装是否成功:

E:\ Rails> ruby​​ -v ruby​​ 2.0.0p598(2014-11-13)[i386-mingw32]

E:\ Rails> sqlite3 --version 3.8.7.2 2014-11-18 20:57:56 2ab564bf9655b7c7b97ab85cafc8a48329b27f93

E:\ Rails> rails -v DL已弃用,请使用Fiddle Rails 4.1.8

现在,当我尝试创建一个应用程序时,我遇到异常:

使用的命令是: rails new blog

         run  bundle install
DL is deprecated, please use Fiddle
Fetching gem metadata from https://rubygems.org/...........
Fetching additional metadata from https://rubygems.org/..
Resolving dependencies...

Gem::RemoteFetcher::FetchError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (https://rubygems.org/gems/rake-10.4.2.gem)
An error occurred while installing rake (10.4.2), and Bundler cannot continue.
Make sure that `gem …
Run Code Online (Sandbox Code Playgroud)

ruby windows ruby-on-rails

5
推荐指数
1
解决办法
6468
查看次数

Regular expression ^\\Q &amp; \\E

I have below code in my application:

private String getRequestPath(HttpServletRequest req) {
        String path = req.getRequestURI();
        path = path.replaceFirst( "^\\Q" + req.getContextPath() + "\\E", "");
        path = URLDecoder.decode(path);
        System.out.println("req.getRequestURI()="+req.getRequestURI());
        System.out.println("path="+path);
        return path;
    }
Run Code Online (Sandbox Code Playgroud)

In the output I can see below messages when I try to access the servlet which this method belongs to:

req.getRequestURI()=/MyApp/test
path=/test
Run Code Online (Sandbox Code Playgroud)

How the ^\\Q & \\E works in regular expressions.

java regex

5
推荐指数
1
解决办法
8564
查看次数

如何在unix中搜索特定文件中的文本

我正在使用Ubuntu机器并尝试使用以下命令来搜索文本:

此命令以递归方式检查给定目录中是否存在该单词:

1)<hello>是我搜索的单词,它在从当前目录开始的所有文件中递归搜索.它工作正常.

grep -r "<hello>" .

2)现在我想将搜索限制为仅限于特定文件,xml仅限于文件:

grep --include=\*.{java} -rnw '/home/myfolder/' -e "<hello>"
Run Code Online (Sandbox Code Playgroud)

这次命令花费更多时间,最后没有给出任何结果.但我的文件有内容.

我已经浏览了这个链接 - 如何在Linux上找到包含特定文本的所有文件?写我的第二个命令.

我的第二个命令有问题吗?还有一个执行速度快的备用命令吗?

unix grep

5
推荐指数
1
解决办法
3万
查看次数

获取图中行驶的最长路线

我有一个相互连接的节点数组

我有下面的节点网络。这里以0为起点,我想尽可能多地移动节点,而一个节点仅移动一次。同样,在从0到目标节点的行程中,我只希望有一个奇数编号的节点(例如1、3、5、7)。现在,我需要找出从起始位置0开始可以走的最长路线。

范例:

int[] array = { 0, 9, 0, 2, 6, 8, 0, 8, 3, 0 };
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

在上图中,以下是可能性:

0 -> 6 -> 4 (valid path, length = 3 nodes)
0 -> 9 -> 1 (Not valid path, length as we have 2 odd numbers here 1 & 9)
0 -> 2 -> 3 -> 8 (valid path, length = 4 nodes)
0 -> 2 -> 3 -> 8 -> 5 (Not valid path as we have 2 odd numbers …
Run Code Online (Sandbox Code Playgroud)

java algorithm tree graph graph-algorithm

5
推荐指数
2
解决办法
311
查看次数

在数字数组中查找重复的数字

在采访中有人问我这个问题,给出一个数字列表,只返回输入中存在的重复项作为排序的输出。

例:

Input = [6, 7, 5, 6, 1, 0, 1, 0, 5, 3, 2]
Output = [0, 1, 5, 6] - sorted unique numbers which are duplicates in input
Run Code Online (Sandbox Code Playgroud)

我想出了以下解决方案:

方法1:

public static List<Integer> process(List<Integer> input) {
    List<Integer> result = new ArrayList<>();
    Map<Integer, Integer> map = new HashMap<>();
    for (int val : input) {
        map.put(val, map.getOrDefault(val, 0) + 1);
    }

    map.forEach((key, val) -> {
        if (val > 1) {
            result.add(key);
        }
    });
    result.sort(null);
    return result;
}
Run Code Online (Sandbox Code Playgroud)

更新的方法2:

public static …
Run Code Online (Sandbox Code Playgroud)

java

5
推荐指数
1
解决办法
102
查看次数

具有唯一字母的子串数

我有一个字符串,现在想计算子字符串的最小数量,以便子字符串中的字母应该只出现一次。

例子:

Input : cycle
Output : 2
Run Code Online (Sandbox Code Playgroud)

解释:

Possible substrings are : ('cy', 'cle') or ('c', 'ycle')
Run Code Online (Sandbox Code Playgroud)

例子:

Input : aaaa
Output : 4
Run Code Online (Sandbox Code Playgroud)

解释:

Possible substrings are : ('a', 'a', 'a', 'a')
Run Code Online (Sandbox Code Playgroud)

我能够获得所有可能的子字符串,但我无法理解如何实现此任务的解决方案:

static int distinctSubString(String S) {
    int count = 0;
    int n = S.length();
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j <= n; j++) {
            String s = S.substring(i, j);
            System.out.println(s);
        }
    }
    return count; …
Run Code Online (Sandbox Code Playgroud)

java algorithm

5
推荐指数
1
解决办法
145
查看次数