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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:21:52+00:00 2026-06-04T11:21:52+00:00

EDIT2: [SOLVED] The create method in the controller file does not end until after

  • 0

EDIT2: [SOLVED] The “create” method in the controller file does not “end” until after the “edit” method. I can’t answer my own question until 8 hours afterwards, however.

EDIT: It’s been brought to my attention that this may be a problem with my routes.rb file. Which is just below.

routes.rb

SimpleCms::Application.routes.draw do

  root :to => "subjects#list"

  match ':controller(/:action(/:id))(.:format)'
end

Essentially this is an @instance_variable issue. More specifically an @instance_variable[:id => nil] problem. Somehow I’m passing a nil (null) :id (primary key) value to rails but the edit button which I’m clicking on (the last file in this list is the list.html.erb file which contains the button that takes you to edit.html.erb) is supposed to be passing the :id value corresponding to the given subject on the list page.

So here is the error message from the browser first of all:

 RuntimeError in Subjects#edit

Showing C:/Users/davo/Desktop/RailsProjects/simple_cms/app/views/subjects/edit.html.erb     where line #6 raised:

Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil,     use object_id
Extracted source (around line #6):

3: <div class="subject edit">
4:   <h2>Update Subject</h2>
5: 
6:   <%=  form_for(:subject, :url => {:action => 'update', :id => @subject.id}) do |f| %>
7: 
8:       <table summary="Subject form fields">
9:         <tr>
Rails.root: C:/Users/davo/Desktop/RailsProjects/simple_cms

Application Trace | Framework Trace | Full Trace
app/views/subjects/edit.html.erb:6:in     `_app_views_subjects_edit_html_erb__829468061_51428148'
Request

Parameters:

{"id"=>"1"}

Here is the controller (“subjects_controller.rb”) so you can see the instance variable stuff. The edit and update methods are on the bottom
**All the other methods which call params[:id] are working. It’s possible that there is nothing wrong with the controller and that it’s just the view. In particular, on that view, the @subject versus :subject versus subjects.method stuff…there seems to be something wrong with that syntax.

class SubjectsController < ApplicationController

  def list
    @subjects = Subject.order("subjects.position ASC")
  end

  def index
    list
    render('list')
  end

  def show
    @subject = Subject.find(params[:id])
  end

  def new
    @subject = Subject.new(:name => 'default')
  end
  def create
    #instantiate a new object using form params
    @subject = Subject.new(params[:subject])
    #save the subject
    if @subject.save
      redirect_to(:action => 'list')
      #if save succeeds redirect to list action
    else
      #if save fails, redisplay form
      render('new')
    end
  def edit
    @subject = Subject.find(params[:id])
  end
  #passing an @instancevariable inside of a {hash}...is there anything odd about that?
  #I'm just trying to inspire you guys -->
  #
  #I have a hunch that the :syntax/@syntax/#{etc} involving params, :id and
  #:subject could be the root of this issue...just a hunch
  #
  def update
    #Find object using form parameters
    @subject = Subject.find(params[:id])
    #Update the object
    if @subject.update_attributes(params[:subject])
      redirect_to(:action => 'show', :id => @subject.id)
    else
      render('edit')
    end
  end
  end
end

Lastly, here is edit.html.erb

<%= link_to("<< Back to List", {:action => 'list'}, :class => 'back-link') %>

<div class="subject edit">
  <h2>Update Subject</h2>

  <%=  form_for(:subject, :url => {:action => 'update', :id => @subject.id}) do |f| %>

      <table summary="Subject form fields">
        <tr>
          <th>Name</th>
          <td><%= f.text_field(:name) %></td>
        </tr>
        <tr>
          <th>Position</th>
          <td><%= f.text_field(:position) %></td>
        </tr>
        <tr>
          <th>Visible</th>
          <td><%= f.text_field(:visible) %></td>
        </tr>
      </table>
      <tr>
        <td><%= f.submit 'Update Subject' %></td>
      </tr>
  <% end %>
</div>

EDIT:
here is the list.html.erb file, which contains the link that points to the edit.html.erb file, which, currently, does not open and displays the error message.

<html>
    <div class="subject list">
      <h2>Subjects</h2>

      <!--- header row with all the different attributes --->
      <table class="listing" summary="Subject list">
        <tr class="header">
          <th>#</th>
          <th>Subject</th>
         <th>Visible</th>
          <th>Pages</th>
          <th>Actions</th>
        </tr>
        <!-- this is the beginning of a loop, that ends way down there -->
        <% @subjects.each do |subject| %>
        <tr>
          <td><%=  subject.position %></td>
          <td><%=  subject.name %></td>
          <td class="center"><%= subject.visible ? 'Yes' : 'No' %></td>
          <td class="center"><%=  subject.pages.size %></td>
          <td class="actions">
            <%=  link_to("Show", {:action => 'show', :id => subject.id}, :class => 'action show') %>
            <%= link_to("Edit", {:action => 'edit', :id => subject.id}, :class => 'action edit') %>
            <%=  link_to("Delete", '#', :class => 'action delete') %>
          </td>
            <% end %>
        </tr>
        </table>
        <%= button_to "Create New Subject", {:action => 'new'}, {:class => "buttonTo"} %>
    </div>
</html>

EDIT:
– Let me know if you need to see a particular model.rb file. In my models folder I have “subject.rb”, “section.rb”, “section_edit.rb”, “page.rb” and “admin_user.rb” if you need to see any of those. I’m kind of stumped on this one so maybe they’d be useful. They all contain a bunch of schema (has_many, belongs_to, etc) instructions and a few custom console calls.

  • 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-04T11:21:54+00:00Added an answer on June 4, 2026 at 11:21 am

    I made a typo when doing the some of the def/end syntax in the controller. I think it was ‘def create’, I didn’t end it.

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

Sidebar

Related Questions

edit: Solved - mod_rewrite was the problem I can't get CI to work as
EDIT: solved it, turns out I should use %c not %s because foodSelect and
[EDIT: Problem solved. Please see my answer below.] In my app I call the
edit #2: Question solved halfways. Look below As a follow-up question, does anyone know
Edit: I have solved this by myself. See my answer below I have set
Answer solved in edit below I had this piece of code Dictionary<Merchant, int> remaingCards
Edit: This has since been solved. Thanks to everyone who helped. Invoking the method
EDIT: Problem solved! After cleaning and rebooting it just disappeared! I don't know what
Edit : Solved, there was a trigger with a loop on the table (read
Edit: Solved. Hi, I'm starting with Qt, I try to connect a slot to

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.