search for: associationcollection

Displaying 12 results from an estimated 12 matches for "associationcollection".

Did you mean: association_collection
2006 Jan 31
2
How can I overwrite the parent.children.push(child) Method?
Hi all I want to overwrite the push method (which is an alias of <<, the same as concat) of collections, and there I want to test if :uniq is set to true in the relationship. If so, the method should check if the passed object is already related to the parent, or not (only then it will be added). But I just can''t find the original code of this method, so I could overwrite
2006 Sep 25
2
@article.article_groups.delete_if... Dosn't work!
If I try: @article.article_groups.delete_if {|x| x.group_id == x.group_id } It does nothing. If I try: articletmp.article_groups.each{ |x| @article.article_groups.delete(y) } It deletes some of the groups. @article.article_groups.clear works. Why dosn''t the to first examples work as expected?? Do I have to put groups I don''t want to
2006 Mar 13
1
adding custom cache field
...antize.modify_value(\"#{self.to_s.underscore.pluralize + "_total"}\",#{association_primary_key}_type,-#{options[:total_cache]})" + " unless #{association_type}.nil?''" ) end end end class AssociationCollection def total count = if has_cached_total? @owner.send(:read_attribute,cached_total_attribute_name) end end def has_cached_total? @owner.attribute_present?(cached_total_attribute_name) end def cached_total_attribute_name...
2007 Nov 20
2
confirming that a model instance was correctly created from POST params
...s line 40 of the create_order_from_post method to set this property when an OrderAddress instance is created. But my example as shown tells me that assigns[:billing_address] is nil when I run it. Also, I realize that line 16 of the example isn''t returning the right thing; it should be an AssociationCollection of OrderAddress. That''s where I''m starting to wonder if I''m spending too much time on something that is probably simple enough that it''s already working but disproportionately hard to write an RSpec example for (because the existing create_order_from_post method...
2011 Sep 13
3
Accessing Rails helper method with_output_buffer
Hi all, I cannot figure out how to correctly use the with_output_buffer helper method (located in ActionView::Helpers::CaptureHelper) inside a custom FormBuilder. Below follows a simplified example. I''m trying to achieve the following behavior in an ERB as suggested in the form_for helper docs in the Rails source: ========== <%= form_for @object, :builder => MyFormBuilder do
2006 Feb 28
1
Cache Magic field for totaling
Hello, Rails provide counter cache field for associations, I want a similar cache for totaling up values (say account_balance = sum_of_deposits - sum_of_withdrawals). I was wondering if rails, already has another surprise in store for me, or is there any plug-in or how-to for doing these kind of things. Thanks. -- Surendra Singhi http://ssinghi.kreeti.com, http://www.kreeti.com Read the
2009 May 12
4
has_many :through and scopes: how to mutate the set of associated objects?
I have a model layer containing Movie, Person, Role, and RoleType, making it possible to express facts such as "Clint Easterbunny is director of the movie Gran Milano". The relevant model and associations look like this class Movie < ActiveRecord::Base has_many :roles, :include => :role_type, :dependent => :destroy has_many :participants, :through => :roles, :source
2008 Mar 23
6
Locals do not appear in partial unless collection is explici
Maybe I''m misunderstanding something but it appears as if <%= render :partial => @items, @locals => { :this => ''that'' } %> does not give the local variable this but this one does: <%= render :partial => ''items/item'', :collection => @items, @locals => { :this => ''that'' } %> Shouldn''t they mean
2007 Jan 23
4
Rails bug reports & patches - why no action?
I have noticed at the dev.rubyonrails.org site that many tickets with pretty clear-cut bug reports/patches or feature enhancements don''t get any attention. They sit there for months at a time. Why is this? Are tickets from those that are not in rails-core deprioritized? Are there just not enough people that have the power to act on tickets? I know it''s not lack of test cases
2010 Apr 13
5
How to check if a parent has children?
What is the new way to check if a parent has child items? In rails 1.2.6 I did this: if @client.has_line_items? Client being the parent and line_items the children. Now that I have upgraded to rails 2.0.1 (on my way to current :-) ) I am getting this message: undefined method `has_line_items?'' for #<Client:0x7f3b093b01a0> How should I format the query now? Regards, Paul
2006 Jul 02
0
Rails Core Weekly June 19 - July 2 2006
...method read http://weblog.rubyonrails.org/2006/4/26/new-in-rails-module-alias_method_chain. You might never use it since it''s internal to Rails but study it nevertheless to sharpen your Ruby-mind. Also, DHH adds Enumerable#sum for calculating a sum from the elements (incidently shadowing AssociationCollection#sum but that is fixed quickly enough). Also Jeremy makes it a bit better by making it block-less Example: payments.sum { |p| p.price * p.tax_rate } payments.sum(&:price) or simply block-less: [1,2,3].sum # => 6 DHH explains this is instead of payments.inject(0) { |sum, p| sum + p.price...
2009 May 27
12
query on Ruby array
Looking for suggestions on following two queries. Query 1 ------------------------------ Are the two following lines of code different in Ruby / Rails ( in a *.html.erb) file. <% if @forms.count != 0 %> <!-- first code --> Vs. <% if @forms.count %> <!--second code --> @forms is an array of objects. Coming from "C" language development background, i thought