[Rails] Re: chaining relations break?

2013-12-05 Thread Fearless Fool
Matt: If you just want data rolled up for *one* Utility (I'm guessing that's what `u` in the code above is...) you could skip the group: sum = u.utility_data.sum(:ami_residential) You are spot on: in this case I'm just considering one Utility at a time. I don't know what possessed me to

[Rails] Re: chaining relations break?

2013-12-04 Thread Fearless Fool
Solved (though I'm not entirely sure why this works): UtilityDatum. select(sum(ami_residential)). where(:utility = u). group(utility_id). reorder(''). first The reorder() prevents the ORDER BY clause from being emitted, so the generated SQL is valid. -- Posted via

[Rails] chaining relations break?

2013-12-03 Thread Fearless Fool
The following works: r = u.utility_data.select(utility_id, sum(ami_residential)).group(utility_id) = #ActiveRecord::Relation [#UtilityDatum id: nil, utility_id: 5621] r.first[:sum] = 263 but when written as a one-liner: u.utility_data.select(utility_id,

[Rails] Re: chaining relations break?

2013-12-03 Thread Fearless Fool
BTW, I also tried this: UtilityDatum. select(sum(ami_residential)). where(:utility = u). group(utility_id). unscope(:order, :limit). first ... but that still tacks on ORDER BY and LIMIT clauses to the query, so it still fails. Evidently I don't understand unscope(). -- Posted via

[Rails] Re: rescue_from ActionController::RoutingError

2012-08-10 Thread Fearless Fool
This is posted years after the fact, but just in case anyone arrives via a web search: The rescue_from method shown above will NOT catch routing errors in Rails 3.1 and Rails 3.2. In particular, this won't work: # file: app/controllers/application_controller.rb class

[Rails] memory bloat quandary

2012-07-16 Thread Fearless Fool
[This is mostly an update on http://stackoverflow.com/questions/11447042/ (thanks Fred!), but I'll take my answer from wherever I can get it...] Short form: does the postgresql db adaptor cache queries? I'm passing lots of large raw SQL queries (160k bytes each), and my private virtual memory is

[Rails] Re: Re: where do I report this DateTime bug?

2012-06-25 Thread Fearless Fool
Colin Law wrote in post #1065800: What is the class of found? I updated the above mentioned gist. 'expected' is a DateTme, 'found' is ActiveSupport::TimeWithZone. Also I don't think you have told us which versions of ruby and rails you are using. Apologies, this was buried at the end of

[Rails] where do I report this DateTime bug?

2012-06-21 Thread Fearless Fool
I have isolated what appears to be a bug in the Rails extensions to DateTime, but I don't know where to report it. I have a standalone file to demonstrate the bug, but the punch line is that this code: TestRecord.create!(:f_datetime = (expected = DateTime.jd(200))) found =

[Rails] Re: where do I report this DateTime bug?

2012-06-21 Thread Fearless Fool
Can you post the contents of schema.rb section for the table. Also it would be interesting to put in some inspect debug for expected and found. Colin: Done. See https://gist.github.com/2967023 for code and results. As for inspect debug for expected and found, I assume you mean like this:

[Rails] Re: rake aborted

2012-06-21 Thread Fearless Fool
Walter Davis wrote in post #1065560: What version of rake, what version of Ruby, what version of Rails? Also, what version of Gem? ... Walter's right. This is just a hunch, but you might try: gem update --system and see if that helps. - ff -- Posted via http://www.ruby-forum.com/. --

[Rails] Re: where do I report this DateTime bug?

2012-06-21 Thread Fearless Fool
I've created: https://github.com/rails/rails/issues/6814 ... which seems like the correct place to report this. I'm sure I'll hear from the rails admin team soon enough if that's not the right place. - ff -- Posted via http://www.ruby-forum.com/. -- You received this message because

[Rails] design of bulk UPSERT (aka MERGE): update_or_insert

2012-06-18 Thread Fearless Fool
Stack Overflow and various forums are rife with questions about how to efficiently update or insert ActiveRecords into a table. (In fact, one of my earliest questions to this forum was on this very topic.) My recent work regularly calls for an efficient update or insert method for tens of

[Rails] Re: Re: rspec: identical tests fails when repeated

2012-04-06 Thread Fearless Fool
Colin Law wrote in post #1055228: On 6 April 2012 01:10, Fearless Fool li...@ruby-forum.com wrote: - the first test fails with response.message = Not Acceptable - the second test fails because count is not incremented. First look in test.log to see if there is any difference there, if still

[Rails] Re: rspec: identical tests fails when repeated

2012-04-06 Thread Fearless Fool
REDACTED! Okay, it's 100% my error. Ability#initialize IS getting called. The source of my woes: I was explicitly passing :user_id = 1001 to Premise#initialize, which was overriding the :user_id that CanCan was providing. It was bad luck (or bad judgement) that I chose 1001 as the id -- this

[Rails] rspec: identical tests fails when repeated

2012-04-05 Thread Fearless Fool
I'm doing RSpec controller testing with CanCan authorization, and I'm seeing something I've never seen in RSpec before: the same test run twice fails on the second one. I am NOT doing before(:all) or other things that should cause state to persist between tests: Here's the relevant code:

[Rails] Re: rspec: identical tests fails when repeated

2012-04-05 Thread Fearless Fool
UPDATE: I noticed that I had a rails console --sandbox running in another window. When I quit that, the behavior of the test changed. Dramatically. I haven't sorted through the new errors, but it's clear that the --sandbox process was causing the db to respond differently. -- Posted via

[Rails] Re: rspec: identical tests fails when repeated

2012-04-05 Thread Fearless Fool
MORE UPDATE: I beefed up the tests to look at the return code, the # of Premises generated and the assignment. And things only got stranger: context POST create do context with user logged in do before(:each) do @user = mock_model(User, :admin? = false, :guest? = false)

[Rails] Re: rescuing ActiveRecord::RecordNotUnique: clever or ugly?

2012-04-03 Thread Fearless Fool
Joe V. wrote in post #1053641: A SQL query takes around 1 ms, possibly more if the db server is on a different machine. That is way more expensive than rescuing an exception. Joe: Thanks for the useful data point. Just to make sure my understanding is complete, since any db transaction is

[Rails] one master table to hold symbols: good or bad idea?

2012-04-03 Thread Fearless Fool
(This is may be more of a db design question than a rails question.) Summary: I'm thinking of creating a single AR class to hold constant symbol values and use it for :has_many_through relations whenever I need a constant symbol. Is this a good idea or a bad idea? Details: I notice that I

[Rails] Re: rescuing ActiveRecord::RecordNotUnique: clever or ugly?

2012-04-03 Thread Fearless Fool
Let me redact that previous post...my only excuse is that I hadn't had my coffee yet! If the time to make a DB query (let's call it 1 Unit of time) swamps out any amount of processing in Ruby, then: Approach A (do a SELECT to check for existence of the record before attempting an insert) will

[Rails] Re: one master table to hold symbols: good or bad idea?

2012-04-03 Thread Fearless Fool
Tim Shaffer wrote in post #1054854: What problem are you trying to solve by doing this? Just seems like it would make your code more complicated with no real benefit. DRYer code: this approach has fewer distinct tables, fewer distinct classes, fewer things to test and maintain. But I may be

[Rails] Re: rescuing ActiveRecord::RecordNotUnique: clever or ugly?

2012-03-24 Thread Fearless Fool
Peter Vandenabeele wrote in post #1052874: A custom validation on the compound unique key would behave similar, always do a SELECT (and suffer from the race condition documented in http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#method-i-validates_uniqueness_of

[Rails] rspec: mocking a reference to a polymorphic model?

2012-03-22 Thread Fearless Fool
The basic question: how do you mock (or stub) a reference to a polymorphic class in RSpec? Trying the obvious thing leads to an error of the form: undefined method `base_class' for Post:Class === The details: # file: app/models/relation.rb class Relation ActiveRecord::Base belongs_to

[Rails] why doesn't .where() honor polymorphism?

2012-03-22 Thread Fearless Fool
I love the query interface (ActiveMethod::QueryMethods), but one thing has bugged me: why doesn't it generate calls for polymorphic associations? For example: class MyModel ActiveRecord::Base belongs_to :parent, :polymorphic = true end I would expect: MyModel.where(:parent = a) to be

[Rails] rescuing ActiveRecord::RecordNotUnique: clever or ugly?

2012-03-22 Thread Fearless Fool
I have an ActiveRecord that has several foreign keys, where the foreign keys act as a single compound key that needs to be unique: class CreateRelations ActiveRecord::Migration def change create_table :relations do |t| t.references :src, :null = false t.references :dst, :null =

[Rails] Re: sti + namespace

2012-03-22 Thread Fearless Fool
Francis P. wrote in post #1052528: I know this is an old topic, and perhaps you've solved it. @Francis: thank you for that. For the record, what I've ended up doing is something like the following. The key thing that took me a while to figure out what to set the table_name in the base class:

[Rails] Re: the naming of STI tables

2012-03-08 Thread Fearless Fool
Robb Kidd wrote in post #1050675: class Fruit ActiveRecord::Base belongs_to :basket end class Apple Fruit end class Basket ActiveRecord::Base has_many :fruits end Ref: Single Table Inheritance http://api.rubyonrails.org/classes/ActiveRecord/Base.html Robb: Pardon -- Although

[Rails] the naming of STI tables

2012-03-07 Thread Fearless Fool
File this under mild pedantry, but it's been bugging me. Assume I want to store different kinds of fruit in an STI table. My approach works, but I end up referring to fruit_bases throughout my code where I'd really prefer just fruits. What I've got is something like: = # File:

[Rails] why does #destroy() DELETE FROM one at a time?

2012-02-16 Thread Fearless Fool
I have a pair of models with a fairly standard :has_many relation. The only twist is that the has_many table is a namespaced STI table: module MeteredService class Base ActiveRecord::Base has_many :service_bills, :foreign_key = :metered_service_id, :dependent = :destroy ... end end

[Rails] Re: why does #destroy() DELETE FROM one at a time?

2012-02-16 Thread Fearless Fool
Sometimes I intentionally introduce small typos to see if you're paying attention! :) The suggested SQL should have read: DELETE FROM service_bills WHERE metered_service_id = my_metered_service.id -- Posted via http://www.ruby-forum.com/. -- You received this message because you are

[Rails] AR update / create pattern: is there an easier way?

2012-01-04 Thread Fearless Fool
I find myself writing the following frequently: r = MyActiveRecord.where(:attr1 = cond1, :attr2 = cond2, ...) r.exists? ? r.first : r.create ... which has the effect of returning an instance of MyActiveRecord if all the conditions are met, or creating one if it doesn't. A variant of

[Rails] awesome polymorphic goodness in before_create

2012-01-02 Thread Fearless Fool
This isn't a question -- it's just me being astonished by yet another thing in Rails that Just Works. Here it is: = class Wizard ActiveRecord::Base before_create :create_deferrables has_one :weather_loader, :as = :owner, :dependent = :destroy def create_deferrables

[Rails] Re: ApplicationController needs a #delete method

2011-12-30 Thread Fearless Fool
Alexey Muranov wrote in post #1038755: I like the idea. By the way, the issues are not on Lighthouse anymore but on GitHub: https://github.com/rails/rails/issues Right you are. So, feeling a little like David facing off against Goliath, I've submitted a ticket:

[Rails] Re: ApplicationController needs a #delete method

2011-12-29 Thread Fearless Fool
Tim Shaffer wrote in post #1038731: I apologize... I guess I wasn't sure what you were asking. No problem! ActionController::Base doesn't have *any* methods included. You're right -- I mis-spoke: s/ActionController::Base/standard Rails distribution/g In addition to the resourceful routes,

[Rails] ApplicationController needs a #delete method

2011-12-28 Thread Fearless Fool
I've just finished a toy project that I call righteously ubiquitous javascript: https://github.com/rdpoor/righteous_ujs and the experience has convinced me that Rails controllers need a #delete method that parallels the contracts of the #new and #edit methods. To explain: The three verbs

[Rails] Re: ApplicationController needs a #delete method

2011-12-28 Thread Fearless Fool
Tim Shaffer wrote in post #1038479: You can easily add a delete method to your controller: ... which is exactly what I did in the cited code example. I'm not sure how to interpret your reply. Sure it's trivial to add. Are you claiming that a delete method should NOT become part of the

[Rails] setting ar.errors[:base] from separate thread

2011-12-28 Thread Fearless Fool
I'm cleaning up how I use Delayed::Job in my app. It's processing an ActiveRecord as a delayed task. If the task ends with an error, I'd *like* to set myActiveRecord.errors[:base] 'error message'. The only twist is that errors will be caught in the delayed task's thread. My early experiments

[Rails] Mechanize GETting twice without redirect?

2011-12-20 Thread Fearless Fool
[Cross posted to Ruby on Rails Forum and Mechanize mailing list.] I'm using Mechanize for page scraping (Ruby 1.9.2 / Rails 3.0.5 / Mechanize 2.0.1). I'm seeing a case where a single agent.get(url) generates two HTTP GETs. Why is this happening? The response to the first GET is a 200 (no

[Rails] Re: Mechanize GETting twice without redirect?

2011-12-20 Thread Fearless Fool
UPDATE: sort of solved. The web server sets Content-Length to a incorrect value (at least for compressed replies), and Mechanize was re-trying the GET before giving up. The temporary fix is to monkey patch Mechanize::HTTP::Agent to ignore Content-Length. A longer-term fix would be to include

[Rails] how to I make a custom configuration variable?

2011-12-16 Thread Fearless Fool
I'm sure there's an obvious answer: I want to create a slightly customized version of my RoR app. It involves minor tweaks to some routes, changes to some of the layouts, turning off devise's :registerable and other bits scattered around the source code. I'd like to define a single variable or

[Rails] generating styled text in a model

2011-11-17 Thread Fearless Fool
I want to convert analytical results (i.e. numbers) into prose (i.e. English sentences). In addition to generating the words, I also want to be able to style bits of the text (presumably by decorating them with css classes). For example, assume something contrived like: def

[Rails] Re: HOWTO Let Rails login into another website

2011-11-15 Thread Fearless Fool
Jeroen van Ingen wrote in post #1031839: Mechanize looks good, I'll definitely give it a try. Where I'm basically searching for is a gem or library that can store a session / cookie, so Rails can login on a website in the background. Anyone who know if there are other options besides

[Rails] why is my text_field getting a default value of current_user.email?

2011-11-07 Thread Fearless Fool
I have a form containing a text field along the lines of: %= form_for(wizard, :url = wizard_path, :method = :put) do |f| % %= form.text_field gas_credentials[user_id], :value = wizard.gas_credentials['user_id'] % % end % Mysteriously, when wizard.gas_credentials is nil, the

[Rails] Re: why is my text_field getting a default value of current_user.email?

2011-11-07 Thread Fearless Fool
Doh! The answer: browser autocompletion. I'm leaving this post in place rather than deleting it out of shame in the faint hope that it might save someone else a few minutes of head scratching. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed

[Rails] Re: why is my text_field getting a default value of current_user.email?

2011-11-07 Thread Fearless Fool
[silly forum code won't let me edit previous reply.] To prevent autocompletion, you can do something like: %= form.text_field gas_credentials[user_id], :value = wizard.gas_credentials['user_id'], :autocomplete = :off % -- Posted via http://www.ruby-forum.com/.

[Rails] Re: where to use colon (:) and where to not use it?

2011-09-11 Thread Fearless Fool
@venkata: Ruby makes a lot of things optional that other languages require. It makes typing easier, but can lead to the very confusion you encountered. The first shorthand to know is that in Ruby, function and method calls can omit the parentheses that bracket the arguments, so your examples:

[Rails] Re: methods generated for an AR field: what do they do?

2011-09-09 Thread Fearless Fool
Frederick Cheung wrote in post #1017751: The guts were moved into ActiveModel, but you can use it with active record just like you used too. There was some fairly major refactoring in rails 3 which confuses apidock quite a bit. Word. I eventually found the more modern docs for

[Rails] Re: skinning the app

2011-08-31 Thread Fearless Fool
Alpha Blue wrote in post #1019380: I would decide what customizations you are willing to support or not support. Life would be lovely if that were up to me. But the person with the checkbook gets to make that decision. (Of course, I can charge more for some customizations...) For the ones

[Rails] skinning the app

2011-08-30 Thread Fearless Fool
Good news everyone: a customer wants to license our Rails-based app! (Maybe we'll be able to afford something fancier than ramen noodle for dinner!!!) The bad news is that they want a custom logo, custom color scheme and a few tweaks here and there. What are the established techniques for

[Rails] Re: methods generated for an AR field: what do they do?

2011-08-21 Thread Fearless Fool
waseem ahmad wrote in post #1017743: Following might be useful. http://ar.rubyonrails.org/classes/ActiveRecord/Dirty.html Got that, and I notice that those are all vintage 2008. But I also note that in: http://apidock.com/rails/ActiveRecord/Dirty ... that ActiveRecord::Dirty ...is

[Rails] methods generated for an AR field: what do they do?

2011-08-20 Thread Fearless Fool
If my table reads like this: create_table(:pet_owners, :force = true) do |t| t.boolean :has_allergies end ... then ActiveRecord::Base generates the following methods: :has_allergies :has_allergies= :has_allergies? :has_allergies_before_type_cast :has_allergies_change

[Rails] Re: :dependent = :destroy with nonstandard :foreign_key?

2011-08-12 Thread Fearless Fool
Resurrecting an old thread because it has a useful lesson: Marnen Laibow-Koser wrote in post #927576: Fearless Fool wrote: [stuff about a before_destroy method using two destroy_all calls] Great! You can probably unify those into one query and get better performance at the expense of a bit

[Rails] what is the lifetime of ActionController, etc?

2011-05-27 Thread Fearless Fool
I realize that I don't know what causes an ActionController to be created and destroyed. As a specific example, consider: class UsersController ApplicationController def myState @myState ||= Object.new end def show ... end end Is there one ActionController

[Rails] Re: MyModel.descendants returns [] in a view after the first call?

2011-05-06 Thread Fearless Fool
Max Schubert wrote in post #996908: Could you respond with your development.rb file (with names sanitized as needed?) .. what version of Rails are you using? We have been using 3.0.5, just upgrading to 3.0.7 this week Sure. Here it is. Thanks. = versions (I'll move to 3.0.7 when

[Rails] Re: Re: MyModel.descendants returns [] in a view after the first call?

2011-05-06 Thread Fearless Fool
@ Fred, @Robert Pankowecki: Frederick Cheung wrote in post #996972: Have you been mixing in calls to require with calls to require_dependency/letting rails load things automatically? That can make a giant mess of things where some classes are reloaded and others aren't, so for example

[Rails] Re: MyModel.descendants returns [] in a view after the first call?

2011-05-06 Thread Fearless Fool
@Robert, @Fred, @Max GOT IT! You all had a piece of the puzzle. (Robert: As an aside, you mean you call Product.descendants() -- not dependencies() -- but that's a trifle.) I realized that my reason that the Fred/Robert solution didn't work was correct: a request passes in the string

[Rails] convincing form_for to generate params for parent class

2011-05-05 Thread Fearless Fool
I have an STI class structure: class MeteredService ActiveRecord::Base ; end class PGEService MeteredService ; end class SCEService MeteredService ; end In my view, I want update (say) the :resource field: %= form_for(metered_service, :url = metered_service_path(metered_service)) do |f| %

[Rails] Re: Re: MyModel.descendants returns [] in a view after the first call?

2011-05-05 Thread Fearless Fool
Max Schubert wrote in post #996758: Fearless, Well, not really a bug - it is 'behavior as designed' but it is also a 'fail' for those of us using 'meta-programming as designed LOL' because meta-programming requires that classes be loaded and that the callbacks associated with Object and Class

[Rails] Re: MyModel.descendants returns [] in a view after the first call?

2011-05-05 Thread Fearless Fool
Frederick Cheung wrote in post #996771: descendants returns all loaded subclasses, but when class caching is off, classes are cleared out, so the freshly loaded copy of MyModel has no loaded subclasses. Robert Pankowecki wrote in post #996778: Use require_dependency to load subclasses. @

[Rails] Re: MyModel.descendants returns [] in a view after the first call?

2011-05-05 Thread Fearless Fool
[@Max: our messages just crossed. With all due respect, I think I like my approach better!] Okay. I'm out of the weeds, but I'd like to know if I've done it the right way. My code references subclasses of MeteredService several transactions after metered_service.rb gets loaded (e.g. the result

[Rails] Re: MyModel.descendants returns [] in a view after the first call?

2011-05-05 Thread Fearless Fool
Fearless Fool wrote in post #996867: [@Max: our messages just crossed. With all due respect, I think I like my approach better!] snip So now I overload MeteredService.descendants, calling 'require' instead of 'require_dependency'. This seems to work just fine: snip Let me know if I'm

[Rails] Re: MyModel.descendants returns [] in a view after the first call?

2011-05-05 Thread Fearless Fool
Fearless Fool wrote in post #996869: So my next approach will be some magick with const_defined? -- this time for sure!!! ;) I tried that and now I'm really confused. @Fred: would you expect it to be the case that: class MeteredService ActiveRecord::Base ; end class PGEBusiness

[Rails] Re: MyModel.descendants returns [] in a view after the first call?

2011-05-05 Thread Fearless Fool
Resistance is futile. Until someone chimes in with a better idea, I'm adopting Max's approach (above). - ff -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to

[Rails] Re: MyModel.descendants returns [] in a view after the first call?

2011-05-05 Thread Fearless Fool
@Max: Fearless Fool wrote in post #996874: Until someone chimes in with a better idea, I'm adopting Max's approach (above). I thought you might want to know: I've implemented your approach and I'm STILL seeing the problem: the descendants are defined the first time, but gone thereafter. I

[Rails] MyModel.descendants returns [] in a view after the first call?

2011-05-04 Thread Fearless Fool
[I posted this initially to the StackOverflow list. There have been no nibbles, so I'm coming here to consult the real experts! :)] I want to display a selection list of MyModel subclasses in a view. It's not working yet, so for sanity checking, I included this in my view: %=

[Rails] Re: MyModel.descendants returns [] in a view after the first call?

2011-05-04 Thread Fearless Fool
@Max: Max Schubert wrote in post #996743: I am guessing you are in development mode with class caching off :) and that this behavior does not occur in test nor production mode ... Try the code with either test or production if you haven't already ... Thanks for the tip. Rather than try to

[Rails] form label inside using jquery, outside without

2011-04-29 Thread Fearless Fool
[I originally posted this on the jquery forum, but I realize that I'll have to figure out the right syntax for form_for anyway, so it makes sense to cross-post here...] I'd like to be able to render forms, augmented by unobtrusive javascript that behave as follows: When javascript is enabled,

[Rails] how to set up fields_for to choose a subclass?

2011-04-21 Thread Fearless Fool
I have an STI model where UtilityProvider is the parent class, and there's a sub-class for each specific utility provider. When the user goes to choose a UtilityProvider, I want to present a pull-down list of UtilityProvider.subclasses (or, more likely, a filtered version of that), and when the

[Rails] Re: Re: AssociationTypeMismatch (superclass expected, got subclass)

2011-04-19 Thread Fearless Fool
Bryan Crossland wrote in post #993205: What is the code for the method find_stations_near? First, here's the code for find_local_weather_stations(). The create method raises the error: def find_local_weather_stations(limit = 10) premise_weather_stations.delete_all stations =

[Rails] Re: Re: AssociationTypeMismatch (superclass expected, got subclass)

2011-04-19 Thread Fearless Fool
Okay, I have found a fix, or at least a workaround. If a Rails core team member is reading this, I'd appreciate knowing if this warrants a lighthouse ticket. If I add a .reload (to the AR that is already in the db): def load_station(candidate) if (incumbent =

[Rails] Re: AssociationTypeMismatch (superclass expected, got subclass)

2011-04-16 Thread Fearless Fool
UPDATE: Stranger and stranger. I do NOT get this error running in the console. I do NOT get this error running the test suite. I ONLY get this error under 'rails server'. I tracked the Rails source to where the AssociationTypeMismatch is raised in association_proxy.rb: def

[Rails] Re: AssociationTypeMismatch (superclass expected, got subclass)

2011-04-16 Thread Fearless Fool
Hi Bryan: Bryan Crossland wrote in post #993150: PremiseWeatherStation.create(:premise = self, :weather_station = station) I've been unable to reproduce your error in the rails server or in the console. However, what I do see is that self is a reserved word. The variable name of the object

[Rails] sti + namespace

2011-04-15 Thread Fearless Fool
I'm spidering historical weather data from various sources. I have a WeatherStation class that is begging for an STI implementation: a WeatherStation is associated with a specific weather service, and each weather service has its own protocol for fetching weather data, but most of the code is can

[Rails] AssociationTypeMismatch (superclass expected, got subclass)

2011-04-15 Thread Fearless Fool
Perhaps this is just http://www.ruby-forum.com/topic/1505406 coming back to bite me -- I suspect I'm missing a trivial declaration. Error message (note that NOAA is an STI subclass of WeatherStation) ActiveRecord::AssociationTypeMismatch (WeatherStation(#2169635200) expected, got

[Rails] the store locator problem.

2011-04-08 Thread Fearless Fool
I'm not sure what Rails elements come into play here, so I'm just calling this the store locator problem. Bear with me... Assume I have a database-backed Store model. And that it has a locator method that returns a list of NEW store objects -- NOT YET SAVED IN THE DB -- that are near a given

[Rails] Re: the store locator problem.

2011-04-08 Thread Fearless Fool
Update: After mulling this over for a few hours, I have concluded that I'm asking two distinct questions: Q1: If I have a page that contains a partial that contains a form that invokes an action in MyController, how do I return the results to the original page? A1a: I could (somehow) arrange

[Rails] Re: compass and blueprint.

2011-04-04 Thread Fearless Fool
@Msan: I had never heard of compass before your question. So I did a google of rails compass, and the first article it came up with was Using Compass with Blueprint in Rails: http://billsaysthis.com/content/compass-blueprint-rails.php Perhaps you'll find it useful while you are waiting for a

[Rails] [Announcement]: roogle_graphics on github: generate png graphics w/o any libraries

2011-04-04 Thread Fearless Fool
I just pushed my second ever project to github (go gentle on me!): https://github.com/rdpoor/roogle_graphics/ roogle_graphics is a standalone Ruby module that generates simple graphics using Google Chart API service. You place text and polygons in a roogle_graphics plot, it emits a really

[Rails] code browsing: I want less than an IDE, more than grep

2011-03-17 Thread Fearless Fool
A question for the pros: I want to dig into the Rails source code to understand How Things Work. What tools do people use for interactive browsing? In particular, I'd like to be able to point at a method name (or package, or class) in the source code, see a list places where that's defined, and

[Rails] Re: emacs-rails

2011-03-07 Thread Fearless Fool
nellinux wrote in post #985959: What is the best mode for Rails in Emacs ? I have emacs-rails but it seems not updated to support rails 3. Heh - I didn't know there was an emacs-rails mode until your query -- thank you for that. Poking around, I found:

[Rails] obfuscating sensitive data

2011-03-07 Thread Fearless Fool
In our app, users give us sensitive information (credentials for logging into a third party site). At some point, we need those credentials in cleartext in order to access the third party site, but while they're in our database, we want to make best effort for protecting them. What techniques

[Rails] Re: render :collection calling partial with phantom object?

2011-03-02 Thread Fearless Fool
Frederick Cheung wrote in post #984876: There's a railscast covering one possible approach: http://railscasts.com/episodes/197-nested-model-form-part-2 @Lorenzo: Looks good. Thanks. @Frederick: I'm beginning to believe that if you can imagine it, Ryan Bates has already coded it. Thanks for

[Rails] Re: render :collection calling partial with phantom object?

2011-03-01 Thread Fearless Fool
Frederick Cheung wrote in post #984616: That sounds like you've got an unsaved metered_service somewhere (eg by doing premise.metered_services.build) Fred Yep, that's true. I based my code on the canonical blog posts / comments example, so in views/premises/edit.html.erb, I wrote: %=

[Rails] render :collection calling partial with phantom object?

2011-02-28 Thread Fearless Fool
I have two models with a straightforward has_many / belongs_to relationship: class Premise ActiveRecord::Base has_many :metered_services, :dependent = :destroy ... end class MeteredService ActiveRecord::Base belongs_to :premise ... end and nested routes to match:

[Rails] using state transitions to generate user feedback

2011-02-25 Thread Fearless Fool
I'm trying to wrap my head around this, and looking for suggestions: In ordinary operation, our system calls upon several external web services to gather info -- these steps can take a while and we want to give our users feedback on what's happening. My hunch is that a state-driven model, using

[Rails] Re: An hash of arrays, how to use?

2011-02-13 Thread Fearless Fool
Hi Norbert: An idiom that I use frequently is: h = {} (h[key] ||= []) item which essentially says if hash h[key] is nil, create an empty array for that key. then push item onto the array. for example: h = {} = {} (h[cats] ||= []) Jellicle = [Jellicle] (h[cats] ||= []) Mr. Mistoffelees

[Rails] Re: can you portably store infinity via AR?

2011-02-11 Thread Fearless Fool
Where it stands: Infinity can be represented in IEEE floating point numbers. Infinity can be represented in Ruby, as evidenced by (1.0/0.0).infinite? = 1 Infinity can be represented in sqlite (and probably other databases): sqlite select * from test_recs; 1|Inf| Yet it appears that

[Rails] can you portably store infinity via AR?

2011-02-10 Thread Fearless Fool
Hi: The gist of my question: is there a way to *portably* store and retrieve Infinity in an ActiveRecord float column? Following is an amusing saga, but it doesn't really answer the question. Step 1: As was mentioned in http://www.ruby-forum.com/topic/74141, you can't simply write a Ruby

[Rails] Re: Lazy regexp is not lazy enough

2011-02-08 Thread Fearless Fool
Ralph Shnelvar wrote in post #980334: How can I do this? That is, I want to find the nearest h1 ... /h1 surrounding Placeholder2. First, I'll +1 Fred on using Nokogiri for parsing HTML. But you can modify you regex so any markup '' characters are excluded using [^], as in: p =

[Rails] favorite pattern for adding functionality to an AR?

2011-02-08 Thread Fearless Fool
Do you have a preferred programming pattern for adding functionality to an ActiveRecord? As an example, say I have some gnarly trig functions for distance and bearing between pairs of latitude and longitude: === file: latlng.rb module LatLng def haversine_distance(lat1, lng1, lat2, lng2) ...

[Rails] Re: Lazy regexp is not lazy enough

2011-02-08 Thread Fearless Fool
Ralph Shnelvar wrote in post #980369: Fearless, your solution seems to work ... but I am clueless as to how and why it works! I'm FAR from a regex wizard, but it's worth noting: [abc] means match any occurrence of a or b or c [^abc] means match any character that is NOT a or b or c ergo

[Rails] seeking guidance: writing effective tests for externally sourced data

2011-01-29 Thread Fearless Fool
So first, thanks in no small part to Marnen's rants, I've become a complete RSpec / FactoryGirl / TDD convert. Hey, autotest coupled with Growl is the bee knees! And I've even started pushing builds out to Heroku to keep me honest. Now I feel uneasy when I've written a piece of code that isn't

[Rails] Re: seeking guidance: writing effective tests for externally sourced data

2011-01-29 Thread Fearless Fool
Marnen Laibow-Koser wrote in post #978394: - any XML data I fetch from the external site is cached The external site isn't already setting its HTTP caching headers properly for this? That's a good suggestion, and I'll certainly look into heeding the HTTP expiration time stamps. In my case,

[Rails] Re: seeking guidance: writing effective tests for externally sourced data

2011-01-29 Thread Fearless Fool
A minor correction: Fearless Fool wrote in post #978457: Marnen Laibow-Koser wrote in post #978394: The external site isn't already setting its HTTP caching headers properly for this? That's a good suggestion, and I'll certainly look into heeding the HTTP expiration time stamps... I

[Rails] different load order in rails console vs rspec tests?

2011-01-28 Thread Fearless Fool
I've written a simple module to extend ActiveRecord::Base, which works fine in the rails console but fails miserably in rspec tests. The intended usage looks like this: class Premise ActiveRecord::Base has_my_extensions end I've traced it down to the fact that in the console, it loads

[Rails] Re: different load order in rails console vs rspec tests?

2011-01-28 Thread Fearless Fool
Frederick Cheung wrote in post #978281: Stuff like this belongs in an initializer. I'm just now realizing how environment.rb has changed in Rails3. Next question: where does one learn the zen of initializers? Do I create my own, e.g. $ROOT/config/initializers/my_extensions.rb? And is it

[Rails] Re: different load order in rails console vs rspec tests?

2011-01-28 Thread Fearless Fool
Fearless Fool wrote in post #978285: ... Do I create my own, e.g. $ROOT/config/initializers/my_extensions.rb? FWIW, I simply created a $ROOT/config/initializers/my_extensions.rb file and populated it with: require 'my_extensions' ... and rspec is all happy. Let me know if that's

[Rails] Re: link_to :method = :delete doesn't?

2011-01-27 Thread Fearless Fool
Frederick Cheung wrote in post #977813: Have you got the rails js loaded that detects those attributes and actually does something with them? @Fred: As I alluded to in the OP, I'm suspicious that I may have messed up the default Rails JS when I included JQuery. My

[Rails] Re: Re: link_to :method = :delete doesn't?

2011-01-27 Thread Fearless Fool
Chris Mear wrote in post #977826: The default rails.js that ships with Rails 3 is designed to work with Prototype; you should replace it with one written to work on jQuery, if you haven't already: https://github.com/rails/jquery-ujs Chris Give that man a cigar! Evidently I'd installed the

[Rails] Re: link_to :method = :delete doesn't?

2011-01-27 Thread Fearless Fool
Marnen Laibow-Koser wrote in post #977875: I rarely use delete links... That's interesting! My instinct is to suggest defining a GET destroy action. OTOH, that's not idempotent. Aaugh! Browsers only generate GETs and POSTs, so any DELETE action needs to be simulated somehow. And as you

  1   2   3   >