search for: allow_destroy

Displaying 20 results from an estimated 31 matches for "allow_destroy".

2013 Mar 30
1
How to use group in nested associations
...ime_entries.worktime) as total").group("timesheets.start_date") The models have the following relations: Timesheet < AR has_many :activities, dependent: :destroy, inverse_of: :timesheet has_many :time_entries, through: :activities accepts_nested_attributes_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...
2013 Mar 25
1
validates presence of foreign key fails in nested form
...accepts_nested_attributes as follows: class Timesheet < ActiveRecord::Base attr_accessible :status, :user_id, :start_date, :end_date, :activities_attributes has_many :activities, dependent: :destroy has_many :time_entries, through: :activities accepts_nested_attributes_for :activities, allow_destroy: true end class Activity < ActiveRecord::Base attr_accessible :task_id, :timesheet_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, d...
2009 May 12
2
2.3 Nested Model Forms; build new without updating existing
...xisting record, and for one new record. In this case, there is no need to edit existing messages - just a need to add new messages. Does anybody know how to do this? Code is below. Models: class MessageThread < ActiveRecord::Base has_many :messages accepts_nested_attributes_for :messages, :allow_destroy => true end class Message < ActiveRecord::Base belongs_to :message_threads end View (show.html.erb) <% @message_thread.messages.each do |message| %> <%= message.message %> <% end %> <% form_for @message_thread do |thread_form| -%> <% thread_form.fields...
2013 Oct 10
12
What's the best way to approach reading and parse large XLSX files?
....:extension" has_attached_file :material_list, :url=>"/:current_user/material_list", :path=>":rails_root/tmp/users/uploaded_files/material_list/material_list.:extension" validates_attachment_presence :material_list accepts_nested_attributes_for :material_list, :allow_destroy => true accepts_nested_attributes_for :inventory, :allow_destroy => true validates_attachment_content_type :inventory, :content_type => ["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"], :message => "Only .XSLX files are accepted as Inventory...
2009 Feb 03
1
update_attributes! does not update nested model
Hi! I have updated my app to rails 2.3. I have form that has few nested models and I am happy that I can just write accepts_nested_attributes_for :tasks, :allow_destroy => true, but update_attributes! does not update my nested model. I have tried update_attributes, and it works. Any ideas? Few lines from log: update_attributes: SQL (0.1ms) BEGIN Education Update (0.3ms) UPDATE `educations` SET `institution` = ''ins'', `updated_at` = ...
2009 Jul 01
2
Nested Forms - how to displayed the attributes content ?
I have a User model class User < ActiveRecord::Base has_one :account accepts_nested_attributes_for :account, :allow_destroy => true validates_associated :account attr_accessible :account_attributes is working fine, validating and updating both records (User and Account), but I caanot display the value in the form when is updated, ex: below the firstname is not displayed but it''s in the db account rec...
2010 Dec 07
1
fields_for and one out of many from association
class Person < ActiveRecord::Base has_many :addresses has_one :primary_address, :class_name => ''Address'', :order => ''preferred desc, id'' accepts_nested_attributes_for :addresses, :allow_destroy => true accepts_nested_attributes_for :primary_address, :allow_destroy => true end class Address < ActiveRecord::Base belongs_to :person end In the view: <% f.fields_for :primary_address do |address_builder| %> <%= render ''addresses'', :f => address_bui...
2011 Feb 11
1
accept_nested_attributes, reject_if doesn't work.
class 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", u...
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>...
2009 Nov 06
0
Nested objects not propagating from view
...t;plus4" t.datetime "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 < Acti...
2013 Jul 21
4
how to use activemodel collection.build for a has_many :through association
...r_accessible :description, :name, :component_specifications_attributes validates :name, :presence => true, :uniqueness => true has_many :component_specifications has_many :components, :through => :component_specifications accepts_nested_attributes_for :component_specifications, :allow_destroy => true end class ComponentSpecification < ActiveRecord::Base attr_accessible :note, :colour, :brand, :components has_many :components belongs_to :specification end class Component < ActiveRecord::Base attr_accessible :description, :name belongs_to :component_specification...
2011 Jul 11
2
Pre-populating association
...n create a survey, with any number of questions, and other users can then vote by creating a ballot for that survey. Here''s the modeling: class Survey < ActiveRecord::Base has_many :questions has_many :eligibilities has_many :ballots accepts_nested_attributes_for :questions, :allow_destroy => true attr_accessible :title, :description, :status, :deadline, :questions_attributes def owner Person.find(owner_id) end end class Question < ActiveRecord::Base belongs_to :survey has_many :preferences end class Ballot < ActiveRecord::Base belongs_to :survey ha...
2011 Nov 24
5
ActiveRecord::AssociationTypeMismatch
...:playlist_items has_many :playlists, :through => :playlist_items end class Playlist < ActiveRecord::Base validates :name, :presence => true, :uniqueness => true has_many :playlist_items has_many :images, :through => :playlist_items accepts_nested_attributes_for :images, :allow_destroy => true end class PlaylistItem < ActiveRecord::Base belongs_to :image belongs_to :playlist end The project can be found here: https://github.com/gpad/rms can anybody help? thanks Gianluca -- You received this message because you are subscribed to the Google Groups "Ruby on Rail...
2009 Nov 24
0
Problem with association when getting a validation error on update
Quick overview: 2 classes- class Building < ActiveRecord::Base has_many :styles, :dependent => :destroy validates_presence_of :address1 accepts_nested_attributes_for :styles, :allow_destroy => true end class Style < ActiveRecord::Base belongs_to :building end The sequence of my problem is as follows: - Edit building view and retrieve is different styles (so I can manipulate them through accepts_nested_attributes_for) - I delete one of the mandatory fields in building (on t...
2010 Oct 06
0
Error customization problem.
Hi, I have following models class User < ActiveRecord::Base has_many :addresses, :as =>:addressee, :dependent => :destroy accepts_nested_attributes_for :addresses, :allow_destroy => true end class Address < ActiveRecord::Base belongs_to :addressee, :polymorphic => true validates_presence_of :address1, :maximum => 50,:message => "Address1 cannot be blank." validates_presence_of :city,:message => "City cannot be blank." valid...
2011 Feb 08
0
Sorting by inner has_many through attribute
...nt_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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails:...
2011 Jul 16
0
nested_form gem don't work for accepts_nested_attributes_for :limit
Hello, I have the next: class Post < ActiveRecord::Base has_many :image, :dependent => :destroy accepts_nested_attributes_for :image, :allow_destroy => true, :limit => 4 end class Image < ActiveRecord::Base belongs_to :Post ... paperclip settings ... end And the form view for the post is: <%= nested_form_for @post, :html => { :multipart => true } do |f| %> <%= f.fields_for :images do |i| %> <% if i.obj...
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...
2012 Apr 05
0
Polymorphism, acts_as_relation gem and nested attributes
...//github.com/hzamani/acts_as_relation) Model code: class Email < ActiveRecord::Base belongs_to :detail validates_presence_of :address end class Detail < ActiveRecord::Base acts_as_superclass has_many :emails accepts_nested_attributes_for :emails, allow_destroy: true end class User < ActiveRecord::Base acts_as :detail validates_presence_of :username, :password end Migration code: class CreateInfo < ActiveRecord::Migration def change create_table :details, :as_relation_superclass => true do |t|...
2013 Feb 27
0
Exended modules and reject_if in nested_attributes
...e_record_additions'' ###################################### class Activity < ActiveRecord::Base include ActiveModel::Validations extend ActiveRecordAdditions The accept nested call accepts_nested_attributes_for :targeting_group, :reject_if => :exists_nested_targeting_group?, :allow_destroy => true The start of the exists_nested_targeting_group? module def exists_nested_targeting_group?(attributes={}) exists=false -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop rec...