[Rails] Re: modules

2012-09-06 Thread John Merlino
thanks for response On Sep 6, 5:32 am, Frederick Cheung frederick.che...@gmail.com wrote: On Thursday, September 6, 2012 2:39:00 AM UTC+1, John Merlino wrote: module ActionView   module Helpers     module FormHelper       def form_for(foo, bar)          instantiate_builder(foo, bar

[Rails] Re: modules

2012-09-06 Thread John Merlino
executes the block only after ActionView is loaded and then yields ActionView to the block so that default_form_builder will become a class method on ActionView, which returns the FormBuilder class object. On Sep 6, 11:46 am, John Merlino stoici...@aol.com wrote: thanks for response On Sep 6

[Rails] modules

2012-09-05 Thread John Merlino
module ActionView module Helpers module FormHelper def form_for(foo, bar) instantiate_builder(foo, bar) end def instantiate_builder(foo,bar) self end end end end self in instantiate_builder refers to ActionView::Helpers::FormHelper. self it

[Rails] :index option to form_for

2012-09-05 Thread John Merlino
I was looking in the Rails source code, and during the call to form_for, it creates a new instance of FormBuilder and during the initialization, it checks if the options hash contains an index: @default_options = @options ? @options.slice(:index, :namespace) : {} When will the options hash

[Rails] Regexp pre_match

2012-09-05 Thread John Merlino
I looked in ruby documentation http://www.ruby-doc.org/core-1.9.3/Regexp.html I cannot find a method called pre_match but its used in Rails... @template.instance_variable_get(@#{Regexp.last_match.pre_match}) -- You received this message because you are subscribed to the Google Groups Ruby on

[Rails] Re: RoutesProxy

2012-09-04 Thread John Merlino
I would like to bump this. Simple question. When will the first element of an array passed as first argument to form_for ever be an instance of RoutesProxy? The rails source looks for this, so I am sure someone out there has examples. On Sep 3, 2:05 pm, John Merlino stoici...@aol.com wrote: when

[Rails] RoutesProxy

2012-09-03 Thread John Merlino
when passing an array as first argument to form_for, polymorphic_url checks if first index is an instance of ActionDispatch::Routing::RoutesProxy: def polymorphic_url(record_or_hash_or_array, options = {}) if record_or_hash_or_array.kind_of?(Array) record_or_hash_or_array =

[Rails] ActionView module declared several times

2012-09-03 Thread John Merlino
The ActionView module is declared several times in the Rails source: rails/actionpack/lib/action_view/base.rb,rails/actionpack/lib/ action_view/buffers.rb,rails/actionpack/lib/action_view/digestor.rb, rails/actionpack/lib/action_view/helpers/asset_tag_helpers/ asset_paths.rb, and the list goes on

[Rails] polymorphic_url

2012-09-03 Thread John Merlino
In polymorphic_routes.rb, polymorphic_url is defined in rails source from github,and this particular line: inflection = if options[:action] options[:action].to_s == new args.pop :singular elsif (record.respond_to?(:persisted?) !record.persisted?)

[Rails] undefined method `singular_route_key' for User:ActiveModel::Name

2012-09-03 Thread John Merlino
In ActionDispatch::PolymorphicRoutes, there is a call to build_named_route_call an on line 172 (of latest rails code from github), there is a call to singular_route_key: model_name_from_record_or_class(parent).singular_route_key Now model_name_from_record_or_class returns an ActiveModel::Name

[Rails] dynamic route generation

2012-09-03 Thread John Merlino
In polymorphic_routes.rb, line 131, a name route that has been built (e.g. post_users_path) gets invoked on self (assuming there was not RoutesProxy instance appended as the first element of the array passed as the first argument to form_for, then send() would be invoked on self, which is

[Rails] Re: ActionView module declared several times

2012-09-03 Thread John Merlino
Yes, it is a basic feature of ruby that you can reopen a class definition. I forgot about that. On Sep 3, 4:05 pm, Colin Law clan...@googlemail.com wrote: On 3 September 2012 19:08, John Merlino stoici...@aol.com wrote: The ActionView module is declared several times in the Rails source

[Rails] Re: polymorphic_url

2012-09-03 Thread John Merlino
Oh, I figured this one out. Reason why the else doesn't pop the last element is because the last element is the object passed to form_for that has been persisted, and that element is needed in the array for the id value when we invoke send on the dynamic route generated. On Sep 3, 2:57 pm, John

[Rails] default form helper

2012-09-02 Thread John Merlino
On line 1152 of form_helper.rb, there is this line: def default_form_builder builder = ActionView::Base.default_form_builder builder.respond_to?(:constantize) ? builder.constantize : builder end I tried searching for default_form_builder on ActiveView::Base

[Rails] default form helper

2012-09-02 Thread John Merlino
On line 1152 of form_helper.rb, there is this line: def default_form_builder builder = ActionView::Base.default_form_builder builder.respond_to?(:constantize) ? builder.constantize : builder end I tried searching for default_form_builder on ActiveView::Base

[Rails] Re: default form helper

2012-09-02 Thread John Merlino
Ok, nevermined, it appears when Active support loaded, its defined as a class method on actionview: ActiveSupport.on_load(:action_view) do cattr_accessor(:default_form_builder) { ::ActionView::Helpers::FormBuilder } end On Sep 2, 12:57 pm, John Merlino stoici...@aol.com wrote: On line

[Rails] to_model

2012-09-02 Thread John Merlino
There's a number of calls in the Rails source to convert_to_model, which takes an activerecord object instance: convert_to_model(object) Here's the thing. All convert_to_model does is calls to_model, which returns self (the ActiveModel instance). Am I missing something here? Why call a method

[Rails] Re: to_model

2012-09-02 Thread John Merlino
Is it just there as a default, to return itself, if a to_model doesn't override it on the model itself On Sep 2, 6:05 pm, John Merlino stoici...@aol.com wrote: There's a number of calls in the Rails source to convert_to_model, which takes an activerecord object instance: convert_to_model

[Rails] routes for new resources

2012-08-17 Thread John Merlino
Does anyone know what the controller code would look like for a route like this: resources :reports do new do post :preview end end and a helper that looks like this: preview_new_report_path thanks for response -- You received this message because you are subscribed to the Google

[Rails] Re: routes for new resources

2012-08-17 Thread John Merlino
actually, let me rephrase this. That route points to the preview action of a reports controller, but why is it a POST for a new resource? On Aug 17, 11:32 am, John Merlino stoici...@aol.com wrote: Does anyone know what the controller code would look like for a route like this: resources

[Rails] invoking an activerecord relation method on the result of a calculation method, which returns a FixNum type

2012-08-12 Thread John Merlino
I was seeing these examples in a book: Person.minimum(:age).where('last_name ?', 'Drake') Person.minimum(:age).having('min(age) 17').group(:last_name) The thing is minimum is returning a FixNum. When invoking the relation methods (e.g. where, having) on a fixnum will raise an exception:

[Rails] before_validation an before_validation_on_create

2012-08-05 Thread John Merlino
I'm not sure what's the difference between before_validation an before_validation_on_create. Is it that before_validation gets invoked before a create and update call, whereas the latter just gets invoked on create call? -- You received this message because you are subscribed to the Google

[Rails] ActiveRecord::Validator vs ActiveModel::Validator

2012-08-04 Thread John Merlino
I know that there is an ActiveModel Validator class https://github.com/rails/rails/blob/master/activemodel/lib/active_model/validator.rb which is used for the class level validation macros. But I didn't find a an ActiveRecord Validator class. From my understanding in Rails 3, validations have

[Rails] Re: accepts_nested_attributes_for, validates_associated, and validates_presence_of within a has_many/belongs_to

2012-08-01 Thread John Merlino
On Aug 1, 10:41 am, Dave Aronson googlegroups2d...@davearonson.com wrote: On Wed, Aug 1, 2012 at 12:09 AM, John Merlino stoici...@aol.com wrote: this will raise an error, because project_id does not exist yet, since the project has not been saved yet. Can you create the project first, saving

[Rails] Re: ActiveRecord::Reflection active_record read-only method

2012-07-31 Thread John Merlino
...@gmail.com wrote: On Tuesday, July 31, 2012 2:09:41 AM UTC+1, John Merlino wrote: Account.reflect_on_association(:users).active_record  = Account(id: integer, name: string, created_at: datetime, updated_at: datetime, ancestry: string, street_address: string, city: string, postal_code

[Rails] is AssociationProxy a subclass or a module of Association?

2012-07-31 Thread John Merlino
In the Rails documentation, it shows Association::AssociationProxy, and I know that in ruby :: operator is a reference to a constant, and a constant can either be a module or a class. So I ask because I'm just curious how the two behave together. Thanks for response. -- You received this message

[Rails] accepts_nested_attributes_for, validates_associated, and validates_presence_of within a has_many/belongs_to

2012-07-31 Thread John Merlino
In a popular Rails book:

[Rails] Re: accepts_nested_attributes_for, validates_associated, and validates_presence_of within a has_many/belongs_to

2012-07-31 Thread John Merlino
prompt to check if the association are valid next), and since the project has not yet been saved, this will raise an error, because project_id does not exist yet, since the project has not been saved yet. So why does book say to use validates_presence_of :project_id? On Jul 31, 11:57 pm, John

[Rails] ActiveRecord::Reflection active_record read-only method

2012-07-30 Thread John Merlino
I was horsing around with the reflect_on_assocation class method of ActiveRecord Reflection, which returns an instance of AssociationReflection. One of its methods is called active_record. I run it in console: Account.reflect_on_association(:users).active_record = Account(id: integer, name:

[Rails] Re: Confused about testing options for rails

2012-07-28 Thread John Merlino
You would either use RSpec or Test::Unit. Test unit built into rails while rspec seems to be the flavor of the day. I use capybara for cucumber testing, when you want human-readable output as part of your test suite. factory girl is a replacement to rails fixtures, which are unreliable. On Jul

[Rails] find_or_initialize_by_id block parameter

2012-07-28 Thread John Merlino
On the other forum on stackoverflow, someone provided this as a solution for the following use case: I want to check by an unique ID whether a record is already created. If it is, I want to add 1 to the amount attribute. If it is not, I want to create it and set the amount attribute to 1. Here

[Rails] :validate = true on a belongs_to

2012-07-27 Thread John Merlino
:validate = true on a belongs_to tells Rails to validate the owner record when the owner record is being saved in order to get a foreign key value for the association. This doesn't seem to make sense, because you cannot save an association without saving first the owning record, so let's say:

[Rails] the :group and :having options on a has_many

2012-07-27 Thread John Merlino
I noticed the has_many relationship method allows for :group and :having options. Can anyone provide an example of when these would be used in a has_many? Something like this? has_many :accounts, :select = 'name, SUM(cash) as money', :group = :name, :having = 'created_at ?, 2.days.ago' I cant

[Rails] testing references

2012-07-23 Thread John Merlino
I am struggling somewhat with testing. And I would like to know a comprehensive reference on rails unit test. I find the railscasts 5 minute video not comprehensive. I have the ruby programming language, design patterns in ruby, and rails 3 way books and none of them delve at all into testing. So

[Rails] Re: ceil method

2012-07-13 Thread John Merlino
Yeah that's pretty much the key point - that return type of invoking the / method of integer and passing it a decimal is a decimal type cast. On Jul 12, 12:45 pm, Dave Aronson googlegroups2d...@davearonson.com wrote: On Thu, Jul 12, 2012 at 1:13 AM, John Merlino stoici...@aol.com wrote

[Rails] ceil method

2012-07-11 Thread John Merlino
Often times the ceil method is used for patterns that involve grouping. For example, if I have an array of objects and I want to group them in rows of 3, I might do this: (@objects.size / 3.0).ceil So if size returns 2, then the above expression returns 1. Here's my question. In terms of

[Rails] why use rescue nil?

2012-06-19 Thread John Merlino
Hey all, I saw this piece of code: @user = User.find(params[:user_id]) rescue nil why rescue with a nil here? If the user is not found, it will be nil anyway. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send

[Rails] Re: why use rescue nil?

2012-06-19 Thread John Merlino
ok I thought it would return nil thanks for response On Jun 19, 8:33 pm, Fernando Almeida ferna...@fernandoalmeida.net wrote: if the record is not found the find() throws an exception. 2012/6/19 John Merlino stoici...@aol.com Hey all, I saw this piece of code: @user

[Rails] route is not loading correct action

2012-06-07 Thread John Merlino
Hey all, When I run rake routes, I see this: inventory_dashboard /inventory/ (.:format) {:action=show, :controller=inventory} when I invoke this: inventory_dashboard_path I get this: Processing InventoryController#index (for 127.0.0.1 at 2012-06-07

[Rails] find the last two records with a certain field value

2012-06-01 Thread John Merlino
I have a situation where a code can be toggled on/off so a record is sent to database with a value of 1 or 2 for code. So lets say it was toggled 4 times: id, code, time 1, 1, 2012-05-31 22:05:24 2, 2, 2012-05-31 22:05:25 3, 2, 2012-05-31 22:05:26 4, 2, 2012-05-31 22:05:27 So it was toggled

[Rails] Re: find the last two records with a certain field value

2012-06-01 Thread John Merlino
I'm basically looking for something more elegant than this: item = [] item last_on = where{:code = 8}.order('time desc').limit(1) item last_off = where{:code = 9}.order('time desc').limit(1) On Jun 1, 3:23 pm, John Merlino stoici...@aol.com wrote: I have a situation where

[Rails] multiple arguments to select

2012-05-13 Thread John Merlino
I read in the Rails 3 Way book that when using select(), you can, in addition to adding calculated columns (i.g. using sql aggregate functions), include additional attributes in resulting object by passing the wild card like this: Unit.select(:*,sum(unit_type_id) as

[Rails] (eval):1: syntax error, unexpected $undefined

2012-05-01 Thread John Merlino
On rails 3 and ruby 1.9.2, I get this error: (eval):1: syntax error, unexpected $undefined $#MenuBuilder:0x007fd9360719a0 = #MENUBUILDER:0X007FD9360719A0 ^ Not sure where to start with this. Everything looks fine to me: #_main_menu.html.haml #main-menu = menu do |m| = m.submenu Products

[Rails] Re: validating a date range based on current object's attributes

2012-04-30 Thread John Merlino
yeah i was using rails 2 thanks for response On Apr 22, 10:53 pm, Frederick Cheung frederick.che...@gmail.com wrote: On Apr 23, 6:46 am, John Merlino stoici...@aol.com wrote: Hey all, I look at the rails documentation validation helpers: http://api.rubyonrails.org/classes

[Rails] undef keyword with symbol

2012-04-30 Thread John Merlino
I see something like this: require ostruct class OptionsWrapper OpenStruct undef :id, :class def [](key) send(key) end def []=(key, value) send(#{key}=, value) end def method_missing(method, *args, block) return @table.include?(method) ? @table.send(method) : nil if

[Rails] Re: undef keyword with symbol

2012-04-30 Thread John Merlino
that makes sense, thanks On Apr 30, 12:41 pm, Tim Shaffer timshaffe...@gmail.com wrote: id and class are built-in ruby methods that are present on all object instances. Rails uses them in a different manner than the default Ruby implementation. They are undefined so that they can be picked

[Rails] validating a date range based on current object's attributes

2012-04-22 Thread John Merlino
Hey all, I look at the rails documentation validation helpers: http://api.rubyonrails.org/classes/ActiveModel/Validations/HelperMethods.html It has this example: class Person ActiveRecord::Base validates_inclusion_of :states, :in = lambda{ |person| STATES[person.country] } end So basically

[Rails] Re: strange javascript rendering

2012-03-27 Thread John Merlino
This was a simple fix. You dont escape html in rails 3. On Mar 26, 5:38 pm, John Merlino stoici...@aol.com wrote: I have a form helper that looks like this: #_alert.html.haml = add_field_link Add Email, f, :notification_emails #application_helper.rb   def add_field_link(name, f

[Rails] strange javascript rendering

2012-03-26 Thread John Merlino
I have a form helper that looks like this: #_alert.html.haml = add_field_link Add Email, f, :notification_emails #application_helper.rb def add_field_link(name, f, association) new_object = f.object.class.reflect_on_association(association).klass.new fields = f.fields_for(association,

[Rails] difference between merging a hash in ruby and using merge_conditions of activerecord

2012-03-23 Thread John Merlino
The ruby library comes with a method called merge that allows you to merge two hashes. So then why does merge_conditions exist in activereocrd, which appears to be doing the same thing. thanks for response -- You received this message because you are subscribed to the Google Groups Ruby on

[Rails] update a list of model instances and their associations

2012-03-21 Thread John Merlino
I have been unable to figure out how to update a list of model instances and their associations and I have looked in the documentation, which doesnt give an example of what I am trying to do: http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-fields_for I would assume

[Rails] rails source fields_for has an options hash not defined anywhere

2012-03-21 Thread John Merlino
Hey all, I looked at source code for fields_for: def fields_for(record_name, record_object = nil, fields_options = {}, block) fields_options, record_object = record_object, nil if record_object.is_a?(Hash) record_object.extractable_options? fields_options[:builder] ||= options[:builder]

[Rails] nested attribute relationship never renders in form

2012-03-16 Thread John Merlino
Hey all, I tried following this railscasts: http://railscasts.com/episodes/196-nested-model-form-part-1 But there is one significant difference from what that does and what I am trying to do. That builds a relationship to one object. In my form, i have a list of objects and want to build

[Rails] Re: 110.years.ago.to_datetime returns wrong date

2012-03-15 Thread John Merlino
There wont be a specific timezone, people will use it in all timezones and so I would need it to work for everyone. This issue started for me when I had this: validates_inclusion_of :date_of_birth, :in = 110.years.ago.to_datetime..60.years.ago.to_datetime, :message = :invalid_age, :allow_nil

[Rails] simulating behavior without actually affecting database

2012-03-09 Thread John Merlino
Hey all, A lot of people use factory girl to simulate behavior without affecting database, particularly for testing. I have a situation where this is not for testing but rather someone clicks on button to simulate behavior but we create a User object in order to run the simulation but while I

[Rails] Re: getting find_by_sql to return the numeric value rather than an object that contains the value as an attribute

2012-03-08 Thread John Merlino
Using this technique: Report.where(unit_id=? AND id = ? AND id = ?, unit_id, report1, report2).sum('distance') was ultimately the best solution for me, because using find_by_sql and then calling sum on it would behave unexpectedly, like sometimes the sum would have to be invoked twice:

[Rails] getting find_by_sql to return the numeric value rather than an object that contains the value as an attribute

2012-03-06 Thread John Merlino
Hey all, So I have a custom query that I embedded into a class method definition: def self.get_sum_for_range(unit_id,report1,report2) find_by_sql([SELECT SUM(distance * 0.000621371192) as sum FROM reports WHERE unit_id=? AND id = ? AND id = ?, unit_id, report1, report2]) end value =

[Rails] Re: ensuring random list of numbers are unique

2012-02-29 Thread John Merlino
thanks for responses, the ultimate goal was just to ensure a list of 500 (no more or less) unique random decimals that are 3 places which would be generated only one time. Currently Im storing them as a float in the mysql database. -- You received this message because you are subscribed to the

[Rails] why does self.included work but not include/extend

2012-02-29 Thread John Merlino
I have interesting situation. a.rb #file class A include M end b.rb #file module M include X extend Y end module X def instance_method end end module Y def class_method end end A.class_method = undefined method class_method Thats strange because what I expect to happen is module M

[Rails] ensuring random list of numbers are unique

2012-02-28 Thread John Merlino
Hey all, using ruby 1.8.7, I wrote this: 500.times.map { Integer((rand * 1) * 1000) / Float(1000) } Basically, this gives me a list of 500 random decimal numbers that are rounded to 3 places. However, I also want to make sure that all are unique. thanks for response -- You received this

[Rails] delete a cookie when wrong password is entered in devise

2012-02-27 Thread John Merlino
How do you have control (in this case deleting a cookie) after devise has determined that a user has entered the wrong password in the latest version of devise. I have my own custom failure app but cookies are not accessible within it: class CustomFailureApp Devise::FailureApp def respond

[Rails] Using Net::HTTP to send data to another server

2012-02-27 Thread John Merlino
Hey all, I have a form, when it posts, if it fails, it sends a response back to the client. Now I want to take the response data and then send it to a wordpress blog for the wordpress to handle it. I already set up the rails app as a proxy to the wordpress blog when a certain page is invoked. My

[Rails] question about passing an array iterator instance to a block

2012-02-25 Thread John Merlino
I was always under assumption that the block accepts the return value of the iterator as the argument to the block, but look at this: Array.new(500) do | i | puts i end I expect i to be an array instance with 500 indexes all will nil values. However, what it returns is indeed an array

[Rails] Re: question about passing an array iterator instance to a block

2012-02-25 Thread John Merlino
. It obviously is an integer. Otherwise this would have failed with (id +1). On Feb 25, 2:55 pm, Valery Kvon adda...@gmail.com wrote: On 25.02.2012, at 23:41, John Merlino wrote: I was always under assumption that the block accepts the return value of the iterator as the argument to the block, but look

[Rails] Re: question about passing an array iterator instance to a block

2012-02-25 Thread John Merlino
. And then the return value is passed back to the resutlt of the yield and that value is then idnexed into the array until the size limit has been reached. On Feb 25, 3:15 pm, Valery Kvon adda...@gmail.com wrote: On 26.02.2012, at 0:07, John Merlino wrote: thanks for response but that was just an example

[Rails] Re: the ^ and % operators in context

2012-02-06 Thread John Merlino
This is not actually a piece of code I would use, but rather something from a book thats a mental exercise. On Feb 4, 7:20 pm, Robert Walker li...@ruby-forum.com wrote: John Merlino wrote in post #1044105: The % is modulus (remainder)operatorand ^ is bitwise. In this context, we take a file

[Rails] the ^ and % operators in context

2012-02-04 Thread John Merlino
The % is modulus (remainder) operator and ^ is bitwise. In this context, we take a file, and go through each character and encrypt it. But why are the ^ and % operators used here: def encrypt(reader, writer) key_index = 0 while not reader.eof? clear_char = reader.getc

[Rails] Re: both with_index and each_with_index not working

2012-01-25 Thread John Merlino
Maybe the title of this post sounds crazy but its true. - iterate_for(@reports) - @reports.to_enum.with_index(1).each do |r, i| - r.alerts.reverse.each do |a| - if a.code == 14 %tr %td.num_col Trip #{i} - elsif a.code == 15

[Rails] Re: both with_index and each_with_index not working

2012-01-25 Thread John Merlino
After typing second message, I realized the nested loop was causing the issue. -- 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 unsubscribe from this group, send

[Rails] Re: undefined method `gsub!' for 2012-01-22 17:00:00 -0500..2012-01-23 00:00:00 -0500:Chronic::Span

2012-01-23 Thread John Merlino
Meinlschmidt to...@meinlschmidt.com wrote: On Jan 22, 2012, at 23:36 , John Merlino wrote: Hey all, I am getting this error: NoMethodError (undefined method `gsub!' for 2012-01-22 17:00:00 -0500..2012-01-23 00:00:00 -0500:Chronic::Span): in this code:          date_range

[Rails] Re: undefined method `gsub!' for 2012-01-22 17:00:00 -0500..2012-01-23 00:00:00 -0500:Chronic::Span

2012-01-23 Thread John Merlino
using Chronic.parse without false got rid of that issue On Jan 23, 10:21 am, John Merlino stoici...@aol.com wrote: thanks for response, Now I get a new issue: ActiveRecord::StatementInvalid in HomesController#map PGError: ERROR:  time zone displacement out of range: (2012-01-23 10:00:00

[Rails] both with_index and each_with_index not working

2012-01-23 Thread John Merlino
- @reports.to_enum.with_index(1).each do |r, i| - r.alerts.reverse.each do |a| - if a.code == 14 %tr %td.num_col Trip #{i} %td.start_col #{r.time} %td.end_col %td.distance_col #{0} i should equal 1

[Rails] Re: why doesn't an instance of Object get Class's new instance method?

2012-01-22 Thread John Merlino
thanks for responses On Jan 21, 4:24 pm, Peter Vandenabeele pe...@vandenabeele.com wrote: On Sat, Jan 21, 2012 at 9:03 PM, John Merlino stoici...@aol.com wrote: Object is the root of Ruby's class hierarchy. Its methods are available to all classes unless explicitly overridden. Wouldn't

[Rails] undefined method `gsub!' for 2012-01-22 17:00:00 -0500..2012-01-23 00:00:00 -0500:Chronic::Span

2012-01-22 Thread John Merlino
Hey all, I am getting this error: NoMethodError (undefined method `gsub!' for 2012-01-22 17:00:00 -0500..2012-01-23 00:00:00 -0500:Chronic::Span): in this code: date_range = Chronic.parse(the_date, :guess = false)

[Rails] why doesn't an instance of Object get Class's new instance method?

2012-01-21 Thread John Merlino
Object is the root of Ruby's class hierarchy. Its methods are available to all classes unless explicitly overridden. Wouldn't Class class be at the root of the class hierarchy? After all, look at this: 1.9.2p290 :006 Object.instance_of? Class = true Object is an instance of class, after all

[Rails] Re: why doesn't an instance of Object get Class's new instance method?

2012-01-21 Thread John Merlino
. Then why: n = m.new doesnt new create an object that gives n access to m's class methods, as it did in the other case? On Jan 21, 3:03 pm, John Merlino stoici...@aol.com wrote: Object is the root of Ruby's class hierarchy. Its methods are available to all classes unless explicitly overridden

[Rails] Internal Server Error Mysql2::Error: Lock wait timeout exceeded; try restarting transaction

2012-01-19 Thread John Merlino
Hey all, When running a cucumber test, I get this: Internal Server Error Mysql2::Error: Lock wait timeout exceeded; try restarting transaction: INSERT INTO `users` (`address_1`, `address_2`, `address_3`, `can_receive_sms`, `city`, `completed_terms_on`, `country_id`, `created_at`,

[Rails] formatting a date string

2012-01-17 Thread John Merlino
Hey all, I have 90 records in database with this kind of format: 2011-05-10 11:23:15 So they are all 2011-05-10 but have different times. User enters two dates, and just in case the two dates are the same, I want to ensure I grab all records that span entire day. So I do this:

[Rails] Re: formatting a date string

2012-01-17 Thread John Merlino
')).end_of_day) On Jan 17, 8:26 pm, John Merlino stoici...@aol.com wrote: Hey all, I have 90 records in database with this kind of format: 2011-05-10 11:23:15 So they are all 2011-05-10 but have different times. User enters two dates, and just in case the two dates are the same, I want

[Rails] Chronic parsing date range in console but not in application in rails 3

2012-01-01 Thread John Merlino
Hey all, Chronic will parse a date range in console: Chronic.parse(1/1/2011 - 1/1/2012, :guess = false) = 2012-01-01 12:00:00 -0500..2012-01-01 12:00:01 -0500 However, when I use logger to check if it's parsing in application, it is not: logger.info The value of history date is

[Rails] Re: Chronic parsing date range in console but not in application in rails 3

2012-01-01 Thread John Merlino
(Date.parse(history_date), :guess = false) else date_range = Chronic.parse(history_date, :guess = false) end Im open to better solutions. thanks for response On Jan 1, 12:54 pm, John Merlino stoici...@aol.com wrote: Hey all, Chronic will parse

[Rails] Re: Chronic parsing date range in console but not in application in rails 3

2012-01-01 Thread John Merlino
, Jan 1, 2012 at 9:54 AM, John Merlino stoici...@aol.com wrote: Chronic will parse a date range in console: However, when I use logger to check if it's parsing in application, it is not: Loading development environment (Rails 3.1.2) ruby-1.9.2-p290 :001 result = Chronic.parse(1/1/2011 - 1/1

[Rails] adding methods to objects that were created on the fly

2011-12-19 Thread John Merlino
Hey all, I call this method to create two objects with certain attributes but because of this, these objects do not have the attributes of any of the report object instantiated normally: def self.sum_distance_by_date find_by_sql(SELECT date_trunc('day', time), SUM(distance) FROM reports

[Rails] finding out where to modify virtual host settings in rails, passenger, apache setup

2011-12-10 Thread John Merlino
Hey all, I have a domain, let's say: dev.mysite.com And I want it to listen on port 3000: dev.mysite.com:3000 Now this is on a remote webserver (not my local apache setup). I have access to the server (which is apache and it's running on ubuntu os). This server is a rails application in it

[Rails] Re: finding out where to modify virtual host settings in rails, passenger, apache setup

2011-12-10 Thread John Merlino
I read this article: http://codecolossus.com/2008/04/12/configurating-passenger-mod_rails-on-slicehost-with-ubuntu-710/ And it says that: Passenger doesn’t even require virtual hosts to configure themselves as Rails applications. It will automatically detect a Rails application So maybe that's

[Rails] get json from resetting password in devise

2011-11-28 Thread John Merlino
Hey all, When logging in and out using devise I know to override the sign_in_and_redirect method that devise provides in my users sessions controller, however when I want to get json response when resetting password, I dont know what method to override and where. I do know of recoverable module

[Rails] Re: undefined method `macro' for nil:NilClass

2011-11-18 Thread John Merlino
Frederick Cheung wrote in post #1032161: On Nov 16, 1:46pm, John Merlino stoici...@aol.com wrote: thanks for response THis here would produce syntax error: :include = {:reports, :notifications = :notification_codes} oops, that should have been [:reports, {:notifications

[Rails] Re: undefined method `macro' for nil:NilClass

2011-11-16 Thread John Merlino
(:id = params[:user_id]).first.units.to_json({:include = {:reports = {}, :notifications = :notification_codes}}) But this will say: can't convert Symbol into Hash On Nov 16, 3:14 am, Frederick Cheung frederick.che...@gmail.com wrote: On Nov 15, 11:06 pm, John Merlino stoici...@aol.com wrote

[Rails] undefined method `macro' for nil:NilClass

2011-11-15 Thread John Merlino
this error usually occurs when trying to mix 1st and 2nd order relationships in a single to_json call: undefined method `macro' for nil:NilClass Rails 3 has this way to support 2nd order relationships: http://apidock.com/rails/ActiveRecord/Serialization/to_json So I try to use it:

[Rails] Re: undefined method `macro' for nil:NilClass

2011-11-15 Thread John Merlino
On Tue, Nov 15, 2011 at 9:06 PM, John Merlino stoici...@aol.com wrote: this error usually occurs when trying to mix 1st and 2nd order relationships in a single to_json call: undefined method `macro' for nil:NilClass Rails 3 has this way to support 2nd order relationships: http

[Rails] Re: getting devise to return json data when signing out

2011-11-03 Thread John Merlino
I also asked this on stackoverflow: http://stackoverflow.com/questions/7997009/rails-3-getting-devise-to-return-json-data-when-signing-out I am finding it difficult to resolve this issue. On Nov 2, 7:43 pm, John Merlino stoici...@aol.com wrote: Hi all, In curl (the command line program), I

[Rails] getting devise to return json data when signing out

2011-11-02 Thread John Merlino
Hi all, In curl (the command line program), I can successfully log a user in using devise: def create respond_to do |format| format.json { if user_signed_in? return render :json = {:success = true, :errors = [Already logged in.]} end

[Rails] Re: nested routes not rendering properly in link helper

2011-11-01 Thread John Merlino
thanks for response, the solution I provided also works if you want to pass params in hash via query string when there isn't a direct association between multiple models On Oct 31, 3:26 pm, Tim Shaffer timshaf...@me.com wrote: On Sunday, October 30, 2011 9:31:50 PM UTC-4, John Merlino wrote

[Rails] Re: nested routes not rendering properly in link helper

2011-10-31 Thread John Merlino
This was easy resolution: send_activation_notification(:user_id = @user.id, :account_id = @account.id) That will pass the params in query string -- 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: each iterator passing in nil

2011-10-30 Thread John Merlino
at 00:09, John Merlino stoici...@aol.com wrote: ruby-1.9.2-p136 :095 portfolio.each {|n, b| n = b } NoMethodError: undefined method `balance' for nil:NilClass It appears that the each iterator does not support passing in two arguments? Correct.  each means apply this block to each

[Rails] nested routes not rendering properly in link helper

2011-10-30 Thread John Merlino
hey all, I have this: scope :path = '/activation', :controller = :activation do post create = :create get confirmation = :confirmation, :as = confirmation get send_activation_notification = :send_activation_notification, :as = send_activation do

[Rails] Re: adding key/value pairs to hash wrongfully adds a right bracket

2011-10-28 Thread John Merlino
thanks for response, code was an integer, and :code was just a key of the session hash. But I decided in end to make this database backed. On Oct 23, 3:19 pm, Dave Aronson googlegroups2d...@davearonson.com wrote: On Mon, Oct 17, 2011 at 17:27, John Merlino stoici...@aol.com wrote: THis line

[Rails] each iterator passing in nil

2011-10-28 Thread John Merlino
Hi all, In Rails console (just doing a general exercise in ruby design patterns), I create two classes: ruby-1.9.2-p136 :023 class A ruby-1.9.2-p136 :024? attr_accessor :name, :balance ruby-1.9.2-p136 :025? def initialize(name, balance) ruby-1.9.2-p136 :026? @name = name ruby-1.9.2-p136

[Rails] Re: adding key/value pairs to hash wrongfully adds a right bracket

2011-10-19 Thread John Merlino
] code if key So if you see a problem here, maybe I am not understanding. thanks for response On Oct 18, 6:26 am, Frederick Cheung frederick.che...@gmail.com wrote: On Oct 17, 10:27 pm, John Merlino stoici...@aol.com wrote: Hey all, THis line of code gets called multiple times and creates

[Rails] adding key/value pairs to hash wrongfully adds a right bracket

2011-10-17 Thread John Merlino
Hey all, THis line of code gets called multiple times and creates a hash: def session_code(unit_id, code) s_code = session[:code] unit_id_hash = s_code.detect {|h| h[unit_id]} if unit_id_hash.nil? unit_id_hash = {} s_code {unit_id = unit_id_hash} end key =

<    1   2   3   4   >