2013-07-17 21 views
1

在我的軌道應用程序中我有兩個控制器座標和鳴叫和他們的表分別。我有兩個文本字段在我的搜索按鈕,我需要從鳴叫表中獲取查詢座標表中的條件。但是我得到這個錯誤「nil:NilClass」的未定義方法`參數'。 我coordinates_controller.rb未定義的方法`參數'爲零:軌道3中的NilClass 3

class CoordinatesController<ApplicationController 

     def paramas(b) 

     @b = params[:show] 
     return @b 

     end 
     def coor(latitude,longitude) 
     @latitude=0`enter code here` 
     @longitude=0 
     end 

     def search 
     @a=Coordinates.where(city: params[:show]).take 
     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 '%search%' AND user_loc LIKE 'a.paramas' 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 '%search%' AND (((longitude BETWEEN min_lng and max_lng) AND (latitude BETWEEN min_lat and max_lat)) OR (user_loc LIKE 'a.paramas')) order by id desc" 
      else 
      return @sql="Select * from tweets where tweet_text LIKE '%search%'" 
      end  

     end 
     end  

    # a= CoordinatesController.new 
     end 

class TweetsController<ApplicationController 
require 'coordinates_controller.rb' 
#require 'models/coordinates.rb' 

    def index 
#include 'coordinates_controller.rb' 
    a= CoordinatesController.new 
    @sql=a.search 
    @tweets=Tweets.paginate_by_sql(sql, :@page, :per_page => @per_page).all 
    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(:search) %> 
<%= text_field_tag(:show) %> 
<%= submit_tag("get results ") %> 
<% end %> 

我的看法代碼,以顯示鳴叫

%= will_paginate @tweets %> 
<% @tweets.each do |tweets| %> 
<ul> 
<li><%= tweets.id %></li> 
<li><%= tweets.tweet_created_at %></li> 
<li><%= tweets.tweet_id %></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> 
<% end %> 
</ul> 

蔭堅持了這個很長一段時間有人請幫助我繼續。提前THKS

+0

你能發佈錯誤嗎?或指定它打破哪一行 – Debadatt

+0

該代碼是一個混亂..未使用的方法參數,錯誤的縮進,包括1控制器在另一..如果你需要使用超過1控制器的方法,將其移動到幫手 – sircapsalot

+0

@Debadatt iam在coordinates_controller的第15行和tweets_controller的第8行出現錯誤。@ sircapsalot我應該如何繼續獲取輸出。請幫助我 – user2492854

回答

1

建議: 安裝開發的寶石better_errors:https://github.com/charliesome/better_errors

有了它,你會在瀏覽器中得到一個不錯的控制檯時,你的代碼失敗。 所以,如果我在那裏你,我會插入一些代碼假:

#include 'coordinates_controller.rb' 
    a= CoordinatesController.new 
    @sql=a.search 
    @tweets=Tweets.paginate_by_sql(sql, :@page, :per_page => @per_page).all 
    likethisboguscodeBLABLABLA 
    end 
end 

爲了確保該行後失敗,則在控制檯,檢查@tweets等實際上是對象等等。重複每一個可能導致此問題的關鍵代碼行。

相關問題