search for: reject_if

Displaying 20 results from an estimated 20 matches for "reject_if".

2009 Jun 24
1
accepts_nested_attributes_for :reject_if issue
I have the following models: class Order < ActiveRecord::Base belongs_to :billing_address belongs_to :shipping_address accepts_nested_attributes_for :billing_address accepts_nested_attributes_for :shipping_address, :reject_if => proc { |attributes| attributes[''has_shipping_address''] != ''1'' } def after_initialize self.build_billing_address unless billing_address self.build_shipping_address unless shipping_address end end class ShippingAddress < OrderAddress attr_...
2011 Feb 11
1
accept_nested_attributes, reject_if doesn't work.
...ss Post < ActiveRecord::Base validates :name, :presence => true validates :title, :presence => true, :length => { :minimum => 5 } has_many :comments, :dependent => :destroy has_many :tags accepts_nested_attributes_for :tags, :allow_destroy => :true, :reject_if => proc { |attrs| attrs.all? { |k, v| v.blank? or v.nil? } } end rails c irb(main):001:0> post=Post.first => #<Post id: 1, name: "prova", title: "titolo prova", content: "prova 1", created_at: "2011-02-01 10:03:10", updated_at: "2011-02-01...
2013 Feb 27
0
Exended modules and reject_if in nested_attributes
I have some common class methods in a module ''active_record_additions'' that I load into a class by Activity by using extend ActiveRecordAdditions The Activity class uses nested_attributes_for with a reject_if method saved in the module ''active_record_additions'' The problem is that the class methods in ''active_record_additions'' works when I use them as ordinary class methods, but not as a a method in reject_if. I got the message NameError (undefined method `exists...
2010 Nov 11
2
Rails 3 - Nested Forms, using Builder -- Check_box issue
...but I can''t see to access that in the nested form (inside builder). Also, the checkbox doesn''t have the recipient_id as the value being set? I want to use the checkbox to tell Rails whether or not to create the record or not on submit using something like this in the model ":reject_if => lambda { |a| a[:recipient_id].blank? }" Anyone with fields_for experience? Any tips or suggestions from the pros? Thanks -- 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 rubyonra...
2010 Dec 09
2
Skip validation on nested attribute
Hi, I have a two models, advert and address. An advert has one address. On my advert form I have a nested form of the address. But I only want to create the nested address depending on the adver kind. how can I skip the nested attribute validation? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails:
2013 Mar 30
1
How to use group in nested associations
...ttributes_for :activities, allow_destroy: true end class Activity < AR belongs_to :timesheet, inverse_of: :activities belongs_to :task has_many :time_entries, order: :workdate, dependent: :destroy, inverse_of: :activity accepts_nested_attributes_for :time_entries, allow_destroy: true, reject_if: proc { |a| a[:worktime].blank? } end class TimeEntry < AR belongs_to :activity, :inverse_of => :time_entries end How is it possible to group all the time sheets by their start_date and sum the work time ? Thank you. -- You received this message because you are subscribed to the Googl...
2013 Mar 25
1
validates presence of foreign key fails in nested form
..._id, :time_entries_attributes validates :task_id, presence: true, uniqueness: { scope: ''timesheet_id''} belongs_to :timesheet belongs_to :task has_many :time_entries, order: :workdate, dependent: :destroy accepts_nested_attributes_for :time_entries, allow_destroy: true, reject_if: proc { |a| a[:worktime].blank? } end As you see, I didn''t define any validation for timesheet_id presence in Activity model. It works fine in the browser, but it is still possible to create an activity without timesheet_id assigned. If I add: validates :timesheet_id, presence: true...
2010 Feb 06
1
accepts_nested_attributes_for with has_many => :through
I have two models, links and tags, associated through a 3rd model, link_tags. I added the following to my link model, has_many :tags, :through => :link_tags has_many :link_tags accepts_nested_attributes_for :tags, :allow_destroy => :false, :reject_if => proc { |attrs| attrs.all? { |k, v| v.blank? } } and put this in a partial called by the new and edit forms for links, <%= f.error_messages %> <p> <%= f.label :uri %><br /> <%= f.text_field :uri %> </p> <p> <%= f.label :title...
2009 Nov 06
0
Nested objects not propagating from view
..."created_at" t.datetime "updated_at" end # relevant models class User < ActiveRecord::Base belongs_to :contact has_many :properties has_many :notes, :through => :properties accepts_nested_attributes_for :contact, { :allow_destroy => true, :reject_if => :all_blank } end class Contact < ActiveRecord::Base has_one :user belongs_to :address belongs_to :biztype accepts_nested_attributes_for :address, { :allow_destroy => true, :reject_if => :all_blank } end class Address < ActiveRecord::Base has_o...
2009 Mar 13
1
Problem saving nested attributes for has_many associations (Rails 2.3 RC2 and Edge)
I''ve tested this on both 2.3 RC2 and Edge. This pastie contains model, helper and view: http://pastie.org/415742 When I save a vocabulary - its terms don''t save. I''m fairly sure it worked in RC1. Would appreciate any insight. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on
2009 Oct 05
1
Re: creating 2 things at the same time?
...text_field :name %> <% end %> </p> <p> <%= f.submit ''Create'' %> </p> <% end %> in model Comment write (modify this according to your needs) has_one :picture,:dependent => :destroy accepts_nested_attributes_for :picture,:reject_if => proc { |attributes| attributes[''name''].blank? } in create action of comments controller @comment = Comment.new(params[:comment]) @comment.save Thats all..Modify the rest of your code like this..This is just an example Sijo -- Posted via http://www.ruby-foru...
2011 Feb 08
0
Sorting by inner has_many through attribute
...ello everyone, For this model: class User < ActiveRecord::Base has_many :component_users, :dependent => :destroy has_many :components, :through => :component_users, :conditions => [''components.active = ?'',true] accepts_nested_attributes_for :component_users, :reject_if => lambda { |a| a[:components].blank? || a[:components] [:name].blank? }, :allow_destroy => true end How can I sort a user.component_users by a order attribute on the Component model? Like user.component_users.sort{|a,b| a.component.order <=> b.component.order} Thanks Thiago -- Yo...
2011 Sep 27
0
accepts_nested_attributes_for is not working for uniqueness
class User < ActiveRecord::Base accepts_nested_attributes_for :emails, :allow_destroy => true, :reject_if => proc { |attributes| attributes[''address''].blank? } end class Email < ActiveRecord::Base belongs_to :user validates_presence_of :address validates_email_format_of :address validates_uniqueness_of :address, :scope=>''user_id'' end when i am sav...
2013 Mar 04
0
fields_for with accepts_nested_attributes: how to pass a value to a label
....end_of_week).step { |date| @timesheet.time_entries.build(:workdate; date) end end ... In the Timesheet model I defined accepts_nested_attributes for time_entries association: class Timesheet < AR has_many :time_entries, :dependent: :destroy accepts_nested_attributes_for :time_entries, reject_if: proc { |attr| attr[''worktime].blank? } end in the Timesheet ''new'' page: <%= form_for @timesheet do |f|%> <%= f.label :status%> <%= f.text_field :status %> <%= fields_for :time_entries do | entry_form| %> # how to display at this place the...
2013 Mar 04
2
accepts_nested_attributes: undefined method 'association'_attributes
I have 2 models Timesheet and TimeEntry: class Timesheet < ActiveRecord::Base attr_accessible :status, :user_id, :time_entries_attributes has_many :time_entries, dependent: :destroy accepts_nested_attributes_for :time_entries, :reject_if => proc { |attributes| attributes[''worktime''].blank? } end class TimeEntry < ActiveRecord::Base attr_accessible :task_id, :timesheet_id, :workdate, :worktime belongs_to :timesheet end As explained in Rails API: ``` Using with attr_accessible The use of attr_acce...
2009 Apr 12
0
rails 2.3 nested forms with has_many through checkboxes
...has_many :category_items, :as => :item, :dependent => :destroy has_many :page_categories, :through => :category_items, :source => :category, :source_type => "PageCategory", :uniq => true accepts_nested_attributes_for :page_categories, :allow_destroy => true, :reject_if => proc { |attrs| attrs.all? { |k, v| v.blank? } } end class PageCategory < ActiveRecord::Base has_many :pages, :through => :category_items, :source => :item, :source_type => ''Page'', :uniq => true end class CategoryItem < ActiveRecord::Base belongs_to :cat...
2009 Oct 06
1
Problems Processing multiple form elements generated by javascript actions
...schedule_form.check_box :saturday %> <%= schedule_form.check_box :sunday %> <% end -%> </div> User Model: validates_associated :schedules, :on => :update after_update :save_schedules accepts_nested_attributes_for :schedules, :allow_destroy => :true, :reject_if => :all_blank def new_schedule_attributes=(schedule_attributes) schedule_attributes.each do |attributes| schedules.build(attributes) end end def existing_schedule_attributes=(schedule_attributes) schedules.reject(&:new_record?).each do |schedule| attributes =...
2013 Feb 10
0
Nested attributes doesnt get updated
...quence_name "w_request_details_seq" set_table_name "w_request_details" attr_accessible :requester_contact, :needed_by, :w_a_details_attributes has_many :w_a_details, :dependent => :destroy accepts_nested_attributes_for :w_a_details, :allow_destroy => :true, :reject_if => proc{ |attrs| attrs.all? {|k,v| v.blank? } } def to_param request_id.to_i.to_s end end *w_a_detail.rb*: class WADetail < ActiveRecord::Base set_primary_key :w_a_detail_id set_sequence_name "w_a_details_seq" set_table_name "w_a_details" attr_accessi...
2011 Mar 01
6
render :collection calling partial with phantom object?
I have two models with a straightforward has_many / belongs_to relationship: class Premise < ActiveRecord::Base has_many :metered_services, :dependent => :destroy ... end class MeteredService < ActiveRecord::Base belongs_to :premise ... end and nested routes to match: Demo::Application.routes.draw do devise_for :users resources :premises do resources :metered_services
2011 Oct 26
6
Add an index to a form
Hello, I''m having some trouble with forms, my app allows to enter data by using a multi-step form that has 7 steps. There are 3 steps that may let the user to add 1 form, for example there''s a step called "children" and that children has the following fields: * name * age * gender but one father may have more than 1 child and I''m adding another form with