2017-06-25 14 views
0

私はRails 5でサイトを作成していますが、データベース内の記事を検索する方法に問題があります。データを表示する際に問題はありません。記事、タイトルや説明のための参照が、私は画像に示すように、ドライバが作成するオブジェクトのデータを表示したくない:Rails 5にオブジェクトデータを表示しない

enter image description here

マイコントローラ:

class PagesController < ApplicationController 
    skip_before_filter :verify_authenticity_token #Para usar metodo post 
    before_action :authenticate_usuario!, except: [:index,:show,:miperfil,:inicio] 

    def search 
    respond_to do |format| 
     if params[:busqueda].strip != "" #si hay solo espacios no busca nada 
     @busqueda = params[:busqueda] 
     puts "\nIngreso al metodo de búsqueda..." 
     @rposts = Post.where("titulo like ?", "%#{@busqueda.downcase}%").order(created_at: :desc) 
     format.html { render :busqueda } 
     else 
     format.html { render :inicio, success: 'Por favor ingresa una palabara para la búsqueda.' } 
     end 
    end 
    end 
end 

私の見解:

<div class="panel panel-primary"> 
    <div class="panel-heading"> 
     <h2>Resultados para <i style="color: wheat;">"<%= @busqueda %>"</i></h2> 
    </div> 
    <div class="panel-body"> 
     <br> 
     <h4 class="h4class" style="color: wheat">Articulos encontrados: <%= @rposts.size %></h4> 
     <% if @rposts.size > 0 %> 
      <%= @rposts.each do |post| %> 
       <%= link_to post do %> 
        <h5><%= post.titulo %>.</h5> 
       <% end %> 

       <p><small><%= content_with_emoji(truncate(post.contenido.html_safe, :length => 250)) %></small></p> 
       <% if (post.contenido.length > 250) %> 
        <%= link_to "Ver más", post%> 
       <% end %> 
       <hr> 
      <% end %> 
     <% end %> 
    </div> 
</div> 

答えて

0

あなた@rposts変数の上に適用しているeachイテレータから=を削除します。

<% @rposts.each do |post| %> 
    ... 
<% end %> 
+0

ああ、あなたが正しい、ありがとう! – dlvngn

関連する問題