# Help building view to pass query to controller

**URL:** <https://www.ruby-forum.com/t/help-building-view-to-pass-query-to-controller/134175>\
**Category:** Rails\
**Created:** [April 8, 2008, 4:56pm UTC](https://www.ruby-forum.com/t/help-building-view-to-pass-query-to-controller/134175 "2008-04-08T16:56:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jasonb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a587f6/32.png) [@jasonb](https://www.ruby-forum.com/u/jasonb)\
**Post date:** [April 8, 2008, 4:56pm UTC](https://www.ruby-forum.com/t/help-building-view-to-pass-query-to-controller/134175/1 "2008-04-08T16:56:12Z")

</div>

I am very new to programming and would like to configure the following:

I want to configure a page that displayes some graphs. These graphs  
pull its data from a sql table. What I would like to do is configure a  
view .erb to have a search field that will take text and inject it to  
part of a pre-configured sql query I have setup in a model. I will try  
to explain as best I can with code.

Specifically I would like to set a view form that will take the text and  
pass that text value to the class vars i have defined (@@hostname,  
@@start\_time and @@end\_time). Once the VARs have user inputted values  
the code will run and result to display. I think I am going to be  
dealing with form\_tags adn I have attemped this way but with no luck.  
I hope I explained this correctly as again I am a programming newbie.  
Thanks in advanced for any input.

Model:

class Health \< ActiveRecord::Base  
def self.sql\_select\_graph(hostname, start\_time, end\_time)  
connection.execute(“set @c = 0”)  
find\_by\_sql(“select \*, @c FROM healths WHERE router\_hostname =  
‘#{hostname}’ AND created\_at \>= ‘#{start\_time}’ AND created\_at \<= ‘#{  
end\_time}’ HAVING (@c:=@c+1)%12=0 ORDER BY id”)

end  
end

Controller:

class BandwidthController \< ApplicationController  
@@hostname = ‘cps-6-elem-2790-rtr-01’  
@@start\_time = ‘2008-04-04 17:000:00’  
@@end\_time = ‘2008-04-04 18:00:00’  
…  
…  
def rtr\_bandwidth

g = Graph.new  
@f = Health.sql\_select\_graph(@@hostname, @@start\_time, @@end\_time)

…  
…  
end
