Ruby on Rails, how to define methods that should be ued in two controllers -


in rails app have 2 controllers namely coordinates_controller , tweets_controller. problem facing have definitions , arguments both controllers using. value returned coordinates controller used tweets controller. there method sort out?

my coordinates_controller code

class coordinatescontroller<applicationcontroller    def paramas(b)      @b = params[:show]     return @b    end   def coor(latitude,longitude)     @latitude=0     @longitude=0   end    def search   @a=coordinates.where(city: params[:show]).take     if(params[:show]== a.city)        @latitude= a.latitude       @longitude=a.longitude     end     if(@latitude=0 && @longitude=0)     return  @sql="select * tweets tweet_text '%search%' , user_loc 'a.paramas' order 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 * tweets tweet_text '%search%' , ( ((longitude between min_lng , max_lng) , (latitude between min_lat , max_lat)) or (user_loc 'a.paramas') ) order id desc"          else         return   @sql="select *  tweets tweet_text  '%search%'"          end          end   end         #  a= coordinatescontroller.new 

end tweets_controller.rb

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 

i know code total mess. dunno how use helper methods , modules. can tell me how sort can use methods in more 1 controller can use returned values?

i searched in rails guides , tutorials. saw other tutorials couldn't find solution. please me this. in advance.

use helper methods

put search method in application.helper or other helper(suppose have searchhelper

then in controller add

include : searchhelper 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -