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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:18:45+00:00 2026-06-16T20:18:45+00:00

I need to read more Ruby theory I have been told, which is fine

  • 0

I need to read more Ruby theory I have been told, which is fine but most literature I read is explained at a very high level and I don’t understand it. So this leads me to the question and my code

I have a module that deals with my api call

module Book::BookFinder

BOOK_URL = 'https://itunes.apple.com/lookup?isbn='

def book_search(search)
response = HTTParty.get(BOOK_URL + "#{search}", :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json' })
results = JSON.parse(response.body)["results"]
end
end

and then my controller

class BookController < ApplicationController
before_filter :authenticate_admin_user!
include Book::BookFinder

def results
results = book_search(params[:search])
@results = results
@book = Book.new
@book.author = results[0]["artistName"]

end

def create
@book = Book.new(params[:book])
 if @book.save
redirect_to @book, notice: 'Book was successfully saved'
 else
render action:new
end
end
end

What I want to do is save the author value to my Book model. I get the error message

undefined method `new' for Book:Module

when conducting a search which in a previous post has been explained to me. A module cannot be instanced. The solution was to make a class? but maybe I am not understanding correctly as I am not sure where to put this class. The solution given to me was

 class Book
  def initialize
   # put constructor logic here
  end

 def some_method
 # methods that can be called on the instance
 # eg:
 # @book = Book.new
 # @book.some_method
 end

# defines a get/set property
  attr_accessor :author
# allows assignment of the author property
end

Now I am sure that this is a valid answer, but could anyone explain what is going on? Seeing an example with an explanation is more beneficial to me than reading lines and lines of text in a book.

  • 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-16T20:18:46+00:00Added an answer on June 16, 2026 at 8:18 pm
    module Finders
    
      ## Wrap BookFinder inside another module, Finders, to better organise related
      ## code and to help avoid name collisions
      ## lib/finders/book_finder.rb
      module BookFinder
        def bar
          puts "foo"
        end
      end  
    end
    
    
    ## Another BookFinder module, but this one is not wrapped.
    ## lib/book_finder.rb
    module BookFinder
      def foo
        puts 'bar'
      end
    end
    
    
    ## Book is a standard Rails model inheriting from ActiveRecord
    ## app/models/book.rb
    class Book < ActiveRecord::Base
      ## Mixin methods from both modules
      include BookFinder
      include HelperLibs::BookFinder
    end
    
    ## app/controllers/books_controller.rb
    class BookController
      def create
        book = Book.new
        book.foo
        book.bar
    
      end
    end
    
    
    BookController.new.create
     - bar
     - foo
    

    In your code you are creating a module and a class with the same name – this is not allowed. The module overrides the class since it is loaded second.

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

Sidebar

Related Questions

I need more information about the Jruby on rails framework. I have read a
I've been looking to read some ruby code(specifically Rails) but I don't want to
I have read more than 3 questions here in stackoverflow about this, but all
I need to read test.TXT file(tab delimited) into MATLAB. TXT file have form: Datum
I need to read the size of a file but the server is forcing
I need to delete an application (MyApp.app), which has read only permissions in all
I know that there have been plenty of topics describing this topic but I
I need to read more than 1 file rtf files and assigned to Richtextbox
I want to have a read more section that expands without linking to another
I need your help with doing a Read More feature for my website. Contents

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.