similar to: find_by_sql + partials question

Displaying 20 results from an estimated 4000 matches similar to: "find_by_sql + partials question"

2006 Jan 19
2
NOOB: Using locals to pass data to a SQL query
I want to show a users entries based on there login id. I have tried this: View: <div id="myfish"> <%= render :partial => ''myfish'', :locals => {:user => session [:user].id } %> </div> Partial: <% for entry in @entries %> <table border ="0" CELLSPACING="0"> <tr class="<%= alternate
2006 Jan 12
0
[file_column] Problem displaying images after upload
This is the last major hurdle in my little app and I can''t seem to figure it out. I am using file_column to upload images. The upload (and rmajick goodness) works just fine, but when I try to display the resulting image I get this error: undefined method `image_relative_path'' for #<Array:0x252b694> In script/console I can do this however:
2006 Jan 19
8
I can''t figure out how to solve this one
I am creating an application to run a fishing tournament (see http:// www.ruby-forum.com/topic/51209 for a little background) Now I am running into an issue trying to calculate a leader board. each participate can enter multiple fish but only the largest fish per a given species counts towards the overall score. My entries table looks like this:
2010 May 07
1
undefined method 'find_by_sql'
Why would I get an undefined method `find_by_sql'' for #Example: 0x981a4e4> for error when trying to use the find_by_sql method in my model? def init_dictionaries tables = find_by_sql( "SHOW TABLES FROM thesaurus" ) @@tables = tables.collect{ |t| t.Tables_in_thesaurus } end -- You received this message because you are subscribed to the Google Groups "Ruby
2006 Jan 26
1
Help constructing a find_by_sql command
Hello all. I am trying to do the equivalent of: @componentlogs = Componentlog.find(:all, :conditions => [ "cl_compname like ?", @criteria ], :offset => offset, :limit => items_per_page, :order => "cl_spr DESC" ) in a find_by_sql statement. I cannot use the build in because the adaptor isn''t quite right (OCI8) When I use it I get the following error
2007 Jan 20
2
find_by_sql with named parameterized sql
I tried to use named parameters in my SQL query , using find_by_sql Order.find_by_sql ([select * from orders where amount > ? and quantity > ?", [ @amount, @quantity ] works;.. but Order.find_by_sql ([select * from orders where amount > :amount and quantity > :quantity ", [ :amount => @amt, :quantity => @qty ] is not working a I wrong or should I use a plain select
2006 Jun 30
0
find_by_sql not quoting properly (in acts_as_taggable plugin)
I have run into a very strange problem discovered through the use of the acts_as_taggable plugin, but related to quoting/sanitizing the interpolated list in a find_by_sql. Apologies for the length, but I wanted to be complete. ;-) The method from acts_as_taggable.rb is: def find_tagged_with(list) find_by_sql(["SELECT #{table_name}.* FROM #{table_name}, tags,
2007 Aug 14
1
find_by_sql vs connection.select_all
I was trying to do SUM based mySQL query simliar to the following: SELECT SUM(updated_on - created_on) AS total from signups If I were to run this command in the mySQL console I would get a result. However, if I were to run it using the following command in Rails: Signup.find_by_sql("SELECT SUM(updated_on - created_on) AS total from signups") The query that is written to the log is:
2006 Sep 01
3
find_by_sql with :include?
When you use find, you can include related objects with include so that both objects get instantiated in the results, e.g. Foo.find(:all, :include => :bar). But when you use find_by_sql, is there a way to do this? You could definitely write the find_by_sql SQL to join Foo and Bar tables: Foo.find_by_sql("SELECT foo.*, bar.* from foo, bar where foo.bar_id = bar.id") But is there a
2006 Jan 30
1
find_by_sql and memcached
Is a find_by_sql query cached with memcached and cached_model (http://dev.robotcoop.com/Libraries/)? Looks like the answer is no. Is there a reason for this? I have a lot of very complicated querys with a lot of unions, subquerys and joins that would greatly benefit from the cache. Going through the code I can see that the find_by_sql method is changed in cached_model.rb, but it does not call
2008 Jun 23
1
Find_by_sql Doesn't Return Attributes?
My find_by_sql is not returning attributes of the calling model class. Thermo.find_by_sql("SELECT COUNT(*) FROM thermo WHERE thermo_loc = ''back'' GROUP BY DAYOFWEEK(time_on) ASC") # ==> [#<Thermo >, #<Thermo >, #<Thermo >, #<Thermo >, #<Thermo >, #<Thermo >, #<Thermo >] The sql is fine and when I checked it in a mysql
2006 Apr 20
1
Returning Count from find_by_sql
I want to return an int from a find_by_sql call. But when I use that result to compare to another count the error tells me I have an array. MODEL: # Returns the number of comments in a specified post def self.find_count(post_id) find_by_sql(["SELECT COUNT(*) FROM commments WHERE post_id = ?", post_id]) end CONTROLLER: def test @post =
2010 May 25
1
find_by_sql timestamp parameter
Hi In controller I have this query: @price_stat = Price.find_by_sql("select id, cost, tour_id, unix_timestamp(created_at) from prices") when I try to display result''s created_at column I don''t have any results: <% @price_stat.each do |p| %> <p><%= p.created_at %></p> <% end %> result is empty But if I try without unix_timestamp. ie:
2006 Jan 31
2
find_by_sql question
I''m no good at SQL and I have a question that will hopefully be fairly easy to answer. I''m using acts_as_paranoid which instead of deleting a record adds a deleted_at column with the datetime the row was deleted. I want to have a find_by_sql filter out any row where deleted_at is not null. I have (at least the relevant parts): #a couple working filters here. filters <<
2006 Nov 04
0
How to paginate a find_by_sql query?
Does anybody know how to paginate a find_by_sql query? Unfortunately I need to paginate a query which is next to impossible for ActiveRecord or just too much of a pain to implement. So I''m using find_by_sql. However, I anticipate a large number of rows returned eventually. So I may need paginate. Does anyone know how? Thanks Phillip Novess http://primalart.net
2009 Apr 06
0
find_by_sql returns Strings! How to I type cast?
When i run find_by_sql the extra fields not in the Model are returned as Strings. What is the correct way to convert all the extra fields to their correct type? Is there a way to somehow define these extra fields in the Model class to ensure they will always be returned correctly? Or is their a better method. I will be using find_by_sql a lot so a clean solution would be good. (I am using
2009 Sep 16
3
find_by_sql - multiple selects, same statement SQL error
I''m trying to get the following statement to work using variable substitution (it works if hard-code the where (med_type) param in the inner SQL statement): med_type = ''game'' @mediaformats = MediaFormat.find_by_sql("select * from media_formats where media_formats.media_type_id = (select media_type_id from media_types where media_type = ?, :med_type) order by
2011 Aug 25
3
ActiveRecord searching in batch (with find_by_sql)
I have an issue where I am getting a large number of records from the database and I cant afford to keep it in the memory due to performance issues. Therefore using the following would be ideal, User.find_each(:batch_size => 5000, :start => 2000) do |user| NewsLetter.weekly_deliver(user) end however, I would like to use find_by_sql since my query is user defined. Question is, is it
2006 Oct 02
2
when to use find_by_sql
I have a bunch of queries to compute some counters, like find_by_sql(<<-SQL SELECT p.*, c.nfavourites FROM people p, ( SELECT fp.person_id, COUNT(fp.user_id) as nfavourites FROM favourite_people fp, users u WHERE fp.user_id = u.id AND u.cluster = ''#{in_cluster_of_user.cluster}'' GROUP BY fp.person_id ) as c WHERE
2005 Oct 28
4
find_by_sql column types
Hello-- There must be a better way to do this. I have a class method in my model that finds averages and does a few calculations using find_by_sql. The problem I¹m encountering is that all computed columns from MySQL come back as type string. E.g., def self.find_averages(domain_id) if @@domain_average return @@domain_average else @@domain_average =