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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:38:45+00:00 2026-06-17T18:38:45+00:00

I am trying to follow the episode #258 Token Fields (revised). I don’t know

  • 0

I am trying to follow the episode #258 Token Fields (revised). I don’t know how the code create authors, I have a feeling that is related to the code below, but I am not sure.

Please can you explain how the code create authors?

in /app/models/book.rb

def author_tokens=(tokens)
    self.author_ids = Author.ids_from_tokens(tokens)
end

Link to episode http://railscasts.com/episodes/258-token-fields-revised?view=asciicast

Thanks!

  • 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-06-17T18:38:46+00:00Added an answer on June 17, 2026 at 6:38 pm

    This code doesn’t actually create the author. The authors themselves need to already be created. This code will take the author’s tokens, and turn those into IDs. So the Book will have many authors.

    You can see in this image below, the authors already exist as the book is being created. We are selecting from the book

    choosing image

    image credit: http://railscasts.com/episodes/258-token-fields-revised?view=asciicast

    UPDATE

    In the end of the episode, the system will create new authors if one is not found. This is created by this code: https://github.com/railscasts/258-token-fields-revised/blob/master/bookstore-tokeninput-after/app/models/author.rb

      class Author < ActiveRecord::Base
        ##...
        def self.ids_from_tokens(tokens)
          tokens.gsub!(/<<<(.+?)>>>/) { create!(name: $1).id }
          tokens.split(',')
        end
      end
    

    So, if the tokens come in with <<>> (which gets sent from the Author.tokens method), it will create the author and then get the ID and return it.

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

Sidebar

Related Questions

I'm trying to follow the steps to compile some C code to import into
I'm trying to follow a tutorial on NodeJS. I don't think I missed anything
So I was trying to follow http://developer.android.com/guide/topics/media/camera.html to create a simple app that captures
Trying to follow some basic examples and getting stuck by this code that is
I've been trying to follow the tutorial here: http://www.edu4java.com/en/androidgame/androidgame2.html But have hit a snag.
I'm trying to follow along with the code example for data binding to a
I have been trying to follow StyleCop's guidelines on a project, to see if
I have been trying to follow this tutorial: Tutorial I can't get past page
I have been trying to follow the guidelines in this Microsoft article to authenticate
I'm trying to follow this tutorial - http://www.dotnetcurry.com/ShowArticle.aspx?ID=231&AspxAutoDetectCookieSupport=1 I have both the vsdoc file

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.