0

所以我現在搜索了一段時間的表單,到目前爲止,我嘗試過的很多修復都讓我失望了一個兔子洞。這就是說,我試圖看看我剛剛創建的故事,但是當我去看看它時,我得到錯誤 「ActiveRecord :: RecordNotFound(找不到與'id'=」namegoeshere「的故事) 」。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

Solv有些幫助感謝這種困境將不勝感激。

如果需要了解更多信息,請告訴我。

+0

您使用什麼URL訪問故事頁面? –

+0

我在哪裏查看視圖的鏈接點可能不正確。你可以發佈該鏈接的視圖的相關部分嗎? – SteveTurczyn

+0

添加了我點擊@SteveTurczyn的視圖 –

回答

0

所以這個錯誤是兩倍,第一部分友好的ID寶石是什麼導致我收到ActiveError消息。第二部分是我用我的應用程序使用elasticsearch,我的用戶/故事不是索引。因此,每次我發佈故事時,我的應用程序都無法找到彈性搜索嘗試查找友好ID的用戶/故事ID(又名友好ID)。所以我加入友好的方法,

def show 
@story = Story.friendly.find(params[:id]) 
end 

然後我手動運行elasticsearch索引每個表我想搜索。

bundle run rake elasticsearch:import:model Class='User' Force=y 

一旦這兩件事情完成,一切都終於運行良好。

值得注意的是,我在Windows平臺上構建了應用程序,因此如果我在哪裏構建了它在Apple或Linux上運行,我可能必須做更多的事情。

相關問題