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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:32:27+00:00 2026-05-21T15:32:27+00:00

I have two models . Events and Questions. Event has many questions. I am

  • 0

I have two models . Events and Questions.
Event has many questions.
I am trying to create a new Question from the Events#show view .
The link comes out to be something like /events/:event_id/questions/new . But when clicked it gives errors –

undefined method `model_name' for NilClass:Class

I guess there is error either with my _form.html or the new method in Questions controller.

Can someone please help ?

Event.rb

class Event < ActiveRecord::Base

  has_many :questions

end

Question.rb

class Question < ActiveRecord::Base
   belongs_to :event

end

Routes.rb

resources :events do

    resources :questions 

end

Events – show.html.erb

<p> <%= link_to "Ask", new_event_question_path(@event) %> </p>

Question Controller

before_filter(:get_event)

  private
def get_event
    @event = Event.find(params[:event_id])
end

 def new
    @question = Question.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @question }
    end
  end

_form.html.erb

<%= form_for([@event,@question]) do |f| %>
  <% if @question.errors.any? %>
    <div id="error_explanation">

........
........
......
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>
  • 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-21T15:32:28+00:00Added an answer on May 21, 2026 at 3:32 pm

    you you have declared private in the beginning of the questions controller all that comes after that is also made private and your action new is also declared private cut it and paste it before the private and then try

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

Sidebar

Related Questions

I have two Models, Programme and Event, a programme has many events. I need
I have a rails site with two models: events and dates events has many
I have two models: Members and Events. A member can participe in many events
Let's say I have two models Event and Person . Many people attend an
I have two models: class Actor(models.Model): name = models.CharField(max_length=30, unique = True) event =
I have got two models, User and Event. I need two kind of relationship
I have two models: Program < ActiveRecord::Base has_many :events def federal_financing events.sum(&:federal_financing) end def
I have two models with the following relationship Event has_many :comments Comment belongs_to :event
I have two models (Event and UserProfile) in a ManyToMany relation. I want to
I have two models : class Event < ActiveRecord::Base belongs_to :destination end class Destination

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.