小编val*_*ecx的帖子

在Active Record Callback中验证日语字符

我有一个需要验证半宽和全宽日文字符的日文项目,半宽度允许14个字符,全宽度允许7个字符.

有没有人知道如何实现它?

现在我的模特

class Customer
   validates_length_of :name, :maximum => 14
end
Run Code Online (Sandbox Code Playgroud)

不是一个好选择

我目前正在使用ror 2.3.5可以使用全宽和半宽

ruby validation ruby-on-rails cjk rails-activerecord

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

用于#<ActionDispatch :: Http :: UploadedFile:0x0000000d3f7778> carrierwave的未定义方法`remove_previously_stored_files_after_update'

我正在使用rails 4进行图像上传,但是我有问题让它工作.

undefined method `remove_previously_stored_files_after_update' for #<ActionDispatch::Http::UploadedFile:0x0000000d3f7778>
Run Code Online (Sandbox Code Playgroud)

有人可以帮我解决这个问题吗?

以下是完整的跟踪:

carrierwave(0.10.0)lib/carrierwave/mount.rb:233:在store_previous_model_for_image' activesupport (4.2.3) lib/active_support/callbacks.rb:430:inmake_lambda 中的 块'activesupport(4.2.3)lib/active_support/callbacks.rb:162:在call' activesupport (4.2.3) lib/active_support/callbacks.rb:162:in块中停止'activesupport(4.2.3)lib/active_support/callbacks.rb:502:在 call' activesupport (4.2.3) lib/active_support/callbacks.rb:502:in 调用块中'activesupport(4.2.3)lib/active_support/callbacks.rb:502:在each' activesupport (4.2.3) lib/active_support/callbacks.rb:502:in调用'activesupport(4.2.3)lib/active_support/callbacks.rb:88:in run_callbacks' activerecord (4.2.3) lib/active_record/callbacks.rb:310:in_update_record 'activerecord(4.2.3)lib/active_record/timestamp.rb:70:in _update_record' activerecord (4.2.3) lib/active_record/persistence.rb:504:increate_or_update'activerecord(4.2.3)lib/active_record/callbacks.rb:302:in block in create_or_update' activesupport (4.2.3) lib/active_support/callbacks.rb:115:incall'activesupport(4.2.3)lib/active_support/callbacks .rb:115:在call' activesupport (4.2.3) lib/active_support/callbacks.rb:553:in编译中的块(2级)'activesupport(4.2.3)lib/active_support/callbacks.rb:503:incall' activesupport (4.2.3) lib/active_support/callbacks.rb:503:in调用'activesupport(4.2.3)lib/active_support/callbacks.rb:88:in run_callbacks' activerecord (4.2.3) lib/active_record/callbacks.rb:302:increate_or_update'activerecord(4.2.3)lib/active_record/persistence.rb:120:在save' activerecord (4.2.3) lib/active_record/validations.rb:37:insave'activerecord(4.2.3)lib/active_record/attribute_methods/dirty.rb:21:在save' activerecord (4.2.3) lib/active_record/transactions.rb:286:inblock(2级)中保存'activerecord( 4.2.3)lib/active_record/transactions.rb:351:在block in …

ruby-on-rails carrierwave

5
推荐指数
0
解决办法
428
查看次数

查询多个数据库最佳解决方案

我有8个数据库与相同的表

db0
  tbluser |  id  |    name

db1
  tbluser |  id  |    name

db2
  tbluser

db3
   tbluser |  id  |    name

db4
   tbluser |  id  |    name

db5       
   tbluser |  id  |    name

db6       
   tbluser |  id  |    name

db7
   tbluser |  id  |    name
Run Code Online (Sandbox Code Playgroud)

我有another table dbcommon用户信息保存的地方

dbcommon
   message  |  id  |  sender_id  |  recipient_id
Run Code Online (Sandbox Code Playgroud)

我的问题是我需要根据发件人ID和收件人ID查询其中包含用户名的所有邮件

在mysql上执行此操作的最佳方法是什么?

我现在的方法是将所有db1和db7用户数据组合使用union然后内部连接到dbcommon中的消息但是我不确定是否可以,如果我在用户表选择和联合上有数百万的数据会是一个麻烦.

为了更好地理解我的问题.我做了这个,但我不会用它.

select *, sender.nickname as sender_name, recipient.nickname as recipient_name
from dbcommon.message m
inner join
(
select * from db0.tbluser …
Run Code Online (Sandbox Code Playgroud)

mysql

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

如何调用类型T的方法传递T作为字符串或"T"

我有类似的东西

public void FunctionName<T>(){

}
Run Code Online (Sandbox Code Playgroud)

并称之为你需要这样的东西

sub main(){
    FunctionName<Integer>();
}
Run Code Online (Sandbox Code Playgroud)

我的问题是我可以将整数作为"整数"传递吗?

sub main(){
    FunctionName<"Integer">();
}
Run Code Online (Sandbox Code Playgroud)

或者还有其他方法

好的,这是我的实际代码

private static T Convert<T>(DataRow row) where T : new()
{
    T model = new T();
    Type modelType = model.GetType();
    FieldInfo[] fields = null;
    FieldInfo field = default(FieldInfo);
    Type fieldType = null;
    string fieldName = null;

    fields = modelType.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Static);

    foreach ( field in fields) {
        fieldType = field.FieldType;
        fieldName = field.Name.Replace("_", string.Empty);
        Interaction.CallByName(model, fieldName, Microsoft.VisualBasic.CallType.Set, GetValue(row, fieldName, fieldType.Name)); …
Run Code Online (Sandbox Code Playgroud)

c#

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