问题列表 - 第31024页

在 Ruby on Rails 应用程序中,在哪里放置视图的重复显示代码?

我有一个注释模型,它可以包含图像链接附件(linktype =“image”或一些文本(linktype =“text))。当我显示注释时,显示方法根据链接类型而变化。一个例子是:

<% @notes.each do |q| %>
    <h2 class="title"><%= q.name %></h2>
    <% if q.linktype == "image"%>
        <img src="<%= q.link %>" />
    <% elsif q.linktype == "text"%>
        <%= q.text %>
    <% end %>
<% emd %>
Run Code Online (Sandbox Code Playgroud)

我必须在站点中的几个不同视图中显示注释,因此我不想多次重复查看代码,而是希望将其放在一个位置并从不同的视图中引用它。

我应该在应用程序助手中执行此操作吗?如果是这样,我是否将显示代码(如上面的代码)直接放入助手中,还是有更好的方法?谢谢阅读。

ruby-on-rails

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

消极的环顾四周

以下正则表达式是错误的 - 有人可以帮助找到所有:-)前面没有"请忽略我"吗?我之前不需要这样的正则表达式.单词边界可能会混淆事物.
谢谢

<script type="text/javascript">
function regexTest(string, assert) {
  document.write('<hr>')
  document.write(string)
  document.write("[")
  document.write(string.match(/\b((?!please ignore me )\:\-\))\b/gi)!=null);
  document.write("]?" + assert);
}

regexTest("1. this is the first string :-)        ",true);
regexTest("2. :-)",true)
regexTest("3. another string:-)here",true);
regexTest("4. Ending a sentence with :-)",true);
regexTest("5. please ignore me :-)",false);
</script>
Run Code Online (Sandbox Code Playgroud)

javascript regex lookbehind

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

在类中连接已定义的变量和字符串时解析错误

我在一个单独的配置文件中定义了一个变量:

define('URL', 'someurl.co.uk');
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试使用它来连接类中的字符串时:

class AdminEmail extends Email {

   private $from = "jsmith".URL;
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

Parse error: parse error, expecting `','' or `';'' 
Run Code Online (Sandbox Code Playgroud)

但是,如果我回应它,​​它显示完美!

希望我没有错过任何明显的东西!

php class parse-error

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

如何使用Foreach迭代集合来构建XDocument?

以下代码给出了错误:

'System.Xml.Linq.XElement.XElement(System.Xml.Linq.XName,object)'的最佳重载方法匹配具有一些无效参数.

我需要更改什么才能List<Customer>使用Foreach构建XDocument 来遍历我的集合?

using System;
using System.Collections.Generic;
using System.Xml.Linq;

namespace test_xml3
{
    class Program
    {
        static void Main(string[] args)
        {

            List<Customer> customers = new List<Customer> {
                new Customer {FirstName="Jim", LastName="Smith", Age=27},
                new Customer {FirstName="Hank", LastName="Moore", Age=28},
                new Customer {FirstName="Jay", LastName="Smythe", Age=44}
            };

            Console.WriteLine(BuildXmlWithLINQ(customers));
            Console.ReadLine();
        }

        private static string BuildXmlWithLINQ(List<Customer> customers)
        {
            XDocument xdoc = new XDocument
            (
                new XDeclaration("1.0", "utf-8", "yes"),
                new XElement("customers",
                    customers.ForEach(c => new XElement("customer", 
                        new XElement("firstName", c.FirstName),
                        new XElement("lastName", c.LastName)
                    )
                )
            );
            return …
Run Code Online (Sandbox Code Playgroud)

c# xml linq foreach linq-to-xml

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

Autoconf 使用损坏的功能生成配置(ac_fn_set_status、ac_fn_exit)

我正在尝试为我的项目设置 autoconf。除了在 ./configure 中找不到 ac_set_<...> 函数之外,我的一切都“正常”工作。如果我直接运行它们,它们在configure.status中工作正常。

具体来说,我在 as_fn_set_status 和 as_fn_exit 方面遇到问题。

如果我手动编辑配置文件并将这两个函数移至配置脚本的顶部,则一切正常。

为了达到这一点,我:

  1. 编写configure.ac
  2. 运行 autoreconf -i
  3. 运行./配置

结果行类似于:

./configure: line 1366: as_fn_set_status: command not found
Run Code Online (Sandbox Code Playgroud)

有3-4行发生错误。

关于什么可能产生这种效果有什么想法吗?这是我的configure.ac:

##########################################
#  Autoconf Configuration File for RPDB  #
##########################################

#   RPDB: An Object-Oriented Wrapper for Oracle's Berkeley Database (BDB/libdb),
#   which is available at: http://www.oracle.com/technology/software/products/berkeley-db/index.html

###########################
#  Init Autoconf >= 2.61  #
###########################

AC_CANONICAL_SYSTEM

AC_PREREQ(2.61)
AC_INIT([rpdb], [0.1.0], [asher@ridiculouspower.com])

AC_CONFIG_AUX_DIR([.])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_FILES([Makefile])
AC_CONFIG_HEADERS([config.h])

AM_INIT_AUTOMAKE

#################################
#  Check for Library Functions  #
#################################

AC_FUNC_ERROR_AT_LINE …
Run Code Online (Sandbox Code Playgroud)

autoconf function configure

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

PHP:需要一个相反的timezone_name_from_abbr方法吗?

我需要一个完全相反的timezone_name_from_abbr()方法:http://php.net/manual/en/function.timezone-name-from-abbr.php

我有一个时区名称列表如下:

Australia/Brisbane
Australia/Hobart
Asia/Vladivostok
Australia/Lord_Howe
Asia/Magadan
Asia/Kolkata
America/Los_Angeles
......
Run Code Online (Sandbox Code Playgroud)

我需要一个方法,它将时区作为一个参数,并返回一个它的缩写.例如:

如果我使用如下方法:

   $timeAbbr = timezone_abbr_from_name('America/Los_Angeles');
   echo $timeAbbr;
Run Code Online (Sandbox Code Playgroud)

结果应该是:

PST
Run Code Online (Sandbox Code Playgroud)

php timezone

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

我怎么能逃避惊叹号!在cmd脚本?

当我setlocal ENABLEDELAYEDEXPANSION在cmd脚本中设置时,我有什么方法可以逃脱!我想用作命令的参数?

@echo off
setlocal ENABLEDELAYEDEXPANSION
echo I want to go out with a bang!
echo I still want to go out with a bang^!
Run Code Online (Sandbox Code Playgroud)

cmd batch-file

71
推荐指数
4
解决办法
5万
查看次数

使用MEF作为IoC

在阅读了一些这样的内容之后:http://mikehadlow.blogspot.com/2008/09/managed-extensibility-framework-why.html

我知道MEF有一些我在IoC中找不到的功能,并且MEF有一些IoC的东西可能不像其他一些IoC系统那样先进.

我需要MEF的东西.我是否还需要一个IoC框架,或者我对MEF有什么好处?

阿谢尔

mef c#-4.0

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

多处理:如何在类中定义的函数上使用Pool.map?

当我运行类似的东西:

from multiprocessing import Pool

p = Pool(5)
def f(x):
     return x*x

p.map(f, [1,2,3])
Run Code Online (Sandbox Code Playgroud)

它工作正常.但是,将此作为类的函数:

class calculate(object):
    def run(self):
        def f(x):
            return x*x

        p = Pool()
        return p.map(f, [1,2,3])

cl = calculate()
print cl.run()
Run Code Online (Sandbox Code Playgroud)

给我以下错误:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/sw/lib/python2.6/threading.py", line 532, in __bootstrap_inner
    self.run()
  File "/sw/lib/python2.6/threading.py", line 484, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/sw/lib/python2.6/multiprocessing/pool.py", line 225, in _handle_tasks
    put(task)
PicklingError: Can't pickle <type 'function'>: attribute lookup __builtin__.function failed
Run Code Online (Sandbox Code Playgroud)

我看过Alex Martelli的一篇文章处理同样的问题,但它不够明确.

python pickle multiprocessing

165
推荐指数
10
解决办法
9万
查看次数

有没有办法获取传递给方法的参数数组?

说我有一个方法:

 public void SomeMethod(String p1, String p2, int p3)
 {

 #if DEBUG
    object[] args = GetArguments();
    LogParamaters(args);
 #endif

     // Do Normal stuff in the method
 }
Run Code Online (Sandbox Code Playgroud)

有没有办法检索传递给方法的参数数组,以便记录它们?

我有大量的方法,并希望避免手动将名称传递给记录器,因为人为错误将不可避免地蔓延.

我猜它会以某种形式涉及反射 - 这很好,因为它只会用于调试目的.

更新

更多信息:

我无法更改SomeMethod的方法签名,因为它作为WebMethod公开,并且必须复制它模拟的遗留系统.

遗留系统已经记录了传入的参数.从新实现开始将包装遗留系统,所以我希望记录进入C#版本的参数,以便我可以验证正确的参数是否传入按正确的顺序.

我只是想记录参数值和顺序,而不是它们的名字.

c# reflection methods arguments

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