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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:25:56+00:00 2026-06-13T04:25:56+00:00

I have an app where I know def new respond_to do |format| format.html {

  • 0

I have an app where I know

def new 
    respond_to do |format|
      format.html { new_or_edit }
      format.js { 
        @category = Category.new
      }
    end  
end

is being called when I click a link.

This leads to new_or_edit being called (defined in the same file).

  def new_or_edit
    @categories = Category.find(:all)
    @category = Category.find(params[:id])
    @category.attributes = params[:category]
    if request.post?
      respond_to do |format|
        format.html { save_category }
        format.js do 
          @category.save
          @article = Article.new
          @article.categories << @category
          return render(:partial => 'admin/content/categories')
        end
      end
      return
    end
    render 'new'
  end

After some tests, I find that the each execution stops at

@category = Category.find(params[:id])

with the error “Couldn’t find Category without an ID”. Params doesn’t have an :id hash when I printed it out. Is this because I have to save it into the database before the default :id field is created?

  • 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-13T04:25:58+00:00Added an answer on June 13, 2026 at 4:25 am

    What you are doing wrong is trying to unify two inherently different actions: new and edit.

    params is a hash of parameters you get from the client.

    When you create a new object, params[:id] is left blank since the id attribute of a newly created object is the responsibility of the server, not the client.

    When you edit an existing object, params[:id] is not blank since the object already exists in the database and has an id. The meaning of params[:id] here is “Please edit object with id param[:id] using these attributes”.

    After explaining this, when you create a new object this line:

    @category = Category.find(params[:id])
    

    Fails since params[:id] is empty.

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

Sidebar

Related Questions

I have an android app it displays web view.I want know the app idle
I don't know if this is possible, but we have an app that has
I have a BlackBerry app running in the background that needs to know when
I have a BlackBerry app running in the background that needs to know when
I know the app servers like Websphere and Weblogic have remote deployment capabilities that
I know that after I have deployed my ipad/iphone app into App Store, it
I have a class library that has settings within an app.config. I know that
In views.py I have the following view which gets called when a new user
we have app hosted on google app engine for java. In this app we
I have app.config in m win application, and loggingConfiguration section (enterprise library 4.1). I

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.