Displaying 20 results from an estimated 4000 matches similar to: "Sorting by inner has_many through attribute"
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,
2013 Mar 30
1
How to use group in nested associations
The below query fails:
Timesheet.joins(:time_entries).select("timesheets.*,
sum(time_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,
2013 Mar 25
1
validates presence of foreign key fails in nested form
I''m using 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
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
2009 Nov 06
0
Nested objects not propagating from view
I thought I had this fixed, but apparently not. It works okay from the
console, but not from the view. I have the following:
# partial schema
create_table "users", :force => true do |t|
t.string "login", :null => false
t.string "first_name"
t.string "last_name"
t.string "email", :null => false
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
2009 Apr 12
0
rails 2.3 nested forms with has_many through checkboxes
I was wondering if anyone knew of a way to combine the new nested
forms in rails 2.3 with a has_many through relationship via
checkboxes. Basically I have a page model, a page_category model and
a category_items join table. Pages have many page categories through
category items. The category_items table is polymorphic so i can use
it for other models who need categories (maybe this is
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,
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
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
2013 Mar 14
0
[Rails 3.2] accepts_nested_attributes_for and time_select
Hi, I am upgrading a Rails application from Rails 3.1.11 to 3.2.12, but
have a problem with ` accepts_nested_attributes_for` in conjunction with
multipart attributes.
The app is used to manage oral exams, so there is a model `Exam`, which has
many `Examdate`s. When creating an exam, I can also create the examdates,
consisting of a date, a start time and an end time. While the date field is
2013 Feb 10
0
Nested attributes doesnt get updated
Hi
Am building a nested form and my code works fine with sqlite3 but throws
errors when using Oracle during update action.
Am getting the following error:
ActiveRecord::RecordNotFound in AWRequestsController#update
Couldn''t find WADetail with ID=5000000015 for AWRequest with ID=5000000022.0
Request
*Parameters*:
{"utf8"=>"✓",
2013 Jul 21
4
how to use activemodel collection.build for a has_many :through association
Hi all,
In my controller I am doing the following to populate a nested form for a
has_many through association:
def new
@specification = Specification.new
Component.find_each.each do |component|
@specification.component_specifications.build(:component_id =>
component.id)
end
The idea being whenever someone creates or edits a form, it will be
populated with all
2009 Oct 06
1
Problems Processing multiple form elements generated by javascript actions
Hi all,
After many days of struggling, I have a multi-model form with ajax
elements more or less working, but I''m hitting a wall with a few bugs
that I can''t figure out. Guidance would be very much appreciated.
I''m using the Ryan Bates technique from Advanced Rails recipes to
dynamically add and remove elements on a multi-model form.
2009 May 12
2
2.3 Nested Model Forms; build new without updating existing
I''m trying to build something similar to a Facebook messaging app, in
which the view displays all the messages for a particular thread, with
a form box for replying at the bottom of the thread.
The problem is that using fields_for generates form fields for each
existing record, and for one new record. In this case, there is no
need to edit existing messages - just a need to add new
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
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
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| %>
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
2013 Mar 04
0
fields_for with accepts_nested_attributes: how to pass a value to a label
I can''t figure out how to pass a value from the following object build in
the controller:
class TimesheetsController < AC
...
def new
@timesheet = current_user.timesheets.new
now = Date.today
#generating 7 time entries: monday through sunday
(now.beginning_of_week..now.end_of_week).step { |date|
@timesheet.time_entries.build(:workdate; date)
end
end
...
In the