A Kali
A Kali

Reputation: 1

Rails Search result issue

I am trying to create a search function in Rails 4. I have it implemented properly and it is displaying the result I want, however it is also returning and displaying the entire database query - All columns from table including password digest etc. I have done this before but haven't run into an issue like this. Would like to know if I am doing something wrong.

here is my controller:

def index
    if params[:search]
        @pro = Admin.search(params[:search])
    else
        @pro = Admin.all
    end
end

Admin Model:

def self.search(search)
    if search
        where('name LIKE ?', "%#{search}%")
    else
        scoped
    end
end

And here is my views:

<%= @pro.each do |ind| %>
<ul>
    <li><%= ind.name %></li>
</ul>
<% end %>

in Chrome, I see the returned name of the individual from the search, as I would like, plus meta data such as id: 1, admin_id: 2, name "", email: "", password_digest: "" etc. in an array format. This is what's stumping me, not sure why it's displaying this.

When I inspect the page in chrome, the array is just pasted right under the tags.

It goes away when I remove the entire .each method on @pro. Any insight anyone can provide is appreciated.

Upvotes: 0

Views: 52

Answers (1)

eugen
eugen

Reputation: 9226

The line in view should be <% @pro.each do |ind| %>. If you're doing <%= %> the result is the actual @pro array, which is why you're getting it pasted under the tags.

Upvotes: 4

Related Questions