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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:58:42+00:00 2026-06-13T22:58:42+00:00

I am trying to finish an application which User can open a Topic and

  • 0

I am trying to finish an application which User can open a Topic and other Users can comment with Posts. I nested my resources in routes.rb:

resources :users

resources :sessions, only: [:new, :create, :destroy]
resources :topics, only: [:show, :create, :destroy] do

resources :posts

my rake routes show :

    topic_posts GET    /topics/:topic_id/posts(.:format)          posts#index
                POST   /topics/:topic_id/posts(.:format)          posts#create
 new_topic_post GET    /topics/:topic_id/posts/new(.:format)      posts#new
edit_topic_post GET    /topics/:topic_id/posts/:id/edit(.:format) posts#edit
     topic_post GET    /topics/:topic_id/posts/:id(.:format)      posts#show
                PUT    /topics/:topic_id/posts/:id(.:format)      posts#update
                DELETE /topics/:topic_id/posts/:id(.:format)      posts#destroy
         topics POST   /topics(.:format)                          topics#create
          topic GET    /topics/:id(.:format)                      topics#show

In my homepage, I build a clickable list of Topics and a textarea which you can open a topic. Now if you click a Topic link, i want it to show you the page which shows Topic name in the top, Posts below and a Post form under it in the same page.
show.html.erb :

<div class="row">
<div class="span6 offset4">
    <h3><%= @topic.title %></h3>
    <h4><%= render 'shared/posts'%></h4>
<%= render 'shared/post_form' %>
</div>
</div>
</div>

my posts_controller is :

# encoding: utf-8

class PostsController < ApplicationController
    before_filter :signed_in_user, only: [:create, :destroy]
  before_filter :correct_user, only: :destroy

    def new
        @topic= Topic.find_by_id(params[:id])
        @post = @topic.build_post
    end

    def show
    @topic = Topic.find(params[:id])
    @posts = @topic.posts.paginate(page: params[:page])
  end 

    def create
        @topic = Topic.find(params[:id])
        @post = @topic.posts.build(params[:post])
        if @post.save
            flash[:success] = "Konu oluşturuldu!"
            redirect_to root_path
        else
            render 'static_pages/home'
        end
    end

  def destroy
    @post.destroy
    redirect_to root_path
  end
  private

    def correct_user
      @post = current_user.posts.find_by_id(params[:id])
      redirect_to root_path if @post.nil?
    end
end

and _posts.html.erb :

%  @posts.each do |post| %>  
  <li><%= post.content %></li>  

 <%= will_paginate @posts %>
<% end %>  

_post_form.html.erb :

<%= form_for([@topic, @post]) do |f| %>
  <%= render 'shared/error_messages', object: f.object %>
  <div class="field">
        <%= f.text_area :content, placeholder: "yorumunuzu girin..." %>
  </div>
  <%= f.submit "Gönder", class: "btn btn-large btn-primary" %>
<% end %>

The error is in _post_form.html.erb as =>

undefined method `model_name' for NilClass:Class

Extracted source (around line #1):

1: <%= form_for([@topic, @post]) do |f| %>
  • 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-13T22:58:42+00:00Added an answer on June 13, 2026 at 10:58 pm

    You don’t have an @post variable in the show action of your controller (only @posts).

    Try adding:

    @new_post = @topic.build_post
    

    and changing the form to:

    <%= form_for([@topic, @new_post]) do |f| %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to finish my forum application. I want arrange user Friendships. I
I am trying to finish writting my news/blog ASP.net C# application and I am
I am trying to finish a project. I am working with user models. When
I am creating a multi-user iPhone app, and I am trying to finish up
I am creating a multi-user iPhone app, and I am trying to finish up
I'm trying create a RCP Application with Eclipse, but I can't get past the
I am basically trying to return from a method which reads user input from
In the application,I am trying to a make activity show when user opens the
In my application I am trying to open an activity from a button in
I'm trying to finish my class which extends FragmentActivity from a static method:- private

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.