小编Lis*_*nge的帖子

在rails上使用ruby为haml创建一个帮助器或东西

我正在使用haml和我的rails应用程序,我有一个问题如何将这个haml代码插入到html文件中的最简单方法:

<div clas="holder">
 <div class=top"></div>
  <div class="content">
   Content into the div goes here
  </div>
 <div class="bottom"></div>
</div>
Run Code Online (Sandbox Code Playgroud)

我想在我的haml文档中使用它,如下所示:

%html
 %head
 %body
  Maybee some content here.
  %content_box #I want to get the code i wrote inserted here
   Content that goes in the content_box like news or stuff
 %body
Run Code Online (Sandbox Code Playgroud)

有更简单的方法吗?


我收到此错误:

**unexpected $end, expecting kEND**
Run Code Online (Sandbox Code Playgroud)

使用此代码:

# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
 def content_box(&block)
  open :div, :class => "holder" do # …
Run Code Online (Sandbox Code Playgroud)

ruby haml ruby-on-rails

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

订阅到期后,MSDN Windows许可证是否仍然有效?

订阅结束后,我的Windows许可证密钥是否仍然可用?这不是批量许可证.

windows msdn

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

Ruby on rails认证指南

有没有人知道在ruby on rails上构建自己的身份验证系统的好指南?我想将我自己的系统用于我的社区即时建设:)

谢谢!

ruby authentication ruby-on-rails system

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

CodeIgniter路由

我正在开发一个包含产品类别和产品的CI的电子商务网站.我想路由URL以便它将转到产品控制器,然后为第一个段运行getCategoryByName函数,然后为第二个段运行getProductByName.这是我有的:

URL:
products/docupen/rc805
routes.php:
$route['products/([a-z]+)'] = "products/getCategoryByName/$1";
$route['products/([a-z]+)/([a-z0-9]+)'] = "products/$1/getProductByName/$2";

但它不起作用."docupen"是类别,"rc805"是产品.

提前致谢.


感谢大家的帮助.这就是我最终需要的东西.

$route['products/:any/:num'] = "products/getProductByID";
$route['products/:any/:any'] = "products/getProductByName";
$route['products/:any'] = "products/getCategoryByName";

php regex routing codeigniter http

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

红宝石中前导零的范围

我有一个表单,我的用户可以在我的网站上注册.

他们以生日,出生月和生日的形式填写他们的出生日期.

所以我使用Range在这样的表单中创建选择:

= f.select(:birthmonth, options_for_select((1..12)))
Run Code Online (Sandbox Code Playgroud)

但是这并没有像我想要的那样以零开始单位数字:01,02,03,04,05,06,07,08,09,10等等.

我甚至试过这个,但它不起作用:

= f.select(:birthmonth, options_for_select((01..12)))
Run Code Online (Sandbox Code Playgroud)

任何知道如何让Range开始使用前导零的人?或者任何其他方式这样做,以便我可以在验证中使用它?:

validates_inclusion_of :birthmonth, :in => 1..12
Run Code Online (Sandbox Code Playgroud)

ruby forms ruby-on-rails range

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

Ruby sprintf在1.9中表现出色

Kernel#sprintf在Ruby中的方法上遇到了一些困惑.

Ruby 1.9以与Ruby 1.8不同的方式处理编码.

以下是我追求的结果,以及它在Ruby 1.8中的表现:

>> RUBY_VERSION
=> "1.8.7"
>> sprintf("%c", 88599)
=> "\027"
Run Code Online (Sandbox Code Playgroud)

这就是它在Ruby 1.9中的表现:

1.9.3p194 :001 > RUBY_VERSION
=> "1.9.3" 
1.9.3p194 :002 > sprintf("%c", 88599)
=> "\u{15A17}"
Run Code Online (Sandbox Code Playgroud)

如果我使用魔术注释将编码设置为二进制(ascii-8bit),我会收到一个错误:

1.9.3p194 :001 > RUBY_VERSION
=> "1.9.3" 
1.9.3p194 :002 > # encoding: binary
1.9.3p194 :003 >   sprintf("%c", 88599)
RangeError: 88599 out of char range
from (irb):3:in `sprintf'
from (irb):3
from /Users/lisinge/.rvm/rubies/ruby-1.9.3-p194/bin/irb:16:in `<main>'
Run Code Online (Sandbox Code Playgroud)

我也尝试过使用Ruby 1.9.2,因此似乎没有特定于1.9.3.

也许我做错了什么?我对这种Kernel#sprintf方法并不熟悉.

我正在使用一个名为ruby-smpp的smpp库,它可以在github上找到.send_concat_mt当我试图在Ruby 1.9.3中运行它时,它就是第47行的方法.

如果你们中的任何人能够对这个问题有所了解,我将不胜感激.

ruby encoding printf

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

我是否以正确的方式使用eventmachine?

我使用ruby-smpp和redis来实现基于队列的后台工作程序来发送SMPP消息.

我想知道我是否以正确的方式使用eventmachine.它有效,但感觉不对.

#!/usr/bin/env ruby

# Sample SMS gateway that can receive MOs (mobile originated messages) and
# DRs (delivery reports), and send MTs (mobile terminated messages).
# MTs are, in the name of simplicity, entered on the command line in the format
# <sender> <receiver> <message body>
# MOs and DRs will be dumped to standard out.

require 'smpp'
require 'redis/connection/hiredis'
require 'redis'
require 'yajl'
require 'time'

LOGFILE = File.dirname(__FILE__) + "/sms_gateway.log"
PIDFILE = File.dirname(__FILE__) + '/worker_test.pid'
Smpp::Base.logger = Logger.new(LOGFILE) …
Run Code Online (Sandbox Code Playgroud)

ruby smpp eventmachine redis

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

在ruby中创建一个函数

我在为Rails应用程序创建函数时遇到了一些问题.

我希望它像这样工作:

str = "string here"
if str.within_range?(3..30)
puts "It's withing the range!"
end
Run Code Online (Sandbox Code Playgroud)

为此,我将其添加到我的应用程序助手中:

def within_range?(range)
  if self.is_a?(String)
    (range).include?(self.size)
  elsif self.is_a?(Integer)
    (range).include?(self)
  end
end
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

undefined method `within_range?' for &quot;&quot;:String
Run Code Online (Sandbox Code Playgroud)

有谁知道问题是什么?

ruby ruby-on-rails function

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

在Windows 7下编译libyaml时编译错误

我想用MingW在Windows 7下编译libyaml.

我试图编译0.1.2和0.1.3但我收到此错误:

api.c:579: error: failure in redeclaration of 'yaml_token_delete': dllimport'd symbol lacks external linkage.
api.c:579: confused by earlier errors, bailing out
Run Code Online (Sandbox Code Playgroud)

还有其他人看过这个错误吗?你们和男士们都知道如何解决这个问题吗?

yaml compilation

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

使用rails创建一个包含数据库迁移的set列

我需要在数据库中的users表中添加一个新列.我想要设置列的类型.该列表示用户性别.该集应该有两个选项.一种形式男性"m",另一种形式为女性"f".

但是我没有找到任何添加具有set类型的列的文档.

我怎样才能做到这一点?

ruby database migration ruby-on-rails

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