search for: delete_if

Displaying 20 results from an estimated 42 matches for "delete_if".

2006 Aug 08
12
delete_if doesn''t work for has_and_belongs_to_many
...> "Something Else" ).save i.save Fine, now I have two records in the items_things table. Now if I say t = Thing.find_by_value ''Something'' i.things.delete t i.save Then I have only one record in the items_things table. Which is correct. But, if I had said i.things.delete_if {|x| x.value = ''Something''} i.save then the relevant record is not deleted from the items_things table. Is this a bug? If so, where''s the best place to report it? bye John
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 upd...
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
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 to index the list in the view and insert the value into each link_to. When I try this in irb the second statement works but the first does not and does not give any error messages. What...
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??...
2006 Nov 04
0
@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??...
2013 Sep 17
4
Rails 4 deprecation of in-place edit methods for collection associations
...nt 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!{}, has_many.select!{}, has_many.delete_if{}, has_many.pop etc. will not work as of Rails 4.2. I tried to get some answers about the motivation of this decision here https://github.com/rails/rails/pull/12236 but i failed. So to the question can someone please explain WHY is this happening? Where is the "confusion" in the example...
2006 Jan 07
3
user engine question
...her in my application_helper.rb as: def construct_horizontal_menu(menu_array) menu_strings = [] menu_array.each do |menu_item| menu_text, throw_away = menu_item.delete(:menu) menu_strings << link_if_authorized(menu_text, menu_item) end menu_strings.delete_if{|x| x.strip == ''''} menu_strings.delete_if {|item| item =~ (user? ? /login/ : /logout/)} menu_strings.join('' | '') end I don''t have a before_filter in application.rb so nothing is protected by default. In my UserController, I added: bef...
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 instance.debit is a virtual attribute ... Any clue ? ngw --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google...
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/> <%
2011 Feb 28
1
(2.3.5) removing validations
...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 validation... # Probably tightly coupled to AR 2.3.5 (callback.method.respond_to?(:binding)) && (eval("attrs", callback.method.binding).first == :login) && (callbac...
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 out observer attributes for datebalks plugin @client = @entity.build_client(params[:client].datebalk!) I get this exception: undefined method `datebalk!'' for...
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 Dec 17
3
Trimming a collection of AR objects?
I have a collection of acts_as_ferret search results that I need to trim based on an attribute. I''ve been trying to iterate through the collection but haven''t been able to make this work. Here is what I have tried unsuccessfully: @people.each {|person| person.clear if person.privacy_type == "private"} Unfortunately Class Person does not respond to clear since it is
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/.
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
2006 Jan 23
5
Bibtex database design
...on class. I tried overriding the content_columns but in console I get a stack too deep error or segfaults sometimes. I tried this class Article < Publication validates_presence_of :title, :journal, :year def self.content_columns return Article.content_columns.delete_if {|c| ["publisher"].include?(c.name) } end end Any ideas on how to do this without having to create a different view for each publication type? regards, Horacio
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
2006 Mar 23
2
Way to iterate over each associtaion
Is there a way with ActiveRecord to get ahold of a collection containing each association? I want to write a rake task that will dump a model and all its related models to yaml. Thanks, Dave -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060323/abdf4305/attachment.html