4

I feel like this should be obvious, but I just cannot find it in the documentation.

I am using rails_admin to build a simple CMS.

Consider this:

 config.model Article do
    list do
      field :title
      field :created_at
      field :updated_at
    end
    edit do
      field :title
      field :description do
        required true #this line is pseudo code! What is the real thing?
        maxlength 600 #ditto this line
      end
    end
  end

How do I turn those two lines of pseudo-code into real marks of "required" and "maxlength"?

4

1 回答 1

6

要获得所需的输出,您的配置应如下所示:

config.model Article do
  list do
    field :title
    field :created_at
    field :updated_at
  end
  edit do
    field :title
    field :description, :string do  #use second parameter to set field type
      required true #this will just set a hints text
      #to set max length use:
      html_attributes do
       {:maxlength => 600} #dont use 600 as maxlength for a string field. It will break the UI
      end
    end
  end
end
于 2013-10-24T01:25:35.257 回答