小编car*_*nts的帖子

将text_field限制为仅三个值

我有一个简单的应用程序,它使用text_field标记来输入:

 <div><%= f.label :user %><br />
  <%= f.text_field :user %></div>
Run Code Online (Sandbox Code Playgroud)

我知道我可以通过使用选择字段来限制输入:

<div><%= f.label :user %><br />
<%= f.select :user, [ ['user1'], ['user2'], ['user3'] ] %></div>
Run Code Online (Sandbox Code Playgroud)

我想知道如何将上述选择字段与上面的简单text_field应用相同的限制.(即user1,user2,user3仍然是唯一允许的输入,但页面上的用户将不会通过select字段看到user1,user2,user3).

编辑*我只是在寻找一个简单的验证方案

ruby-on-rails

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

rvm无法安装ruby-1.9.3-p484

我正在尝试更新我的OctoPress博客并收到错误消息

未安装ruby-1.9.3-p484.

当我输入命令

rvm install ruby​​-1.9.3-p484我得到了错误:

Searching for binary rubies, this might take some time.
No binary rubies available for: osx/10.8/x86_64/ruby-1.9.3-p484.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for osx.
Error: No available formula for gcc46 
Installing requirements for osx.
Updating system.........
Error running 'requirements_osx_brew_update_system ruby-1.9.3-p484',
please read /Users/stevenbrooks1111/.rvm/log/1386191431_ruby-1.9.3-p484/update_system.log
Requirements installation failed with status: 1.
Run Code Online (Sandbox Code Playgroud)

不知道这里发生了什么.我现在有

ruby-1.9.3-p429 [ x86_64 ]
ruby-2.0.0-p195 [ x86_64 ]
ruby-2.0.0-p353 [ x86_64 ]
Run Code Online (Sandbox Code Playgroud)

安装在我的电脑上.

ruby rvm octopress

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

返回指向局部变量的指针时的堆栈行为

我有一个简单的例子,其中Rust的行为与我的心理图像不匹配,所以我想知道我错过了什么:

fn make_local_int_ptr() -> *const i32 {
    let a = 3;
    &a
}

fn main() {
    let my_ptr = make_local_int_ptr();
    println!("{}", unsafe { *my_ptr } );
}
Run Code Online (Sandbox Code Playgroud)

结果:

3
Run Code Online (Sandbox Code Playgroud)

这不是我所期望的.使用堆栈和堆中给出的符号

我希望堆栈框架看起来像这样:

Address | Name | Value
-----------------------
   0    |   a  |   3  
Run Code Online (Sandbox Code Playgroud)

在里面make_local_int_ptr(),但在此之后,

let my_ptr = make_local_int_ptr();
Run Code Online (Sandbox Code Playgroud)

由于a超出范围,我希望堆栈被清除.但它显然没有.

此外,如果我在创建my_ptr和打印它的解除引用值之间定义另一个变量:

fn main() {
    let my_ptr = make_local_int_ptr();
    let b = 6;
    println!("{}", b); // We have to use b otherwise Rust
                       // compiler …
Run Code Online (Sandbox Code Playgroud)

stack rust

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

Python字典for循环无值

我的代码:

hand = {'e': 1, 'i': 2, 'h': 1, 's': 1, 'r': 1, 'w': 1, 'v': 2}
def showhand(a):
    for letter in hand:
        for j in range(hand[letter]):
            print letter,
Run Code Online (Sandbox Code Playgroud)

我期望获得的输出是:

e i i h s r w v v 
Run Code Online (Sandbox Code Playgroud)

但我看到的是:

e i i h s r w v v None
Run Code Online (Sandbox Code Playgroud)

我不知道None价值来自哪里.如何获得我想要的输出?

python dictionary

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

标签 统计

dictionary ×1

octopress ×1

python ×1

ruby ×1

ruby-on-rails ×1

rust ×1

rvm ×1

stack ×1