[Rails] Re: functional testing API: GET versus POST?

2011-11-06 Thread Grary Stimon
Colin, Here's some of the debug trace... => 14 data = ActiveSupport::JSON.decode(request.body.read) (rdb:1) p request.body.read "loan=400" So, this is consistent with the controller error.. JSON::ParserError: unexpected token at 'loan_request=400' My functional testing approa

[Rails] Re: functional testing API: GET versus POST?

2011-11-06 Thread Grary Stimon
Dave, Thanks for the consideration you show to this issue of mine, here is the recap... I have the following error from my Rails 3.1 controller... JSON::ParserError: unexpected token at 'loan_request=400' ...where the controller code line in question is... data = ActiveSupport::JSO

[Rails] Re: functional testing API: GET versus POST?

2011-11-06 Thread Grary Stimon
Hey, Sorry to promote this again, but I'm stuck. Anybody? Grar -- 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 rubyonrails-talk@googlegroups.com. To unsubs

[Rails] Re: functional testing API: GET versus POST?

2011-11-05 Thread Grary Stimon
Matt, Thanks. Continued work on this problem has shifted the emphasis, but I'm still blocked and could use help. I've changed the request from a GET to a POST, just to remove uncertainty around the availability of the request.body for processing in the controller. I now have the following error

[Rails] functional testing API: GET versus POST?

2011-11-04 Thread Grary Stimon
Hi, I'm unable to properly test GET calls for my JSON API in Rails 3.1, using ActionController::TestCase. get :loan, ActiveSupport::JSON.encode(minimum_valid_json_params), :format => :json ...where minimum_valid_json_params has the form... {:one_thing=>"something", :another_thing=>23, ... } ..

[Rails] Re: how to simulate typecasting of ActiveRecord in non-AR classes?

2011-11-04 Thread Grary Stimon
Peter, Wow, that's a lot! One of my reasons for posting was I saw ActiveModel::Serializers#from_json and I thought, 'What good is this, if there is not some other facility to handle non-String attributes?' It seems, though, that the functionality you have so generously sketched is just not av

[Rails] how to simulate typecasting of ActiveRecord in non-AR classes?

2011-11-04 Thread Grary Stimon
Hi, I have non-ActiveRecord Ruby classes that I use for numerical (and other) processing as part of an API service. I seem to recall that AR will cast attributes, say, from a params hash, into the data type expected for the attribute. That is useful, and I'm missing that feature in my non-AR clas

[Rails] Re: ActiveModel::Validations in another module?

2011-10-30 Thread Grary Stimon
Matt, Thanks, that did the trick, and I think it unlikely that I would have found that without some help! Now, on to what is likely the subject of yet another post: How do I obtain the effect of ActiveModel::Validations#validates_associated if applied to non-ActiveRecord classes where I seek t

[Rails] Re: ActiveModel::Validations in another module?

2011-10-30 Thread Grary Stimon
Frederick, I seek to create Ruby modules that use ActiveModel::Validations. The examples I have seen of ActiveModel::Validations all involve including that module in classes. This is not what I want. I want to involve the use of ActiveModel::Validations in a module, which I may then choose to impl

[Rails] ActiveModel::Validations in another module?

2011-10-29 Thread Grary Stimon
Hey, I'm trying to specify validations with ActiveModel::Validations at the module level, i.e., I wish to mix-in validations to a module. I am not succeeding at this, however. How do I mix-in ActiveModel::Validations into another module and use its methods just as I would in a class? Thanks, L

[Rails] Re: how do I structure gem to avoid LoadError in my Rails project?

2011-09-04 Thread Grary Stimon
OK, solved it. Thanks to Luis's reference to the original rubygems guide, I was able to build a simple gem that worked with my Rails 3.0.7 project. So, I realized there was something wrong with my use of bundler in creating gems. The problem was that I was not managing the gem's development wi

[Rails] Re: how do I structure gem to avoid LoadError in my Rails project?

2011-09-04 Thread Grary Stimon
Luis, Yes, the gemspec is as listed in my previous post... Thanks for the reference to RubyGems doc, which I am reading now, in hopes of solving this. Meanwhile, I'm wondering if there's interaction between rvm 1.9.2 and this problem? In this connection, I modified zipcode/config.rb as follows.

[Rails] Re: how do I structure gem to avoid LoadError in my Rails project?

2011-09-04 Thread Grary Stimon
Hey, Still no joy. I thought I'd follow 7stud's example and recreate the gem structure to see if I could load it after any reasonable modifications... /lib zipcode.rb -- require 'zipcode/config.rb' /zipcode version.rb config.rb cityandstate.rb ...where lib/zipcod

[Rails] how do I structure gem to avoid LoadError in my Rails project?

2011-09-03 Thread Grary Stimon
Hi, I'm new to gem development. I just completed a gem for use with a Rails 3.0.7 project. The gem itself passes its tests. I've listed the gem in the Rails project's Gemfile... Unfortunately, Rails is choking on some requires in my gem. Here is what I get in Rails: activesupport-3.0.7/lib/activ

[Rails] Re: nested resources and controllers: I think I'm down the w

2010-04-26 Thread Grary
I can't recreate the problem, somehow, let's consider the question dead until I can. Thanks, Grar On Apr 26, 11:06 am, Marnen Laibow-Koser wrote: > [Please quote when replying.] > > Grary Stimon wrote: > > Marnen, > > > Here is the expression of a repr

[Rails] Re: nested resources and controllers: I think I'm down the w

2010-04-26 Thread Grary
5 am, Marnen Laibow-Koser wrote: > Grary Stimon wrote: > > Hi, > > > I'm new to nested resources. I'm surprised to find that to make my > > code work I need to retrieve the parent model in my RESTful > > controllers for my dependencies. > > > So, for exam

[Rails] nested resources and controllers: I think I'm down the wrong path

2010-04-26 Thread Grary
Hi, I'm new to nested resources. I'm surprised to find that to make my code work I need to retrieve the parent model in my RESTful controllers for my dependencies. So, for example, let's say A has_one B. In controller B I seem to need to refer to parent A, for example: @b = A.find(params[:a_id])

[Rails] Re: newb's quick question on session variable vs. params in 'pretty' urls

2010-04-17 Thread Grary
ill not be persisted indefinitely -- indeed its creation should be silent to the user. Grar On Apr 16, 2:07 pm, steve ross wrote: > On Apr 15, 2010, at 2:37 PM, Grary wrote: > > > > > > > Hi, > > > Is there a compelling reason to prefer reliance on the params ha

[Rails] newb's quick question on session variable vs. params in 'pretty' urls

2010-04-15 Thread Grary
Hi, Is there a compelling reason to prefer reliance on the params hash vs. the same info stored in a session hash? So, for example, params[:id] = @loan vs. session[:loan_id] = @loan.id? It matters because I can make prettier urls if I store certain uniquely identifying model attributes as session

[Rails] how to remove dependents in has-many-belongs-to relationship before saving?

2010-04-13 Thread Grary
Hi, In my RESTful controller's create method, how do I intercept and modify any dependents before saving? That is, I have a model that is the parent of nested associations gathered from a form. The first line of this model's controller create method is: @parent = Parent.new(params[:parent]) What

[Rails] Re: test database and migrations

2010-04-11 Thread Grary
ur development database with > "rake db:fixtures:load". > > Anthony Crumleyhttp://commonthread.com > > On Sat, Apr 10, 2010 at 8:59 AM, Grary wrote: > > Hi, > > > I'd like to have the results of a migration file that prepopulates my > > development da

[Rails] Re: test database and migrations

2010-04-10 Thread Grary
response is that testing is typically performed on a limited subset of development/production data that has been supplied from fixtures. Can you please confirm? Thanks, Grar On Apr 10, 9:52 am, Frederick Cheung wrote: > On Apr 10, 2:30 pm, Grary wrote:> Hi, > > > I'd like to h

[Rails] test database and migrations

2010-04-10 Thread Grary
Hi, I'd like to have the results of a migration file that prepopulates my development database available for testing. So, right now, after the usual rake migration, I can access my prepopulated data via script/ console, but not in my unit tests. I've reviewed comments on this subject but the custo

[Rails] test database and migrations

2010-04-10 Thread Grary
Hi, I'd like to have the results of a migration file that prepopulates my development database available for testing. So, right now, after the usual rake migration, I can access my prepopulated data via script/ console, but not in my unit tests. I've reviewed comments on this subject but the custo

[Rails] Re: 'to_f or not to_f', that is the matter of my question...

2010-04-06 Thread Grary
Having duly considered it, I withdraw my suggestion of a 'tradeoff'. I'm better off for your comments, so thanks all. Grar On Apr 5, 3:38 pm, Colin Law wrote: > On 5 April 2010 19:48, Grary wrote: > > > Colin, > > > So, there is something I will regret eith

[Rails] Re: 'to_f or not to_f', that is the matter of my question...

2010-04-05 Thread Grary
no previous experience in the matter, I'll adopt your proposal. Thanks, Grar On Apr 5, 1:35 pm, Colin Law wrote: > On 5 April 2010 17:57, Grary wrote: > > > What is the best practice for handling ActiveRecord attributes in > > logic when those attributes were allow

[Rails] 'to_f or not to_f', that is the matter of my question...

2010-04-05 Thread Grary
What is the best practice for handling ActiveRecord attributes in logic when those attributes were allowed to be nil? I've been handling the possibly-nil status of my Numeric attributes in my logic by calling to_f (to_i) on them, but I wonder if there's a better practice? For example, default value

[Rails] Re: Newbie seeking advice on DRYing up my model validations...

2010-04-01 Thread Grary
t; ActiveRecord::Base >     include MyEmailValidations >   end > > Does this solve your problem? > > /Lasse > > 2010/4/1 Grary > > > Hi, > > > Despite close reading of Matz's Ruby book and Agile Web Dev. w. Rails, > > I can't  figure out how to

[Rails] Newbie seeking advice on DRYing up my model validations...

2010-04-01 Thread Grary
Hi, Despite close reading of Matz's Ruby book and Agile Web Dev. w. Rails, I can't figure out how to tackle the challenge of sharing validation code across models with attributes in common. In each of my models I'd like to validate the shared attributes with a custom validator that includes Rail

[Rails] Re: factory_girl factory gem: problem with simple associations

2010-03-22 Thread Grary
No takers, huh? On Mar 22, 10:00 am, Grary wrote: > Hi, > > Can anyone familiar with the use of factory_girl please comment on why > I don't succeed with the following: > > has_one_instance = Factory.build(:has_one_class) > assert_equal 10, has_one_instance.belon

[Rails] factory_girl factory gem: problem with simple associations

2010-03-22 Thread Grary
Hi, Can anyone familiar with the use of factory_girl please comment on why I don't succeed with the following: has_one_instance = Factory.build(:has_one_class) assert_equal 10, has_one_instance.belongs_to_class.some_attribute ...when I've constructed the relevant factories, as follows: Factory.

[Rails] Re: selective migrations possible?

2010-03-20 Thread Grary
Fernando, When you say... "When you have too many migration files, simply remove them." ...I think this means that you refer to the schema as the one source of summary information and that migration files are not informative except when a developer wants to revert to an earlier stage via 'redo'

[Rails] Re: selective migrations possible?

2010-03-19 Thread Grary
env, upgrade the prod env, and post-test the prod env, and when > all is good, dump the db again as a post-upgrade backup.  (I usually > test each upgrade scripts against a similar version/state of the dev > env prior to performing the upgrade on the prod env, and once the > script

[Rails] Re: selective migrations possible?

2010-03-19 Thread Grary
l side. Thanks, Grar On Mar 19, 1:50 pm, Colin Law wrote: > On 19 March 2010 16:07, Grary wrote: > > > Hi, > > > I prefer to keep one migration per model, but lately I'm adding data > > that's expensive to drop every time I change my models. > > It is co

[Rails] Re: selective migrations possible?

2010-03-19 Thread Grary
I've registered your skepticism. Yes, I can't see that the benefit of satisfying my preference here outweighs the burden. That said, I still think it's a drag to sift through multiple migration files. Thanks, Grar On Mar 19, 12:40 pm, Ar Chron wrote: > Grary wrote: > &g

[Rails] Re: selective migrations possible?

2010-03-19 Thread Grary
OK. Also, I was just thinking: if I create models and then, without a migration, create corresponding tables, I have sidestepped the problem, such as it is. Anyway, I've registered your skepticism. Thanks, Grar On Mar 19, 12:40 pm, Ar Chron wrote: > Grary wrote: > > Hi, >

[Rails] selective migrations possible?

2010-03-19 Thread Grary
Hi, I prefer to keep one migration per model, but lately I'm adding data that's expensive to drop every time I change my models. How do I db:drop and db:migrate only selected tables/files? Basically, I want to ignore certain tables and migrations altogether during certain development phases. Tha

[Rails] Re: what is the proper role of seed data?

2010-03-16 Thread Grary
Robert, Another high quality response, thank you. Let me respond briefly, selectively to your reply... > - The parameters x, y & z will be initialized to known values. > - The values of x, y & z are normally fixed, but can be altered by users > (administrators) at runtime. Yes, very infrequentl

[Rails] Re: Recommendations for pdf generators

2010-03-16 Thread Grary
...and see Ryan Bates' Railscast on prawn: http://railscasts.com/episodes/153-pdfs-with-prawn Grar -- 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 rubyonrails-t...@googlegroups.com. To unsubscribe fr

[Rails] Re: what is the proper role of seed data?

2010-03-16 Thread Grary
at my data should be accessible by administrators, but what is the Rails mechanism for that access? Am I going to be issuing raw SQL commands? Thanks for any additional comment, Grary -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk"

[Rails] what is the proper role of seed data?

2010-03-16 Thread Grary
Hi, In my Rails app, I have some parameters whose values change only infrequently. These parameters are used in computations. Where is the place for data like this -- data that is particular to the application? On the one hand, I might think a flat file (yaml) is appropriate, but maybe I shouldn'

[Rails] noob question on associated records and their controller structure

2010-03-08 Thread Grary
rent model for later recovery? I would have guessed it was something like as follows: class ChildController... def create @parent = ParentModel.find(params[:id]) # How to get "current" parent from database? @parent.child = ChildModel.new(params[:child]) ... Any thoughts? Gra

[Rails] text_field value as a local variable in in-line template function

2010-03-05 Thread Grary
Hi, I'd like to conserve the sum total of several text fields on my form, even as I set them to blank upon a user link action. The following in-line snippet fails to store the value of my sum total field locally for eventual reassignment. (I am re-assigning it because the fields all have an obser

[Rails] nested model form javascript question (re Ryan Bates's Railscasts #196-7)

2010-02-28 Thread Grary
nk_to_function(name, h("add_fields(this, \"#{association}\", \"#{escape_javascript(fields)}\")")) end What I think I need to do is figure out how to append to some arbitrary place on the DOM, like the passed-in link element. I just don't know how. Thanks for any help, Gra

[Rails] accepts_nested_attributes_for vs. multiple controllers on one page

2010-02-25 Thread Grary
Hi, I'd like to render the results from show, create, edit and delete actions for several different models (one controller per model) on one page. While these several models are conceptually related, they do not need to be associated with each other. So, I'd rather not impose associations on them

[Rails] Re: how to validate uniqueness across multiple columns i

2010-02-23 Thread Grary
@Robert - Yes, I read that portion of the documentation and thanks for the reminder. Otherwise, of potential interest to discussants... I now have a migration adding a unique index to a model, like so: add_index :projects, [:name, :street_address, :city, :state, :zip], :uni

[Rails] Re: how to validate uniqueness across multiple columns in ActiveRecord?

2010-02-23 Thread Grary
Another fine idea, it would appear. But why do both? Does checking a combined parameters column before validation save me some kind of performance hit? Grar On Feb 23, 11:17 am, Michael Pavling wrote: > On 23 February 2010 01:30, Rick DeNatale wrote: > > > To create an index you can create a mi

[Rails] Re: how to validate uniqueness across multiple columns in ActiveRecord?

2010-02-23 Thread Grary
Rick, Thanks. That sounds exactly like what I'm after... Grary On Feb 22, 8:30 pm, Rick DeNatale wrote: > On Mon, Feb 22, 2010 at 4:54 PM,Grary wrote: > > Thanks Fred. > > > What do you mean by 'use a unique index'? > > > What I am concerned about

[Rails] Re: how to validate uniqueness across multiple columns in ActiveRecord?

2010-02-22 Thread Grary
Thanks Fred. What do you mean by 'use a unique index'? What I am concerned about is logical uniqueness, i.e., persist only data objects with a unique combination of attributes. Thanks, Grar On Feb 22, 3:54 pm, Frederick Cheung wrote: > On Feb 22, 8:52 pm, Grary wrote: > >

[Rails] how to validate uniqueness across multiple columns in ActiveRecord?

2010-02-22 Thread Grary
Hi, >From a model class, what is the standard way of ensuring uniqueness across multiple columns (attributes) simultaneously? In other words, I want to ensure only unique "rows" are persisted to storage. I feel like there must be a straightforward way to do this. Any suggestions? Thanks, Grar

[Rails] Re: ruby update on OS X 10.5 and I now this: "Rails requires RubyGems >= 1.3.2"

2010-02-17 Thread Grary
n Feb 17, 10:48 am, Frederick Cheung wrote: > On Feb 17, 1:59 pm, Grary wrote: > > > Fred, > > > I'm just hoping to get Rails working again, so I'll do whatever's > > easy... > > >  sudo gem install rubygems-update > >  sudo update_ruby

[Rails] Re: ruby update on OS X 10.5 and I now this: "Rails requires RubyGems >= 1.3.2"

2010-02-17 Thread Grary
Fred, I'm just hoping to get Rails working again, so I'll do whatever's easy... sudo gem install rubygems-update sudo update_rubygems ...I still get the same message. What did you mean when you wrote: "Sounds like you need to install rubygems for your new ruby install"? Thanks, Grar -- Yo

[Rails] Re: ruby update on OS X 10.5 and I now this: "Rails requires RubyGems >= 1.3.2"

2010-02-17 Thread Grary
Fred, Per your comment... "...if your PATH has /opt/local/bin higher up then the /opt/local install of ruby might not have rubygems at all. Sounds like you need to install rubygems for your new ruby install" ...yes, here is my path: /opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/

[Rails] ruby update on OS X 10.5 and I now this: "Rails requires RubyGems >= 1.3.2"

2010-02-17 Thread Grary
ings in RubyGems? Thanks for any help, Grary -- 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 rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsub