Search restaurant by city
In the previous section we were only showing restaurants in Chicago. If you noticed, it was hardcoded in the URL itself and was not generic. In this section we will make the application more generic and allow the user to search data based on a parameter city.
Update restro_controller.rb
as follows:
class RestroController < UITableViewController def viewDidLoad super @restaurants = [] searchBar = UISearchBar.alloc.initWithFrame(CGRectMake(0, 0, self.tableView.frame.size.width, 0)) searchBar.delegate = self; searchBar.showsCancelButton = true; searchBar.sizeToFit view.tableHeaderView = searchBar view.dataSource = view.delegate = self searchBar.text = 'Chicago' searchBarSearchButtonClicked(searchBar) end def searchBarSearchButtonClicked(searchBar) query = searchBar.text.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding) url = "http://restro.nalwaya.com/restaurants/search.json?city=#{query}" ...