Displaying 20 results from an estimated 1100 matches similar to: "Trimming a collection of AR objects?"
2013 Sep 17
4
Rails 4 deprecation of in-place edit methods for collection associations
Hi everyone!
For those of you who are not noticed the in-place edit method for
collection associations are broken in the current rails release - 4.0.0,
and here''s what is cooking in the rails master
https://github.com/rails/rails/commit/1a40be02113287d9a003f8224e91b9f623857f4b
and this https://github.com/rails/rails/pull/12227
In short: it looks like things like has_many.reject!{},
2006 Aug 08
12
delete_if doesn''t work for has_and_belongs_to_many
I''m using Rails-1.1.4 with Ruby-1.8.4
So let''s say I have 2 model classes:
class Item
has_and_belongs_to_many :things
end
class Thing
has_and_belongs_to_many :items
end
i = Item.new
i.things << Thing.new( :value => "Something").save
i.things << Thing.new( :value => "Something Else" ).save
i.save
Fine, now I have two records in the
2006 May 23
6
How to list all models of an application?!?
How can I get a list of all model classes in the domain of a Rails
application (all models, both in "app/models" and in
components/somedir/model.rb)?
Thanx in advance for your precious help!
Edoardo "Dado" Marcora
2009 Feb 04
2
delete_if does not work on associations
I tried to user delete_if on an association:
class Group < ActiveRecord::Base
has_many :memberships, :dependent => :destroy
has_many :users, :through => :memberships
...
end
This is the controller method, trying to use delete_if. Although some
elements are removed (s2 < s1), the save method does not update the
association.
def intersect_or_remove_group
other_group =
2006 May 26
4
shouldn''t this work? - session[:array_of_objects].delete_if {|x| x.id == params[:id]}
I am saving an array of active record objects (college courses) in the
session as session[:course_list]. This is the cart for a registration
controller.
If a student chooses to delete the course from the list I get the :id
as params[:id].
However if I do
session[:course_list].delete_if {|x| x.id ==params[:id]}
does not work.
session[:course_list].delete_at(idx)
works. Ocourse to do this I have
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 Jan 28
3
DRY conflict with "Updated at" "Created at" "Deleted at" in view
Hi all,
Are there any helpers or so for listview routines that suppres the three above
mentioned columns? I''m currently exploring something like the code below. But
it feels like I''m doing Rails'' work.
# just for test purposes
<div id="debug">
<% for col in Product.columns.map %>
<%= col.name %> - <%= col.type %><br/>
<%
2007 Jan 06
3
speeding up pagination
I need help to optimize a query (sort of ...)
if params[:debit] == "on"
@schools = School.find(:all,
:conditions => ["name like ?", "%#{params[:search]}%"],
:order => ''name'')
@schools.delete_if { |s| s.debit <= 0 }
@school_pages = Paginator.new self, @schools.length, 20
The problem here is that
2006 Jan 07
3
user engine question
I''ve created an array of hashes in UserController#initialize to describe
a menu:
@menu_array = [
{:menu => ''home'', :controller => ''home'', :action => ''send_home''},
{:menu => ''user list'', :action => ''list''},
{:menu => ''login'', :controller =>
2006 Apr 09
6
Write/Display AR query as Grouped Results?
I''ve got a publications table that contains an author_id foreign key and
a pubrole_id foreign key. What I want to do is query the DB using AR so
that I can get a list of all publications that belong_to a particular
author, and group the results by the pubrole.role_name (Author, Joint
Author, Editor, etc.) so that the results look something like:
Author
book1 info
book2 info
etc.
2006 Jun 20
4
Searching ActiveRecord sets
Hey all,
I''m learning AR and I''m trying to find the best way to search an
ActiveRecord set in order to make a conditional statement decision,
something like .has_value?(value) but for a multi-dimensional array like
an AR set of like 100 rows.
I know I can do something like this:
results = Table.find_by_sql("...")
for result in results
if
2009 Feb 09
2
dynamic constant assignment
I have a constant set up like that :
ALL_LOCALES
=> {"it"=>"Italian", "fr"=>"Français", "de"=>"Deutsch", "en-
GB"=>"English (UK)", "es"=>"Español (España)", "pt-PT"=>"Português",
"pl"=>"Polski", "en-US"=>"English
2006 Apr 17
5
Finding out updated fields
Hi,
When we update a record via an update form, is there an easy way to find
out the fields that have been changed. If the update is successful, i
want to display:
The following fields have been changed:
field-name = new-value
...
Thanks,
Lantis.
--
Posted via http://www.ruby-forum.com/.
2008 Jun 18
4
How to use Chars in classes not derived from AR
Hi!
I have a class that derives from nothing and is located in /models. I''m
using " my string ".chars to manipulate strings that potentially contain
special chars and replace them with an US-ASCII equivalent.
It did work until yesterday. Now on a linux system "a".chars returns
#<Enumerable::Enumerator:0xb74e3d6c>
While it should return
2007 Dec 28
11
LIKE clause in rails
Hello,
I am trying to achieve a search functionality in the following manner
i have an table called people
which has
first_name,last_name,etc...
After the user form to search people is submitted i get the params hash
as params[:persons]={"first_name"=> "%John%","last_name"=>"%Stevens%"}
NOTE : I have changed the params hash to include the %.
Now
2011 Feb 28
1
(2.3.5) removing validations
Today I tried to remove (actually overwrite) a validation from a model,
from within a plugin.
This was the original validation:
validates_length_of :login, :maximum => 30
This was the only code I could come up with to replace it:
def self.included(base)
base.class_eval do
@validate_callbacks.delete_if { |callback|
begin
# Sorry, only way to remove
2008 Mar 26
2
Missing Method defined in controllers/application.rb
I have this in my controllers/application.rb:
class ApplicationController < ActionController::Base
...
def datebalk!
# set regexp for datebalks generated attributes
c = /.*__dteblk/
# Remove datebalks generated attributes from params hash
delete_if { |k, v| c =~ k.to_s }
end
...
end
When I call this from client_controllers.rb in this fashion:
# need this to strip
2005 Sep 18
1
trimmed mean in R seems to round the trimming fraction
subject: trimmed mean in R seems to round the trimming fraction
to r-help at stat.math.ethz.ch.
Consider the following example of 10 numbers. 10% trimmed mean is correct
but you can see that the result is the same for many trimming fractions
till 0.20!
For example 13% trimmed mean should use interpolation of second and
eighth ordered observation. R does not seem to do this.
The correct 13%
2006 Jul 16
1
Don''t log params
Hello!
I need to supress the logging of params for certain actions, i.e. I don''t
want the params hash to show up in one of my actions.
Does anyone know how to do that?
Thanks,
Rob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060716/62b2e2d5/attachment.html
2006 Jun 17
2
problem with select_date
In my form I have these items:
<%= select_year Date.today,
:start_year => Schoolyear.get_startdate.year,
:end_year => Schoolyear.get_enddate.year %>
<%= select_month Date.today.month %>
No matter what I do, in my controller I can''t seem to access the
selected year and
month.
I have tried params[:month].to_s and also