In my rails app I need to implement a conditional search form .There are two tables named tweets and coordinates , but the output is showing a blank page and I am stuck up with dis. my coordinates_controller
class CoordinatesController < ApplicationController
def home
end
# def paramas(b)
#
# @b = params[:show]
# return @b
end
#def coor(latitude,longitude)
# @latitude=0
#@longitude=0
#end
def query
@a=Coordinates.find("city=?", params[:show])
if(params[:show]= a.city) then
latitude= a.latitude
longitude=a.longitude
end
if(latitude=0 && longitude=0) then
return sql="Select * from tweets where tweet_text LIKE '%text%' AND user_loc LIKE 'params[:show]' order by id desc"
else if (latitude!=0 && longitude!=0)
min_lat = latitude - 1.0
max_lat = latitude + 1.0
min_lng = longitude - 1.0
max_lng = longitude + 1.0
return sql = "Select * from tweets where tweet_text LIKE '%text%' AND ( ((longitude BETWEEN min_lng and max_lng) AND (latitude BETWEEN min_lat and max_lat)) OR (user_loc LIKE 'params[:show]') ) order by id desc"
else
return sql="Select * from tweets where tweet_text LIKE '%text%'"
end
end
end
My Tweets_controller class TweetsController < ApplicationController
include CoordinatesHelper
def search
render 'tweets/search'
end
def index
# include CoordinatesHelper
sql=query
@tweets=Tweets.paginate_by_sql(sql, :page => @page, :per_page => @per_page )
#render 'tweets/index'
end
end
my view code for the search button
<%=form_tag({controller: 'tweets', action:'index'}, method: "get") do %>
<%=label_tag(:search, "Search for:") %>
<%=text_field_tag(:text) %>
<%=label_tag(:show, "Show for:") %>
<%=text_field_tag(:show) %>
<%= submit_tag( "GO" ) %>
<% end %>
my view code to display the results
<%= will_paginate @tweets %>
<% @tweets.each do |tweets| %>
<ul>
<li><%= tweets.id %></li>
<li><%= tweets.tweet_created_at %></li>
<li><%= tweets.tweet_source %></li>
<li><%= tweets.tweet_text %></li>
<li><%= tweets.user_id %></li>
<li><%= tweets.user_name %></li>
<li><%= tweets.user_sc_name %></li>
<li><%= tweets.user_loc %></li>
<li><%= tweets.user_img %></li>
<li><%= tweets.longitude %></li>
<li><%= tweets.latitude %></li>
<li><%= tweets.place %></li>
<li><%= tweets.country %></li>
</ul>
<% end %>
But for some reasons the output is showing an empty page tried editing several tymes but in vain. Anybody kindly help me wid dis, I am struggling wid dis from a long tym