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 6686635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:11:40+00:00 2026-05-26T05:11:40+00:00

I collect tags in a nice javascript UI widget. It then takes all the

  • 0

I collect tags in a nice javascript UI widget. It then takes all the tags and passes them to the server as tag1,tag2,tag3,etc in one text_field input. The server receives them:

params[:event][:tags] = params[:event][:tags].split(',') # convert to array
@event = Event.find(params[:id])

Is there a better way to convert the string to the array? It seems like a code smell. I have to put this both in update and in the new actions of the controller.

  • 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-26T05:11:40+00:00Added an answer on May 26, 2026 at 5:11 am

    you could do this in the model:

    I have seldom experience on mongoid. The following would work in active record (the only difference is the write_attribute part)

    class Event
      def tags=(value_from_form)
        value_from_form = "" unless value_from_form.respond_to(:split)
    
        write_attribute(:tags, value_from_form.split(','))
      end
    end
    

    On the other hand, for consistency, you may want to do the following:

    class Event
      def tags_for_form=(value_from_form)
        value_from_form = "" unless value_from_form.respond_to(:split)
    
        self.tags = value_from_form.split(',')
      end
    
      def tags_for_form
        self.tags
      end
    
      # no need to change tags and tags= methods. and tags and tags= methods would return an array and accept an array respectively
    end
    

    In the first case (directly overwriting the tags= method), tags= accepts a string but tags returns an array.

    In the second case, tags_for_form= and tags_for_form accepts and returns string, while tags= and tags accepts and returns array.

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

Sidebar

Related Questions

ok so i collect the variable below through javascript. var frameState = $(this).attr('id'); I
I'm using selenium-client to test a site. I want to get all a tags
I have something like this: <p> <b>Tags:</b> <%if @post.tags.count > 0%> <%= @post.tags.collect {|c|
For example, I have a bunch of <tr> tags I'd like to collect. I
My goal is to collect all images urls with jquery that are inserted in
I would like to collect all css/js resources in a controller. This would result
I collect a few corner cases and brain teasers and would always like to
I collect statistics on IP addresses from where users visit my site and I
Let's collect some tips for evaluating the appropriate use of global.asax.
I added google-collect-1.0.jar to my Android project and it made a 50K .apk into

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.