커뮤니티 has_many CommunityTopics
community_topics_controller.rb # show를로드하면 다음과 같은 오류가 발생합니다. 왜?? (예 : http://example.com/shop/walmart/topic/12)
아니야 @community_topic ???중첩되어있을 때 show action이 잘로드되지 않는 이유
라우팅 오류 없음 경로 일치 {: 컨트롤러 => "community_topics" : community_id => 전무}
내 코드는
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_top ICS/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
모델/community.rb
def to_param
"#{community_name}"
end
올바른 코드 조각을 제공하셨습니까? 제 말은 : resources : communities, : path => "shop", do는 구문 오류 메시지를 출력해야합니다 (마지막 쉼표로 인해). – jdoe