【发布时间】:2016-10-04 20:25:26
【问题描述】:
所以我已经搜索了一段时间的表格,到目前为止,我尝试过的很多修复都让我陷入了困境。话虽这么说,我正在尝试查看我刚刚创建的故事,但是当我去看它时,我得到了错误 “ActiveRecord::RecordNotFound(找不到带有 'id'="namegoeshere" 的故事)”。
然后它指向我的 stories_controller 用于“显示”
def show
@story = Story.find(params[:id])
@responses = @story.responses.includes(:user)
@related_stories = @story.related_stories
if request.path != story_path(@story)
redirect_to @story, status: 301
end
end
我不清楚这里会发生什么,因为我认为
@story = Story.find(params[:id])
会列出所有的故事。这是我的路线
resources :users, only: [:show, :edit, :update] do
resources :recommended_stories, only: [:index]
end
resources :stories, except: [:index] do
resources :responses, only: [:create]
end
此 show.html.erb 文件中的部分
<div class="sidebar-top-stories">
<ul>
<% @dashboard.top_articles.each_with_index do |story, index| %>
<li class="top-articles-list-item">
<div class="count-button-wrapper">
<span class="count-button"><%= index + 1 %></span>
</div>
<div class="top-articles-links">
<%= link_to story.title, story, class: 'story-title' %><br/>
<small>
<%= react_component("PopoverLink", { user_id: story.user.id, url: user_path(story.user), children: story.username }) %>
</small>
</div>
</li>
<% end %>
</ul>
</div>
在模型故事中
extend FriendlyId
friendly_id :title, use: [ :slugged, :history, :finders ]
这是 cmd Story.find_each(&:save) 的日志 logs
感谢您帮助解决这个难题。
如果需要更多信息,请告诉我。
【问题讨论】:
-
您使用什么 URL 来访问故事页面?
-
where I go to see view处的链接可能不正确。您可以将视图的相关部分发布在该链接所在的位置吗? -
添加了我点击@SteveTurczyn的视图
-
@AlexandreAngelim 添加了查看文件
-
@ChrisLewis 您是否在 Story 模型上覆盖了 #to_param?
标签: ruby-on-rails activerecord heroku elasticsearch rails-activerecord