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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:14:57+00:00 2026-06-16T17:14:57+00:00

Community has_many CommunityTopics When it loads community_topics_controller.rb # show, it gives error like this.

  • 0

Community has_many CommunityTopics
When it loads community_topics_controller.rb # show, it gives error like this. Why??
(Example: http://example.com/shop/walmart/topic/12 )
It’s not getting @community_topic???

Routing Error No route matches {:controller=>”community_topics”,
:community_id=>nil}

My codes are

community_topics_controller.rb #show

  def show
    @community_topic = CommunityTopic.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @community_topic }
    end
  end

views/community_topics/show.html.erb

<%- model_class = @community_topic.class -%>
<div class="page-header">
  <h1><%=t '.title', :default => model_class.model_name.human %></h1>
</div>

<dl class="dl-horizontal">
  <dt><strong><%= model_class.human_attribute_name(:community_id) %>:</strong></dt>
  <dd><%= @community_topic.community_id %></dd>
  <dt><strong><%= model_class.human_attribute_name(:user_id) %>:</strong></dt>
  <dd><%= @community_topic.user_id %></dd>
  <dt><strong><%= model_class.human_attribute_name(:title) %>:</strong></dt>
  <dd><%= @community_topic.title %></dd>
  <dt><strong><%= model_class.human_attribute_name(:body) %>:</strong></dt>
  <dd><%= @community_topic.body %></dd>
  <dt><strong><%= model_class.human_attribute_name(:community_topic_icon_file_name) %>:</strong></dt>
  <dd><%= @community_topic.community_topic_icon_file_name %></dd>
  <dt><strong><%= model_class.human_attribute_name(:community_topic_icon_content_type) %>:</strong></dt>
  <dd><%= @community_topic.community_topic_icon_content_type %></dd>
  <dt><strong><%= model_class.human_attribute_name(:community_topic_icon_file_size) %>:</strong></dt>
  <dd><%= @community_topic.community_topic_icon_file_size %></dd>
  <dt><strong><%= model_class.human_attribute_name(:community_topic_icon_updated_at) %>:</strong></dt>
  <dd><%= @community_topic.community_topic_icon_updated_at %></dd>
  <dt><strong><%= model_class.human_attribute_name(:deleted_at) %>:</strong></dt>
  <dd><%= @community_topic.deleted_at %></dd>
</dl>

<div class="form-actions">
  <%= link_to t('.back', :default => t("helpers.links.back")),
              community_topic_index_path(@community), :class => 'btn'  %>
  <%= link_to t('.edit', :default => t("helpers.links.edit")),
              edit_community_topic_path(@community, @community_topic), :class => 'btn' %>
  <%= link_to t('.destroy', :default => t("helpers.links.destroy")),
              community_topic_path(@community, @community_topic),
              :method => 'delete',
              :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')),
              :class => 'btn btn-danger' %>
</div>

routes.rb

resources :communities, :path => "shop", do
    resources :community_topics, :path => "topic", :as => :'topic'
end

models/community.rb

def to_param
  "#{community_name}"
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-06-16T17:14:58+00:00Added an answer on June 16, 2026 at 5:14 pm

    I don’t see you assigning a @community variable yet you’re using it in your show.html.erb, so your path helpers are receiving a nil instead of an id.

     def show
       @community = Community.find params[:community_id]
       @community_topic = CommunityTopic.find params[:id]
       # the rest of the action
     end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Community has_many CommunityTopics It shows form of CommunityTopics When I access to example.com/shop/WALMART/topic/new and
I have 2 Models. Community CommunityTopic Community has_many CommunityTopics But what if I want
Why does this code return an error? Is it because my association from Community
User has_many :communities has_many :posts Community belongs_to :user has_many :posts Post belongs_to :user belongs_to
I've been full of questions lately, but thanks to this awesome community, I'm learning
unique_code belongs_to :community unique_code belongs_to :user user has_many :unique_codes community has_many :unique_codes I want
I am trying to show the number of users who has the community's uniquecode.
This is my first SO post. I'm eternally grateful for the information this community
Note: A have asked this question at the Superuser community first , but since
I heard about this community while listening to Hypercritical and I am excited 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.