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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:56:45+00:00 2026-05-13T15:56:45+00:00

I have tried to set up a separate section of my app using a

  • 0

I have tried to set up a separate section of my app using a subdirectory called controlpanel to manage various parts of the site.

I’ve set up the namespace in my routes.rb

map.namespace :controlpanel do |submap|
    submap.resources :pages
    # other controllers
end

And placed the controller and views into the relevant subdirectories.

Controlpanel::PagesController

  def new 
    @page = Page.new
  end

  def create
    if @page = Page.create_with_author(current_user, params[:page])
      flash[:notice] = 'Page was successfully created.'
      redirect_to ([:controlpanel, @page])
    else
      render :action => 'new'
    end
  end

Using this mixed in class method

def create_with_author(author, params)
    created = new(params)
    created.author = author
    if created.save
      created
    end
  end

And the view (controlpanel/pages/new.html.erb renders a partial called _form

<%= render :partial => 'form' %>

Which is as follows:

<% semantic_form_for([:controlpanel, @page]) do |form| %>
    <% form.inputs do %>  
    <%= form.input :title %>
    <%= form.input :body %>
    <% end %>
    <%= form.buttons %>
  <% end %>

If I fill in the form correctly, it works as expected, redirecting me to the new page, however, if I leave fields blank, violating the validation constraints, I get the following error:

RuntimeError in Controlpanel/pages#create

Showing app/views/controlpanel/pages/_form.html.erb where line #1 raised:

Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id

Can anyone see what is going wrong?

I’m using the formtastic plugin to create the form, but it still happens if I use a regular form.

Any advice greatly appreciated.

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-13T15:56:46+00:00Added an answer on May 13, 2026 at 3:56 pm

    Given that the create action is called and new is rendered, Page.create must evaluate to nil.

    You probably want to pass params[:page] to create.

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

Sidebar

Related Questions

I want to achieve this using html and css: I have tried to set
I have tried setting the debug flags using the set command in cmake but
All right so I tried using the button set. So fair, I have been
I have tried the obvious SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED, but my
I have tried this but it doesn't work: tell application Preview set myfile to
I have created a button in my Android application & I tried to set
I've tried almost everything. In my nginx.conf I have rails_env set to production in
I have tried to set up combo boxes in the gridview but all the
I have a section of code where I call a set of results with
I have separate models for Devise users and admins. I am also using Basecamp

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.