在我的 rails 应用程序中,我需要从另一个控制器调用一个表中定义的方法。有两个表名为坐标和推文。推文表的条件由坐标表决定。在我的最终视图中,我需要显示推文表的属性,其条件由坐标表决定。我的坐标表代码
  class Coordinates<ActiveRecord::Base
      def self.query()
        a = Coordinates.where("city=?", params[:show])
        b = a.first
        if a.count == 1
          latitude = b.latitude
          longitude= b.longitude
          if(latitude=0 && longitude=0) then
            return  sql="Select * from tweets where tweet_text LIKE '%text%' AND user_loc LIKE '%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 '%show%') ) order by id desc"
               else
                 return   sql="Select * from  tweets where tweet_text LIKE  '%text%'"
               end    
          end
        end
我的推文表
class Tweets<ActiveRecord::Base
  attr_accessible  :id, :tweet_created_at, :tweet_id, :tweet_text, :tweet_source, :user_id, :user_name, :user_sc_name, :user_loc, :user_img, :longitude, :latitude, :place, :country
end
我需要从我的 tweets_controller 调用查询定义,以便它决定从 tweets 表中获取什么查询并在最终视图中显示。但是 params 函数在 model.rb 文件中不起作用。我想要这样的东西 我的 tweets_controller.rb
class TweetsController<ApplicationController
  def index
    Coordinates.query()
  end
end
我的最终视图代码
<%= @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 %>
我无法从 tweetscontroller 调用坐标表中定义的查询函数。我也尝试使用辅助方法,但这似乎没有帮助,而且听起来很复杂。任何人都可以帮助我