Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7679697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:56:16+00:00 2026-05-31T17:56:16+00:00

I have created model, controller and view with rails scaffold generator: rails g scaffold

  • 0

I have created model, controller and view with rails scaffold generator:

rails g scaffold Todo description:string tags:array

So I have the model:

class Todo
  include Mongoid::Document
  field :description, :type => String
  field :tags, :type => Array
end

And controller:

def create
    @todo = Todo.new(params[:todo])
    @todo.save

But this case (auto-generated code) I get error that tells me something like:

tags field must be array datatype, but you're trying to use string

So I have fixed the controller:

def create
    #@todo = Todo.new(params[:todo])

    @tmp = params[:todo]
    @tmp["tags"] = @tmp["tags"].split(',')
    @todo = Todo.new(@tmp)

And I’m just wondering if there is any better way to fix my error?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T17:56:17+00:00Added an answer on May 31, 2026 at 5:56 pm

    Depends on how your view is structured. From what I see, there must be a single text input or something, into which you input tags, separated by comma. No wonder it comes as a string! In this case your workaround is correct. I would add stripping of leading and trailing whitespace, though.

    @tmp["tags"] = @tmp["tags"].split(',').map(&:strip)
    

    To get a real array in params your HTML must look like this:

    <input type='text' name='tags[]' />
    <input type='text' name='tags[]' />
    <input type='text' name='tags[]' />
    

    Where each of these inputs holds a single tag.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created model, view and controller: $ rails generate scaffold Post name:string title:string
Using: Rails 3.1.1 I have a controller/model/view called Category that is built up on
if i have created a view model and have a partial form that is
I am developing a Rails v2.3.2 app. I have a Model with validations: class
I have a controller called articles , which creates the articles model which gets
I have a model called Details, and two controller methods new and create. New
I have created a Dynamic Data site against an Entity Framework Model I have
I have an Entity Data Model that I have created, and its pulling in
I have a DateTimeField called created in my model and I would like to
I have a sqlite DB created by my CoreData model automatically, but my app

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.