在My rails应用程序中,我有两个控制器,分别是tweets_controller和coordinates_controller。在我的最终视图中,我想使用coordinate_controller中的条件显示tweets_controller的属性。我面临的问题是tweets_controller应该知道coordinates_controller的变量。 我的coordinates_controller如何定义在rails中使用其他控制器变量的方法3
def CoordinatesHelper.query()
a = Coordinates.where(city: params[:show])
b = a.first
if a.count == 1
latitude = b.latitude
longitude= b.longitude
end
if(latitude=0 && longitude=0)
sql="Select * from tweets where tweet_text LIKE '%text%' AND user_loc LIKE 'show' order by id desc LIMIT 30"
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
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 LIMIT 30"
else
sql="Select * from tweets where tweet_text LIKE '%text%' LIMIT 30"
end
end
end
我tweets_controller只显示鸣叫表。采用在tweets_controller.The条件,例如纬度定义“索引”的属性,东经来自坐标表,是代码有没有办法通过其中tweets_controller将能够评估坐标表的纬度,经度,然后在最终视图中显示推文。确切地说,坐标控制器在搜索按钮中具有变量纬度,经度和城市,以及params [:show]。 tweets_controller应该可以访问coordinates_controller的属性。我应该怎么做?
<%= @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 %>
这是最后的观看内容,并显示此,纬度和经度的条件在坐标表
通过包含此关联并在tweets_controller中使用coordinates_controller的帮助器方法,可以访问tweets _controller中的坐标吗? – user2492854