Right now in app/views/microposts/home.html.erb I have..
<% form_tag purchases_path, :method => 'get', :id => "products_search" do %>
<p>
<%= text_field_tag :search, params[:search] %>
<%= submit_tag "Search", :name => nil %>
</p>
<% end %>
<% form_tag sales_path, :method => 'get', :id => "sales_search" do %>
<p>
<%= text_field_tag :search, params[:search] %>
<%= submit_tag "Search", :name => nil %>
</p>
<% end %>
and then in micropost.rb I have
scope :purchases, where(:kind => "purchase")
scope :sales, where(:kind => "sale")
def self.search(search)
if search
where('name LIKE ?', "%#{search}%")
else
scoped
end
end
and then finally in the microposts_controller.rb I have
def home
@microposts=Micropost.all
@purchases=@microposts.collect{ |m| m if m.kind == "purchase"}.compact
@sales=@microposts.collect{ |m| m if m.kind == "sale"}.compact
end
edit:
I also tried using
def home
@microposts=Micropost.all
@purchases=@microposts.purchases
@sales=@microposts.sales
end
instead but then it gives me the error undefined method `purchases' for #
Anways,
Right now with the .collect method I am getting an error saying undefined local variable or method `purchases_path' and it does the same for sales_path.
What I want is to have TWO search forms. In my micropost table I have a column called kind which can be either "purchase" or "sale". How can I change my code so that one search form searches through and displays results for only those microposts with the kind "purchase". And then the other searches through and displays results for only those microposts with the kind "sale"