Displaying 20 results from an estimated 30000 matches similar to: "Validations"
2012 Nov 17
2
Help needed for error in foreign key validation
I have two models bank and country. User should only associate a Bank with
a country id present in the country table and I put validates presence of
country to enforce it but i get error mysql2::Error: Unknown column
''countries.bank_id'' in ''where clause'': SELECT `countries`.* FROM
`countries` WHERE `countries`.`bank_id` = 17 LIMIT 1 when updating the bank
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,
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
2013 Mar 26
0
nested forms: use validate :some_method works in update mode only
I have a strange behavior when validating a record in a nested form. The
association collection is empty when creating a new record and the
validation does not catch the error. But when updating the same record the
validation gets it right but continues to catch the error even after
modifying the needed attribute value to make it pass.
Here is the model:
#timesheet.rb
class Timesheet <
2013 May 13
1
RAILS GET IDS
I don''t know how to solve something about a project I''m doing in Ruby on
Rails.
I want to save the IDS of my 3 models to my table DETAILS between these,
my BD is Mysql.
ASIGNATURAS--MALLAS--NIVELS-------->ASIGNATURA_ID--_MALLAS_ID--_NIVELS_ID
In the view MALLA, i list my asignaturas, mallas and niveles, and in the
controller MALLA i want to save the arrays to my model
2012 Oct 11
4
what;s the right url in this case
Hello,
I have this models
class Berichten < ActiveRecord::Base
attr_accessible :bericht, :user
belongs_to :user
belongs_to :Category
end
class User < ActiveRecord::Base
attr_accessible :email, :name
has_many :berichten
end
class Category < ActiveRecord::Base
attr_accessible :id :name
has_many :berichten
end
What I wonder is what the right url is when I want to place a
2009 Nov 22
2
WARNING: Can't mass-assign these protected attributes: active
Hi,
I''m trying to understand this error:
WARNING: Can''t mass-assign these protected attributes: active
I had this error before when creating a record.I did not mark the attibutes
posted from the form as attr_accessible, so when the following line tries to
execute it throwed an Warning in the log, and the record was not saved.
@user = User.new(params[:user])
I find out that I
2013 May 07
3
validates :uniqueness apparently doesn't
ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin12.3.0]
Rails 3.2.13
I have a validates ... :uniqueness constraint on one of the attributes
of an ActiveRecord class.
In my test suite, I set the attribute from the same attribute in a
record in the fixture. I then send invalid? to the object under test.
invalid? returns _false_, and the .errors object for the record shows no
errors.
A
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
2014 Feb 05
0
Solr Search with one to many associations
I have a 2 entities which have many to many relation say teacher and
slot. Each teacher has many classes he/she takes up and each class is a
slot. I want to perform search on teacher by sunspot solr for all the
teacher who takes classes for different days in specific time.
Say model structures and relations as follows
class Teacher < ActiveRecord::Base
attr_accessible - name,
2011 Jan 02
0
"Confirmation" succeeds when the *_confirmation attribute was neglected from the Model.
<pre>
models/user.rb:
# Oops! I forgot to add the :password_confirmation attribute!
class User < ActiveRecord::Base
attr_accessor :password
attr_accessible :password #, :password_confirmation
validates(:password,
:confirmation => true,
:presence => true)
end
activemodel/lib/active_model/validations/confirmation.rb:
3 # == Active Model
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 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
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
2013 Apr 08
1
cattr_accessor and Thread.current prblems
Hello,
I am trying to convert three applications to multitenant, all of them have
same structure difference is only in little functions and template designs.
All of them using cattr_accessor for setting currencies and other data, and
it works perfectly
Now i added app_id as cattr_accessor to App model to use it in
default_scope to implement multi-tenancy
class App < ActiveRecord::Base
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"=>"✓",
2012 Jun 18
0
Creating an object with a nested has_many :through relationship
I have 3 models that define members, groups and the subscriptions: Member,
Group, and GroupMember.
class Member < ActiveRecord::Base
> has_many :group_subscriptions, class_name: "GroupMember"
> has_many :groups, through: :group_subscriptions
> attr_accessible :email, :password
> end
> class Group < ActiveRecord::Base
> has_many :member_subscriptions,
2013 Sep 30
0
TypeError: no implicit conversion of Symbol into Hash when submitting form to upload files
I''m currently new to Rails and Ruby and I''m trying to learn from my
mistakes, this time I''m trying to upload 2 files from a form for later
processing, however, after I hit the "Submit" button. I keep getting this
error:
TypeError in UploadFilesController#create
app/controllers/upload_files_controller.rb:28:in `new''
2012 Aug 25
0
accepts_nested_attributes_for and fields_for not working!
I want to be able to create one menu object that has fields_for :brunch,
:lunch, and :dinner. The menu object has_many brunches, lunches, and
dinners, but each time I "edit", only one brunch, one lunch, and one dinner
object are added. I''m using carrierwave to upload brunch_menus,
lunch_menus, and dinner_menus (attributes of brunches, lunches, and dinners
respectively) as
2013 Sep 26
0
Devise Invitable and Validations -- what's the right way to do this?
Rails 3.2.14, Ruby 1.9.3, devise_invitable 1.1.8
I am trying to get invitations containing custom fields to validate their contents properly. I have tried the invite_keys hash route, as documented here: https://github.com/scambra/devise_invitable#model-configuration and unless I am doing something wrong with my Regexps, what happens is the fields are validated, but the error messages are