小编cam*_*xon的帖子

如何使用Nokogiri解析XML文件?

我和Nokogiri有一些问题.

我试图解析这个XML文件:

<Collection version="2.0" id="74j5hc4je3b9">
  <Name>A Funfair in Bangkok</Name>
  <PermaLink>Funfair in Bangkok</PermaLink>
  <PermaLinkIsName>True</PermaLinkIsName>
  <Description>A small funfair near On Nut in Bangkok.</Description>
  <Date>2009-08-03T00:00:00</Date>
  <IsHidden>False</IsHidden>
  <Items>
    <Item filename="AGC_1998.jpg">
      <Title>Funfair in Bangkok</Title>
      <Caption>A small funfair near On Nut in Bangkok.</Caption>
      <Authors>Anthony Bouch</Authors>
      <Copyright>Copyright © Anthony Bouch</Copyright>
      <CreatedDate>2009-08-07T19:22:08</CreatedDate>
      <Keywords>
        <Keyword>Funfair</Keyword>
        <Keyword>Bangkok</Keyword>
        <Keyword>Thailand</Keyword>
      </Keywords>
      <ThumbnailSize width="133" height="200" />
      <PreviewSize width="532" height="800" />
      <OriginalSize width="2279" height="3425" />
    </Item>
    <Item filename="AGC_1164.jpg" iscover="True">
      <Title>Bumper Cars at a Funfair in Bangkok</Title>
      <Caption>Bumper cars at a small funfair near On …
Run Code Online (Sandbox Code Playgroud)

ruby xml parsing nokogiri

11
推荐指数
2
解决办法
3万
查看次数

Rails:.destroy错误的参数数量(0表示1)

我的错误消息是"错误的参数数量(0表示1)"

对于这一行:@post = Post.destroy in my

PostsController#destroy
Run Code Online (Sandbox Code Playgroud)

我有一个post.rb的模型

我的帖子控制器就在这里

class PostsController < ApplicationController
  def new
    @post = Post.new
  end

  def index
    @posts = Post.all
  end

  def create
    @post = Post.new(post_params)

    if @post.save
      redirect_to @post
    else
      render 'new'
    end
  end

  def post_params
    params.require(:post).permit(:title, :text)
  end

  def show
    @post = Post.find(params[:id])
  end  

  def edit
    @post = Post.find(params[:id])
  end

  def update
    @post = Post.find(params[:id])

    if @post.update(params[:post].permit(:title, :text))
      redirect_to @post
    else
      render 'edit'
    end
  end

  def destroy
    @post = Post.find(params[:id])
    @post = Post.destroy

    redirect_to …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails

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

jQuery DatePicker显示在其他常规页面元素的后面

我遇到了由其他人实现的日期选择器的麻烦。我试图在我的网站上实施代码,但无法正常工作。以下是Javascript DatePicker

// init datepicker
function initDatepicker(){
    jQuery('.with-datepicker').each(function(){
        var hold = jQuery(this);
        var input = hold.find('input:text');
        var opener = hold.find('.btn');
        input.datepicker({
            showOtherMonths: true
        })
        opener.bind('click', function(e){
            input.focus();
            e.preventDefault();
        })
    })
}
Run Code Online (Sandbox Code Playgroud)

所以我的问题是2折。
A)除了将焦点放在jQuery(this).find('input:text').focus();
B 之外,我不知道input.focus()到底在做什么。B)类“ .with-datepicker”的datepicker出现在页面上其他元素的后面,当我尝试单击时在日期选择器上,它消失了,并且没有选择日期。

要给您提供更多信息,我将其与联系表7一起使用,该联系表具有一个文本框,您可以单击该文本框来激活日期选择器。该部分似乎正常。日期选择器从字面上显示在显示“选择日期”的输入框的正下方。问题在于datepicker类位于其他元素(如单选按钮)的后面。

我也尝试过 input.focus();

$(this).parent().css('position', 'relative');
$(this).parent().css('z-index', 3000);
Run Code Online (Sandbox Code Playgroud)

以下是页面外观的链接: http://www.camdixon.com/wp-content/uploads/2014/03/Capture.png

css jquery focus datepicker

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

Rails 4 - CarrierWave default_url无法使用资产图像

class ImageUploader < CarrierWave::Uploader::Base

  # Include RMagick or MiniMagick support:
  include CarrierWave::RMagick
  # include CarrierWave::MiniMagick

  # Choose what kind of storage to use for this uploader:
  storage :file
  # storage :fog

  # Override the directory where uploaded files will be stored.
  # This is a sensible default for uploaders that are meant to be mounted:
  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

  def default_url
    ActionController::Base.helpers.asset_path("fallback/" + [main, "default.png"].compact.join('_'))
  end

  # Create different versions of your uploaded files:
  version :thumb do
    process :resize_to_fit => …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails image carrierwave

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

C#在.net中切换窗口

嗨我正在尝试使用C#将窗口切换到正在运行的其他程序(即使最小化).

我想知道为什么这不起作用.

错误消息:参数1:无法从'System.Diagnostics.Process'转换为'System.IntPtr'

当它到达循环时,我认为proc变量将引用适当的窗口处理程序.这不是真的吗?我非常感谢你的帮助.

//declarations
using system.IO;
using System.Runtime.InteropServices;
//more

//namespace here

//class here

//initialize method

//related .dll import
[DllImport("user32.dll")]
        public static extern void SwitchToThisWindow(IntPtr hWnd);

String ProcWindow = "itunes";
//function which calls switchWindow() is here but not important

//now we have switch window.
private void switchWindow()
        {
            Process[] procs = Process.GetProcessesByName(ProcWindow);
            foreach (Process proc in procs)
            {
                //switch to process by name
                SwitchToThisWindow(proc);

            }
        }
Run Code Online (Sandbox Code Playgroud)

对于未来的读者:我在另一个问题的代码中达到了这一点. 正确的方式(在.NET中)将焦点切换到另一个应用程序

.net c# process dllimport

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

Ruby - 数组,边界和引发异常

下面是我的脚本的代码.

如您所见,我有一个数组和一个索引.我把它传递给名为'raise_clean_exception'的块.它的整数部分实际上引发了一个很好的标准错误异常.当我使用超出范围的索引时,我遇到了一个问题.因此,如果我的数组只有4个元素(0-3)并且我使用9的索引,它将不会引发异常,而是打印出一个空行,因为没有任何内容.它为什么要这样做?

#!/usr/bin/ruby
puts "I will create a list for you.  Enter q to stop creating the list."
array = Array.new
i = 0
input = ''
print "Input a value: "  #get the value from the user
input = STDIN.gets.chomp
while input != 'q' do #keep going until user inputs 'q'
  array[i] = input  #store the value in an array of strings
  i += 1   #increment out index where the inputs are stored
  print "Input a value: "  #get …
Run Code Online (Sandbox Code Playgroud)

ruby arrays exception-handling indexoutofboundsexception

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

为什么我的Gemfile不会运行?

我正在关注Hartl Ruby on Rails教程,我在本教程的1.2.4节

在设置Rails应用程序时,它说要运行这些命令:

cd first_app_direcory
sublime Gemfile
bundle update
Run Code Online (Sandbox Code Playgroud)

sublime Gemfile命令显然编辑了Gemfile,但是当我尝试运行该命令时,bundle update我收到以下错误:

bundle update
Gemfile syntax error:
ruby 2.0.0 
         ^
/home/cameron/ruby/ror/first_app/Gemfile:2:
syntax error, unexpected tINTEGER,
expecting '('
ruby 2.0.0 
          ^
Run Code Online (Sandbox Code Playgroud)

我从gemfile中取出了这两行,尽管它说要包含它们.此外,我尝试了Ruby 1.9.3,仍然得到相同的错误消息.

ruby 2.0.0 
#ruby-gemset=railstutorial_rails_4_0
Run Code Online (Sandbox Code Playgroud)

采取这些方法之后,它起作用了.我试图让它与gemfile中的那些行一起工作.我怎样才能做到这一点?

这是完整的Gemfile:

source 'https://rubygems.org'
ruby 2.0.0 
#ruby-gemset=railstutorial_rails_4_0

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0'

# Use sqlite3 as the database for Active Record
group :developent do
    gem 'sqlite3', '1.3.7'
end

# Use …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails gemfile

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

如何将此匹配作为给定的目录

currDir = ""
# 
# regex is from stack overflow question:
dirRegex = Regexp.new '^(?!.*[\\/]\.{2}[\\/])(?!\.{2}[\\/])[-\w.\\/]+$'
if ARGV.length == 1 && $1.to_s.match dirRegex
  currDir = $1
  puts $1
  puts "#{currDir}"
  puts ARGV.length
else
  currDir = "./"
  puts $1
  puts "#{currDir}"
  puts ARGV.length
end
Run Code Online (Sandbox Code Playgroud)

当我尝试让上面的代码匹配一个目录,如home或〜/ test /时,它给了我一个错误.

./script.rb /home/local/NKU/dixonc3/test
./script.rb:9: syntax error, unexpected tIDENTIFIER, expecting keyword_then or ';' or '\n'
./script.rb:14: syntax error, unexpected keyword_else, expecting $end
Run Code Online (Sandbox Code Playgroud)

ruby regex

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

Ansible - 使用角色中的相同模板创建多个配置文件

我发现了一个类似的问题:创建多次相同的角色,但使用不同的项目, 但我不知道如何使用group_vars目录结构.

我的问题

如何使用带有模板的角色来创建具有不同名称和值的多个配置文件?我也使用group_vars目录,该目录与我运行的主机运行的playbook位于同一级别.

这是我目前的样本剧本

---
- hosts: emea-stg-web
  vars_files:
    - group_vars/ssh_user.yml
  remote_user: "{{ ssh_user }}"
  become_user: root

  roles:
    - nginx-install
    - php5.6-install
Run Code Online (Sandbox Code Playgroud)

如何让角色中的每个"项目"使用不同的变量值.例如变量"name"可以在迭代时使用["test 1","test 2","test 3"]?我可以将这些值存储在文件中吗?

---
- hosts: emea-stg-web
  vars_files:
    - group_vars/ssh_user.yml
  remote_user: "{{ ssh_user }}"
  become_user: root

  roles:
    - nginx-install
      with_items:
      - test1
      - test2
      - test3
    - php5.6-install
Run Code Online (Sandbox Code Playgroud)

ansible devops ansible-role

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