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

  • Home
  • SEARCH
  • 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 7185177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:21:33+00:00 2026-05-28T18:21:33+00:00

My system has the following associations set up: class Book < ActiveRecord::Base has_many :

  • 0

My system has the following associations set up:

class Book < ActiveRecord::Base
has_many : suggestions
has_many : comments
has_many : references

On the Show view of my Book model, I want to give user an option to choose (from a drop box) the view they would like to see. So for example if a user selects suggestions from this drop box then the partial reloads with the suggestions. Similarly for the other 3 options.
In order to achieve this, I wrote the following method in my Model, book.rb:

def self.select_content_type(content_type)
case content_type

when "suggestions"
  # get the suggestions
  @book_suggestions = Book.suggestions.paginate(:per_page => 6, :page => params[:page])
  # return this
  return @book_suggestions

when "comments"
  # get the comments
  @book_comments = Book.comments.paginate(:per_page => 6, :page => params[:page])
  # return this
  return @book_comments

when "references"
  # get the references
  @book_references = Book.references.paginate(:per_page => 6, :page => params[:page])
  # return this
  return @book_references

end

end

I am trying to access this method in the “Show” action of my book_controller.rb as follows:

@book_content = Book.select_content_type(params[:content_type])

In the Show view, I have the following form to make a get request to this method:

   - form_tag  book_path(@book), :id=>"select_rel_form", :remote => true, :method => 'get' do               
      = text_field_tag :content_type, params[:content_type], :id=>"select_rel_type"
      = submit_tag "submit", :name => nil, :class=>"select_rel_submit"  

And in a partial named *_content* I am accessing the value returned as follows:

- if !@book_content.nil?
  - @issue_relations.each do |relation|
    ...

I get the following error:

NoMethodError (undefined method `suggestions' for #<Class:0x1177f4b8>):
app/models/book.rb:93:in `select_content_type'
app/controllers/books_controller.rb:21:in `show'

Kindly help me understand how I can fix this. If there’s a correct and better way to achieve this, please guide me. 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-05-28T18:21:34+00:00Added an answer on May 28, 2026 at 6:21 pm

    Your form tag has select_content_type and as it says it’s undefined, but there you should have something like book_path(@book)

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

Sidebar

Related Questions

I'm trying to build a modified role system that has the following class/relationship structure:
I have tried the following code but has no effect: Imports system.Runtime.InteropServices <DllImport(UxTheme.DLL, BestFitMapping:=False,
This has been driving me nuts. I keep getting the following exception System.InvalidOperationException: The
I have the following problem: Our system has products that when released only are
Dear all, My system has the following distribution details $ lsb_release -a No LSB
I have a 'Comments' MySQL table that has the following fields: id text parent_id
IEqualityComparer in the namespace System.Collections.Generic has following methods: bool Equals(T x, T y); int
assuming that you have the following sentence in a requirements document The system has
I have some legacy code with linq2sql classes. DataContext class has following definition for
I has this following code to show a VideoView on top of anything that

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.