Displaying 20 results from an estimated 900 matches similar to: "how to use activemodel collection.build for a has_many :through association"
2012 Jun 21
1
ActiveModel::Serializers::JSON support arbitrary keys
Is there a reason why AM:S doesn''t support arbitrary keys to serialization?
I can see a lot of uses cases where arbitrary keys could come handy. Right
now, if one tries to do it, AM:S checks if the keys match a method of the
model and raises exception if it can''t find any.
class Client < ActiveRecordBase
attr_accessible :name, :address, as: :creator
include
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
2012 Jul 09
10
attr_accessible on some properties + attr_protected on others makes class 'open-by-default'
(I posted this as a bug in GitHub
(https://github.com/rails/rails/issues/7018), but then someone there told
me I should post it here, so here it is.)
If you set attr_accessible on some properties in an ActiveRecord-descended
class, and then attr_protected on others - the class becomes ''default-open''
- if any properties are missed or added later, they will be accessible by
2011 Feb 03
5
Ignore attr_accessible in seed file
Is there a way to tell Rails to ignore attr_accessible when seeding the
database and to allow mass assignment with create or new?
I know how to skip validations but do not find anything on mass
assignment...
--
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
2006 Jul 17
2
actionmailer / @recipeints
Hi all,
i''m trying to email multiple people based on certain criteria.
i do a search like
@stacks = Group.find(:all, :conditions => ["component_id = ?", 2])
this populates stack to contain multiple groups with component_id =2.
How do i populate @recipients to contain all possible @stack.email.
Let me clearify. Each stack has its own email, and i need to include
each
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
2013 Oct 10
12
What's the best way to approach reading and parse large XLSX files?
Hello, I''m developing an app that basically, receives a 10MB or less XLSX
files with +30000 rows or so, and another XLSX file with about 200rows, I
have to read one row of the smallest file, look it up on the largest file
and write data from both files to a new one.
I just did a test reading a few rows from the largest file using ROO
(Spreadsheet doesn''t support XSLX and
2011 Jul 11
2
Pre-populating association
Hello,
I think this is an easy one for the average Rails developer but I''m a bit stuck.
I''m creating a simple voting app: any user can 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
2008 Aug 27
11
find_by_sql and xml_serializer problems
Hi,
I''m doing a find_by_sql and am getting an odd error when trying to
render the result to xml.
The find is:
children_list = find_by_sql("SELECT components.componentid,
components.logicalname, versions.level, versions.branch,
versions.sequence FROM components, versions where
components.componentid = ''" + component_id + "''" + " AND
2012 Aug 05
0
ActiveRecord::Validator vs ActiveModel::Validator
I know that there is an ActiveModel Validator class
https://github.com/rails/rails/blob/master/activemodel/lib/active_model/validator.rb
which is used for the class level validation macros.
But I didn''t find a an ActiveRecord Validator class.
From my understanding in Rails 3, validations have been moved into
ActiveModel to leave ActiveRecord as an ORM.
So now I see this Rails 3 code
2012 Sep 03
0
undefined method `singular_route_key' for "User":ActiveModel::Name
In ActionDispatch::PolymorphicRoutes, there is a call to
build_named_route_call an on line 172 (of latest rails code from
github), there is a call to singular_route_key:
model_name_from_record_or_class(parent).singular_route_key
Now model_name_from_record_or_class returns an ActiveModel::Name
object, which is a wrapper to the string class, that returns a string
name of the class of an
2010 Aug 13
2
Rails 3 / ActiveModel for Credit Card information?
When submitting billing information in the past I''ve always used
attr_accessor for credit card details as they should not be saved in
the database. In addition I always end up storing the card
expiration date so that the date form helper works correctly.
With Active Model it seems logical to create a CreditCard class to
hold this data instead.
**1st issue.**
It seems there still
2011 May 19
0
NoMethodError (undefined method `serializable_record' for #<ActiveModel
Hi ,
Am using rails 3 .I have added code in my controller
-----------------------------------------------------------------------
la.map{|c| ActiveRecord::Base::Serializer.new(c).serializable_record
-----------------------------------------------------------------------
But am getting below error
------------------------------------------------------------
NoMethodError (undefined method
2010 Apr 09
0
[PATCH] add :root option to ActiveModel JSON serialization
This is a small, straightforward patch that I''d love to see merged:
https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/4358-patch-add-root-option-to-activemodel-json-serialization
It''s all pretty self-explanatory, it basically just ports a useful
option from to_xml to to_json, making their interfaces more compatible
with each other. Feedback would be greatly
2012 Jul 08
0
ActiveModel::ValueObject
Hi guys
Seeing `composed_of` removed I put together a quick proof-of-concept
ValueObject implementation on top of ActiveModel and ActiveRecord
`serialize`.
https://gist.github.com/3070184
Features:
- VO''s are immutable
- VO''s are identified by their attributes
- VO''s can be conveniently created from hashes (with a little extra work)
What do you think?
--
You
2011 Aug 20
2
[Linux] Error installing rails "activemodel requires activesupport"?
Well, I''m trying to install Rails through gems in a Linux box `sudo gem
i rails --pre` I''m getting this:
ERROR: Error installing rails:
activemodel requires activesupport (= 3.1.0.rc6, runtime)
Which is funny, because when I check `gem list` I get
activesupport (3.1.0.rc6)
bcrypt-ruby (2.1.4)
builder (3.0.0)
i18n (0.6.0)
multi_json (1.0.3)
I don''t know what to
2011 Feb 05
3
ActiveModel::AttributeMethods limiting
In my attempt to add AM:Dirty to my model I realized that
AM#AttributeMethods is a bit imperfect. It''s impossible to generate
attribute methods step-by-step in DataMapper-like manner.
class Model
include ActiveModel::Dirty
def self.property(name, klass = String)
define_property_accessors(name, klass)
# This method will be called once, because of
2011 Apr 09
4
API documentation for find_in_batches
Hello,
At guides.rubyonrails.org I read about the possibilities of
find_in_batches. However I cannot find this option anywhere in the API
documentation (api.rubyonrails.org).
My question: where should I look for the documentation of this
command?
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email
2010 Nov 06
0
ActiveModel: undefined method `attributes`
Trying to setup a tableless model, and serialize it to XML, but am
getting:
NameError: undefined local variable or method `attributes''
anyone know what I need to get the attributes method defined?
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
2010 Sep 17
0
Key Value Json ActiveModel::Errors
Hi all,
I''m using Rails 3.0, and I have a model which validates if the
attribute :name is present. On my my views, I use Jquery to submit the
form which creates the model. If the name is not present, Rails
returns something like this Json:
[''Name is a required value'']
Is there a way to make it return something like this?
[''name'': ''Name is a