-1

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

4

1 回答 1

0

在您的查询方法中,您编写了 finder 方法,但是您在那里写了表名,而不是模型名称,finders 对模型名称起作用,这样写:

在您的查询方法中替换此:

@a=Coordinates.find("city=?", params[:show])

有了这个 :

@a=Coordinate.find("city=?", params[:show])

因为模型名称始终保持单数,除非您更改任何配置。我认为,你的 params[:show] 有问题。请粘贴'params [:show]'的结果

希望它会有所帮助。谢谢

于 2013-07-25T12:44:08.837 回答