Vahid Hashemi
Vahid Hashemi

Reputation: 5240

I've created a new action in rails but I don't know how to connect to an appropriate view

I have created a search action for an existing entity(model/controller/view) in RoR and the action works but the browser gives me error about missing template and now I want to add a template(view) for showing the result.

here is sketch-like of my website:

app/controller/items.rb <-- where I define an action called "search"

app/models/item.rb <-- where I define the search function

app/views/items/_search_result.html.haml <-- where I only copy a simple "hello world" in it and it doesn't work

and this is the function in model :

 def self.search(search)
   search_condition = "%" + search + "%"
   find(:all , :conditions => ['product_name LIKE ? or details LIKE ?',search_condition , search_condition])
 end

and this is the action in controller :

def search
  @item = Item.search params[:search]
end

how should I have another view for showing the result?

Upvotes: 1

Views: 27

Answers (1)

Mischa
Mischa

Reputation: 43298

Rename

app/views/items/_search_result.html.haml

to

app/views/items/search.html.haml

Upvotes: 2

Related Questions