2015-09-16 22 views
2

嗨我在我的模型中使用简单的表单文本字段。创建完成后,我将添加最好的编辑和更新。现在我想给这个特定领域的最大和最小长度,请帮助我如何继续下去。如何将文本字段范围设置为rails中的best_in_place?

我需要最好的文字包装

感谢您的提前。

batchnotification.rb

class BatchNotification 
    include Mongoid::Document 
    include Mongoid::Timestamps 


    field :finalCount, type: Float 
    field :message, type: String 
    field :approved, type: Boolean 
    field :batch_id, type: Integer 
    field :user_id, type:Integer 


    validates_presence_of :approved 
    validates_presence_of :message 
    validates_length_of :message, :maximum => 5 


    belongs_to :batch 
    belongs_to :user 
    belongs_to :calculated_batch_counts 

end 

index.html.erb

<%= best_in_place notification, :message %> 

回答

0

验证:消息,长度:{最小:2}

+0

它不工作我已经使用这个sreeraj nyros – Kiran

2

可以尝试

html_attrs: html参数的哈希值,如maxlength。

<%= best_in_place :message, :html_attrs => {:maxlength => 50} %> 
+0

哇它的工作谢谢 – Kiran

+0

但我需要最佳到位自动换行 – Kiran

相关问题