小编cra*_*aig的帖子

向link_to添加查询字符串参数

我很难在link_to UrlHelper中添加查询字符串参数.我有一个索引视图,例如,它具有用于排序,过滤和分页的UI元素(通过will_paginate).will_paginate插件正确管理查询字符串参数的页内持久性.

是否有自动机制将查询字符串参数添加到给定命名路由,或者我是否需要手动执行此操作?对这个看似简单的结构的大量研究让我一无所知.

编辑

一些挑战:

  1. 如果我有两个查询字符串参数,存储桶和排序,如何在link_to中为其中一个设置特定值,同时保留另一个的当前值?例如:

    <%= link_to "0", profiles_path(:bucket => '0', :sorting=>?? ) %>
    
    Run Code Online (Sandbox Code Playgroud)
  2. 如果我有多个查询字符串参数,bucket&sorting&page_size,并且我想将值设置为其中之一,是否有办法'自动'包含其余参数的名称和值?例如:

    <%= link_to "0", profiles_path(:bucket => '0', [include sorting and page_size name/values here] ) %>
    
    Run Code Online (Sandbox Code Playgroud)
  3. will_paginate插件自动管理其页面变量和其他查询字符串变量.似乎没有用于管理页面大小的自动UI元素.虽然我已经看到了创建页面大小选择列表的代码,但我宁愿为此设置A元素(如SO).这个挑战的一部分与#2有关,部分与基于记录的存在/不存在隐藏/显示该UI元素有关.换句话说,如果有页面记录,我只想包含页面大小的链接.此外,我更喜欢自动包含其他QS变量(即页面,存储桶,排序),而不必在link_to中按名称包含它们.

ruby-on-rails query-string

198
推荐指数
4
解决办法
21万
查看次数

将objective-c typedef转换为其等效字符串

假设我在.h文件中声明了一个typedef:

typedef enum {
  JSON,
  XML,
  Atom,
  RSS
} FormatType;
Run Code Online (Sandbox Code Playgroud)

我想构建一个将typedef的数值转换为字符串的函数.例如,如果邮件[self toString:JSON]已发送; 它会返回'JSON'.

该函数看起来像这样:

-(NSString *) toString:(FormatType)formatType {
  //need help here
  return [];
}
Run Code Online (Sandbox Code Playgroud)

顺便说一句,如果我尝试这种语法

[self toString:FormatType.JSON];
Run Code Online (Sandbox Code Playgroud)

要将typedef值传递给方法,我收到一个错误.我错过了什么?

c enums typedef objective-c

138
推荐指数
9
解决办法
12万
查看次数

Ruby on Rails:清除缓存页面

我有一个在开发环境中缓存页面的RoR应用程序(ruby v1.8.7; rails v2.3.5).这不是一个问题,但缓存页面的a元素是不正确的.

我没有对development.rb文件进行任何更改,我没有故意向控制器添加任何缓存命令.

我已经尝试清除浏览器(OSX上的Firefox 3.5)cookie和页面缓存(localhost).我也重启了Mongrel.似乎没有任何帮助.

我错过了什么?

caching ruby-on-rails

76
推荐指数
3
解决办法
12万
查看次数

创建一个返回表的Oracle函数

我正在尝试在包中创建一个返回表的函数.我希望在包中调用一次函数,但能够多次重复使用它的数据.虽然我知道我在Oracle中创建临时表,但我希望保持干燥.

到目前为止,这就是我所拥有的:

标题:

CREATE OR REPLACE PACKAGE TEST AS 

    TYPE MEASURE_RECORD IS RECORD (
      L4_ID VARCHAR2(50),
      L6_ID VARCHAR2(50),
      L8_ID VARCHAR2(50),
      YEAR NUMBER,
      PERIOD NUMBER,
      VALUE NUMBER
    );

    TYPE MEASURE_TABLE IS TABLE OF MEASURE_RECORD;

    FUNCTION GET_UPS(
      TIMESPAN_IN IN VARCHAR2 DEFAULT 'MONTLHY',
      STARTING_DATE_IN DATE,
      ENDING_DATE_IN DATE  
    ) RETURN MEASURE_TABLE;

END TEST;
Run Code Online (Sandbox Code Playgroud)

身体:

CREATE OR REPLACE PACKAGE BODY TEST AS 

  FUNCTION GET_UPS (
    TIMESPAN_IN IN VARCHAR2 DEFAULT 'MONTLHY',
    STARTING_DATE_IN DATE,
    ENDING_DATE_IN DATE
  ) RETURN MEASURE_TABLE IS

    T MEASURE_TABLE;

  BEGIN

        SELECT  ...
        INTO    T …
Run Code Online (Sandbox Code Playgroud)

plsql package oracle10g

20
推荐指数
2
解决办法
12万
查看次数

Java OutputStream等效于getClass().getClassLoader().getResourceAsStream()

我试图存储对我的应用程序属性所做的更改.该.properties文件位于resources包中,该包与包含我的UI和模型的包不同.

我用以下方式打开了包裹:

this.getClass().getClassLoader().getResourceAsStream("resources/settings.properties")
Run Code Online (Sandbox Code Playgroud)

是否有一个功能等同于允许我在同一.Properties文件中持久更改属性类?

java file-io swing persistence properties

15
推荐指数
4
解决办法
2万
查看次数

确定PSCustomObject的数组是否包含具有属性值的实例

我需要确定一个PSCustomObjects 数组是否包含一个Title属性与值匹配的项.我需要一个布尔值来与Pester断言一起使用:

$Items -<function> $Name | Should Be $True
Run Code Online (Sandbox Code Playgroud)

假设:

$Items = @()
$Items += [PsCustomObject]@{Title='foo';Url='http://f.io'}
$Items += [PsCustomObject]@{Title='bar';Url='http://b.io'}
Run Code Online (Sandbox Code Playgroud)

Contains 不起作用:

PS> $Items -contains 'foo'
False
Run Code Online (Sandbox Code Playgroud)

Match 返回匹配的实例,但它不是布尔值:

PS> $Items -match 'foo'

Title  Url
-----  ---
foo    http://f.io
Run Code Online (Sandbox Code Playgroud)

我想我可以:

($Items -Match $Name).Count | Should Be 1
Run Code Online (Sandbox Code Playgroud)

有更好的选择吗?

powershell powershell-3.0 pester

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

使用JCheckBox节点进行JTree渲染

我正在尝试修改标准的Swing JTree以使用和不使用复选框来混合节点.这是一个例子:

替代文字

当我尝试选中/取消选中其中一个复选框(本例中为"User 01"节点)时,树会丢失节点:

替代文字

我的代码是这个例子的改编:http://forums.sun.com/thread.jspa?threadID = 5321084&start = 13.

而不是像这样在DefaultMutableTreeNode中嵌入JCheckBox:

new DefaultMutableTreeNode(new CheckBoxNode("Accessibility", true));
Run Code Online (Sandbox Code Playgroud)

我认为创建一个派生自DefaultMutableTreeNode的模型节点更有意义,我称之为JTreeNode.该类自动将DefaultMutableTreeNode的UserObject设置为JCheckBox.TreeCellRenderer使用类的ShowCheckBox属性来确定是否使用了JCheckBox或DefaultTreeCellRenderer.JTreeNode的用法如下:

    JTreeNode user01 = new JTreeNode("User 01");
    user01.setShowCheckBox(true);
    user01.setSelected(true);
Run Code Online (Sandbox Code Playgroud)

我认为问题在于实现TreeCellEditor的类,特别是在getCellEditorValue()或getTreeCellEditorComponent()方法中.我怀疑这个问题与getCellEditorValue()有关,返回DefaultMutableTreeNode的派生,而不是更简单的模型实例.

public Object getCellEditorValue() {

    JCheckBox checkBox = renderer.getCheckBoxRenderer();

    JTreeNode node = new JTreeNode(checkBox.getText());
    node.setShowCheckBox(true);
    node.setSelected(checkBox.isSelected());
    return node;

}

public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) {

    Component editor = renderer.getTreeCellRendererComponent(tree, value, true, expanded, leaf, row, true);

    // editor always selected / focused
    ItemListener itemListener = …
Run Code Online (Sandbox Code Playgroud)

java swing rendering jtree jcheckbox

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

Rails 3 has_one路由

我有两节课:

class User < ActiveRecord::Base
  :has_one :foo
end

class Foo < ActiveRecord::Base
  :belongs_to :user 
end
Run Code Online (Sandbox Code Playgroud)

Foo是可选的.

我创建了以下路由:

resources :users do
  resources :foo
end
Run Code Online (Sandbox Code Playgroud)

这导致以下路线:

GET    /users/:user_id/foo(.:format)              {:controller=>"foos", :action=>"index"}
user_foos POST   /users/:user_id/foo(.:format)              {:controller=>"foos", :action=>"create"}
new_user_foo GET    /users/:user_id/foo/new(.:format)          {:controller=>"foos", :action=>"new"}
GET    /users/:user_id/foo/:id(.:format)          {:controller=>"foos", :action=>"show"}
PUT    /users/:user_id/foo/:id(.:format)          {:controller=>"foos", :action=>"update"}
user_foo DELETE /users/:user_id/foo/:id(.:format)          {:controller=>"foos", :action=>"destroy"}
edit_user_foo GET    /users/:user_id/foo/:id/edit(.:format)     {:controller=>"foos", :action=>"edit"}
Run Code Online (Sandbox Code Playgroud)

问题:

  1. 看起来Index和Show操作是多余的.是否应该删除其中一个?如果是这样,哪一个?
  2. 似乎不需要Show动作中的:id参数,因为user_id是foos表中的外键,每个用户只有一个foo.我错了吗?
  3. 如果没有foo,我想有一种优雅的方式来路由到New动作.一种选择是测试@ user.foo.nil?在FooController的Show或Index操作中,然后重定向到New操作.有没有更好的办法?

谢谢你的时间.

routing has-one ruby-on-rails-3

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

以PowerShell对象表示法(PSON)保存哈希表

从文件中加载PowerShell哈希表的问题记录如何将包含PSON格式的哈希表的文件加载到变量中,但是如何将哈希表保存为PSON格式的文件?

哈希表:

@{            
 "name" = "report 0"            
 "parameters" = @(
    @{"name" = "parameter 0"; "default" = 1; "values"=1,2,3,4},
    @{"name" = "parameter 1"; "default" = 'A'; "values" = 'A','B','C'}
    )            
}
Run Code Online (Sandbox Code Playgroud)

powershell serialization expression powershell-2.0

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

在PowerShell模块中忽略了Write-Verbose

我希望Write-Verbose在脚本和函数中使用命令行开关.它在脚本(.ps1)文件中按预期工作,但在模块(.psm1)文件中不起作用 - 在模块中忽略命令行开关.

运行以下脚本:

PS> .\scaffold.ps1 -verbose
Run Code Online (Sandbox Code Playgroud)

生产:

VERBOSE: starting foo
path: c:\bar.txt
[missing entry here - 'verbose path: c:\bar.txt']
VERBOSE: ending foo
Run Code Online (Sandbox Code Playgroud)

scaffold.ps1:

[cmdletbinding()]
param()

import-module Common -force

write-verbose "starting foo"

foo "c:\bar.txt"

write-verbose "ending foo"
Run Code Online (Sandbox Code Playgroud)

Common.psm1:

function foo {

  [cmdletbinding()]
  Param(
    [string]$path
  )

  write-host "path: $path"
  write-verbose "verbose path: $path"

}
Run Code Online (Sandbox Code Playgroud)

此时我没有将清单(.psd1)与模块(.psm1)相关联.

是否需要使用特定于模块的语法?

**编辑**

我需要的是一种确定-verbose标志是否已在.PS1文件上设置的方法,以便我可以将其传递给.PSM1文件.

scaffold.ps1:

[cmdletbinding()]
param()

import-module Common -force

write-verbose "starting foo"

foo "c:\bar.txt" $verbose_flag # pass verbose setting to module based …
Run Code Online (Sandbox Code Playgroud)

powershell powershell-2.0

10
推荐指数
3
解决办法
8023
查看次数