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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:41:39+00:00 2026-06-06T07:41:39+00:00

I created an application , which Users can create a Topic and other can

  • 0

I created an application , which Users can create a Topic and other can post their comments about the topic. I can create a topic now and post.form work but when i post a comment i get

NoMethodError in Posts#create 

undefined method `each' for nil:NilClass

Extracted source (around line #2):

1: 
2: <% for topic in @topics do %>  
3:   <li><%=link_to topic.title, topic_path(topic) %></li>  
4: 
5:  <%= will_paginate @topics %>

My posts controller is :

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


    def create
        @post = current_user.posts.build(params[:post])
        if @post.save
            flash[:success] = "Konu oluşturuldu!"
                redirect_to topic_path(topic)
        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

When i create a post it redirects to localhost/posts … although i want it to stay in that topic . How can i correctly redirect?

  • 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-06T07:41:41+00:00Added an answer on June 6, 2026 at 7:41 am

    I think it is better and a lot more concise to use @topics.each do instead of for topic in @topics do.

    Basically, in your create action, it seems that you aren’t assigning @topics any value. So it will be nil. No defined method exists for trying to enumerate over nil, that is why ruby starts looking into the method_missing method of Nil class. Having not found any handling there, the following exception is generated.

    I’d recommend you to assign some value to @topics

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

Sidebar

Related Questions

I am writing an application , which User can create Topics and others can
I'm working on an android application which allows users to create accounts on a
I am attempting to write a VB.net application which will allow users to create
I'm trying to create a simple web-application, which allows users create topics and comment
I created a Ruby on Rails application (2.3.9) where users can record workouts. I
I want to create logins & users for my c#.net winforms application which uses
I want to create an application where users can mark on map location of
In my web application, users can post text to a feed, and the text
In my application using CanCan I have permissions where users can view and create
Some background: I've created a Swing application which uses the Substance LaF (Thanks again,

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.