小编p.m*_*los的帖子

如何在bash函数中打印换行符

我在bash脚本文件中有以下代码:

#! /bin/sh
#
# Usage:
#
# f.sh <start_directory> <destination_directory> <prepare_directory> <remote_host_for_copy> <remote_user>
#
print_correct_syntax() {

 echo "f.sh <start_directory> <destination_directory> <prepare_directory> <remote_host_for_copy> <remote_user>"
 echo ""
 echo '<start_directory> needs to be a full path, <destination_directory> needs to be full path, <prepare_directory> has to be relative to start_directory path'
 echo ""

}
# ---- end of function definition ----

# check number of run-time arguments given to script

if [ $# != 5 ]
then
 echo Wrong Syntax! $(print_correct_syntax)
 exit;
fi …
Run Code Online (Sandbox Code Playgroud)

bash debian newline echo

4
推荐指数
1
解决办法
2904
查看次数

如何设置太阳黑子来搜索字符序列而不是单词?

我想了解Sunspot在标准模式下是否在全文搜索中搜索字符或字符序列以及如何搜索序列.

例如,我有以下设置:

class User < ActiveRecord::Base
   searchable do
      text :email
   end
end
Run Code Online (Sandbox Code Playgroud)

一个User与电子邮件"panayotis@matsinopoulos.gr"

以下查询:

search = User.search do 
   fulltext 'matsinopoulos'
end
Run Code Online (Sandbox Code Playgroud)

没有带来任何结果,而:

search = User.search do
   fulltext 'panayotis@matsinopoulos.gr'
end
Run Code Online (Sandbox Code Playgroud)

带来的.

是否有任何配置设置太阳黑子匹配字符序列而不是单词?

或者,我做错了什么?

ruby-on-rails sunspot sunspot-rails

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

为什么提交输入样式不适用于 Chrome 和 Safari (Mac),但仅适用于应用背景颜色?

我有一个简单的网页,其中 CSS 样式规则不适用于表单按钮,如果我使用的是 Chrome 或 Safari(Mac OS X、Yosemite)。它确实适用于 Firefox。如果我使用 background-color 属性,它确实适用于 Chrome 和 Safari。

看下面的例子。该save按钮没有Roboto Mono字体,它应该是。仅当您在 Chrome 或 Safari 上打开页面时才会出现此问题。它在 Firefox 上运行完美。

最重要的是,如果我background-color在按钮上应用类似的样式,那么字体会Roboto Mono突然按预期工作,并且它也应用在按钮上。

这是我使用的代码。

http://jsbin.com/foqiso/edit?html,css,output

任何线索为什么按钮不采用指定的字体,但前提是

  • 我在 Firefox 或
  • 我在 Chrome 或 Safari 上,我应用了背景颜色

?

更新:还有另一种解决方法。<input type="submit" value="Save">如果我使用<button type=submit>Save</button>,而不是使用,则使用button我期望的字体进行样式设置。

html css safari macos google-chrome

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

什么是最优雅的Ruby语句将字符串中的字符串拆分为两个?

我有字符串"abigword",我想采取数组["ab", "ig", "wo", "rd"].为了概括,给定一个字符串,我想把它的组成字符数组一对一地配对.

什么是最优雅的Ruby方式呢?

ruby

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

为什么在子控制器上的before_filters在Rails上的父控制器上的before过滤器之前被调用?

我在用 Rails 3.2.X

我有Controllers继承案例如下:

class ApplicationController < ActionController::Base
  before_filter :do_something

  protected

  def do_something
  end
end
Run Code Online (Sandbox Code Playgroud)

class ChildController < ApplicationController
  before_filter :do_something_else

  protected

  def do_something_else
  end
end
Run Code Online (Sandbox Code Playgroud)

在调用动作时ChildController我看到do_something_else之前被调用do_something.这是预期的行为吗?

即使我这样做:

append_before_filter :do_something_else
Run Code Online (Sandbox Code Playgroud)

do_something_else始终首先调用,这是不是我的预期.

如何before_filters在子控制器上before_filters定义其父控制器上定义的子控制器之后执行.

[更新]请注意,问题更为笼统.我需要一个答案,它将涵盖任何数量的过滤器ApplicationController和子控制器上的任何数量的过滤器以及更长的继承树上的子控制器的子控制器.

要使此更新更加清晰:

class ApplicationController < ActionController::Base
  before_filter :do_something1
  before_filter :do_something2
end

class ChildController < ApplicationController
  before_filter :do_something3
  before_filter :do_somethign4
end

class Child2Controller < ChildController
  before_filter :do_something5
  before_filter :do_somethign6
end
Run Code Online (Sandbox Code Playgroud)

呼叫操作Child2Controller应该被称为:1)do_something1 …

ruby-on-rails ruby-on-rails-3

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

使用 Rails 3.2 进行日志记录时,如何记录日志语句出现的文件名和行号?

在使用 Rails 3.2 进行日志记录时,我想记录日志条目所在的文件名和行号。

因此,如果在我的在线 ruby​​ 脚本中customer.rb23有一个类似以下的日志:

Rails.logger.debug "Debug message"
Run Code Online (Sandbox Code Playgroud)

我希望日志记录如下内容:

[customer.rb:23] Debug message
Run Code Online (Sandbox Code Playgroud)

那可能吗?

logging ruby-on-rails ruby-on-rails-3.2

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

是否有Ruby文档可以验证Enumerable.to_a是否在内部调用?

我可以写一个简短的例子来验证内部to_aEnumerable调用each.这里是:

class MyFooClass
  include Enumerable
  def initialize
    @members = [1, 2, 3]
  end
  def each
    puts "each is now called"
    @members.each{ |m| yield(m) }
  end
end

a = MyFooClass.new
puts "let us convert to array"
g = a.to_a
Run Code Online (Sandbox Code Playgroud)

输出是:

let us convert to array
each is now called
Run Code Online (Sandbox Code Playgroud)

请注意,each它不是成员Enumerable,但是to_a.此外,如果我each从我的类中删除定义,然后代码崩溃与以下消息:

in `to_a': undefined method `each' for #<MyFooClass:0x997c1ac @members=[1, 2, 3]> (NoMethodError)
Run Code Online (Sandbox Code Playgroud)

我想知道是否有关于此的Ruby官方文档,这将记录to_a(在其成员中Enumerable)通过each …

ruby enumerable

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

如何使用Ruby枚举器获取下n个元素?

我试图n使用Ruby枚举器获取下一个数量的元素,使用:

a = [1, 2, 3, 4, 5, 6]
enum = a.each
enum.next(2) # expecting [1, 2]
enum.next(2) # expecting [3, 4]
Run Code Online (Sandbox Code Playgroud)

#next不支持这一点.还有另一种方法可以做到吗?或者我该怎么办?

什么是正确的Ruby方法呢?

ruby enumerators

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

ERB空白删除关闭表达式符号( - %>)的HAML等效项是什么?

有谁知道如何在纯HAML中写下以下内容?请注意,我想显示两个完全相邻的选择框,旁边是一个按钮,中间没有任何空格:

<%= f.select :state, State.all.order(:name).map {|s| [s.name, s.id]} -%>
<%= f.select :subject, Subject.all.order(:name).map {|s| [s.name, s.id]} -%>
<%= f.button "Search", class: "input-lg" -%>
Run Code Online (Sandbox Code Playgroud)

编辑包含在以下内容中:

= form_for @tutors_search_form, url: "/tutors/search", method: :get do |f|
  .container
    .row.text-center
      :erb
        <%= f.text_field :subject, class: "input-lg input-no-border-radius", placeholder: "What Subject do you want to learn?", required: true, id: 'home-page-search-bar-subject-input' -%>
        <%= f.text_field :state, class: "input-lg input-no-border-radius", placeholder: "Which State are you in?", required: true, id: 'home-page-search-bar-state-input' -%>
        <%= f.button "Search", class: "btn btn-primary-wouaou btn-lg …
Run Code Online (Sandbox Code Playgroud)

haml ruby-on-rails erb

-1
推荐指数
1
解决办法
260
查看次数