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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:18:49+00:00 2026-05-24T09:18:49+00:00

I have a (rails 3) application that allows users to query for books. I

  • 0

I have a (rails 3) application that allows users to query for books. I have three models: query, result, book with a has_many :through relation both ways:
query has many books through result
and
book has many queries through results

When I enter a query and click OK, I get a form to create a book using the query phrase. I want the books_controller#create to use the query id to create a result with book_id = the book’s id and query_id = the passed in query’s id. The form looks as follows:

<%= form_for(@book) do |f| %>

  <div class="field">
    <%= f.label :title %><br />
    <%= f.text_field :title %>
  </div>
  <div class='field'>
 <%= f.hidden_field :query_id, :value => @query_id%>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

And in the books controller, I have:

def create
    @book = Book.new(params[:book])
    query = Query.find(params[:query_id])
    if(@book && query)
      result = Result.new
      result.book = @book
      result.query = query
      result.save!
      ...
    end
end

On submitting this form, I get the error:

ActiveRecord::UnknownAttributeError in BooksController#create

unknown attribute: query_id

(on line @book = Book.new(params[:book])

My question is: how do I pass through the query id to the book creation action so I can construct the result record there?

Update: Found a solution: I used the form_for with url to pass in the param instead of form field as follows:

<%= form_for(@book,:url => {:action => 'create',:query_id => @query.id}) do |f| %>

Is there a better way to do this?

Thanks
Anand

  • 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-24T09:18:50+00:00Added an answer on May 24, 2026 at 9:18 am

    You should use hidden_field_tag instead of f.hidden_field as query_id as not a attribute of Book model.

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

Sidebar

Related Questions

I have a really simple Rails application that allows users to register their attendance
I have built a Ruby on Rails application that allows users to track their
I have a Ruby on Rails application that allows for users to create a
I have built a Ruby on Rails (2.3.8) application that allows users to track
I have a fairly simple Rails application that allows users to manage their clients
I have a Rails application that allows users to import information from various sources
I have a rails application that allows searches using longitude and latitude. I have
I have made a simple Rails application that allows people to comment on posts.
I have built a custom administration panel into a Rails application that allows content
Building a rails B2B application that will have various users. I'm pretty clear on

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.