I am trying to put a search (microposts) function into my app. All of the ways to do it involve giving the definition
@microposts=Micropost.search(params[:search])
or something like that. you always have to define @microposts in the microposts_controller.rb
The problem is that I already have
def home
@microposts=Micropost.all
end
because initially the home page is just a list of all microposts. How can I change the definition once the user uses the search function. Is that the only way? Do I need an if then statement.
like if they press search @microposts=Micropost.search(params[:search]) else @microposts=Micropost.all? how can I do that?
when the page is initially loaded, i guess the
params[:search]was not present. so you can try: