Skip to content


Subversion checkout URL

You can clone with
Download ZIP


[mongoid] Devise string fields #1247

foohey opened this Issue · 4 comments

3 participants


I'm just playing with mongoid and trying RA.

Devise fields (email and all String fields) are interpreted as textarea in RA.

I've added a "name" field and he work as input.

user model:

HTML output:

<div class="control-group text_type email_field " id="user_email_field">
  <label class="control-label" for="user_email">Email</label>
  <div class="controls">
    <textarea cols="48" data-options="{}" data-richtext="false" id="user_email" name="user[email]" rows="3"></textarea>
    <p class="help-block">Obligatoire. </p>

This is by design, because there is no way to tell whether Mongoid's String type should be mapped to RailsAdmin :string type(which shows input field) or :text type(which shows textarea).
So RailsAdmin basically maps String to :text, except for fields named as 'name', 'title', 'subject'(listed here).

If you want 'email' field as input, you can explicitly set

RailsAdmin.config do |config|
  config.model User do
    configure :email, :string

in your RailsAdmin initializer.

@mshibuya mshibuya closed this

Since mongoid defaults data types to string I think rails_admin should follow suit. Any fields preferred to be a textarea should be explicitly defined.

Also I notice the mongoid adapter defines an artificial length of 255 in many cases. The mongoid string data type has no such limitation. rails_admin (IMO) should limit casting length restrictions to only cases where a user-defined length validation is defined.

Im still familiarizing myself with the rails_admin code base and this could be a considerable modifcation, but if its decided to be a good idea i can take a crack at it.

@mshibuya mshibuya reopened this

If we make string type as default, we lose ability to edit the data properly if the field has multi-lined string data. Is it OK for you?
I've chosen safer one because text type can also handle single-lined string data...

And I agree for an artificial 255-char upper limit, now that meaningless 'Length up to(blank).` help texts are fixed by your pull request.

Mongoid type-mapping logic needs to be cleaned up, for sure.


the support for multi-line fields would still be supported its just a matter of defaults. for me, i typically use far more fields intended for text inputs than textareas. form builders (like simple_form, or formtastic) generate input tags for string data types and need to be explicitly defined as a text area to support multi-line. i have found defaulting to an input is more common practice so the rails_admin behavior seems backwards to me. but its really just a matter of preference when it comes down to it.

As for the 255 limit, i dislike the idea of limiting an input at the presentation level and imposing it on the model. those limitations should only be represented rather than defined in the view.

@mshibuya mshibuya was assigned
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.