Displaying 20 results from an estimated 178 matches for "new_record".
2006 Jan 23
5
validates_uniqueness_of :username, :if => !self.new_record?
...d a password. Then a link with an activation token
will be sent to them, and after clicking the link the user sees a page
where he should fill in further details, means: a username.
My model looks like this:
class Member < ActiveRecord::Base
validates_presence_of :username, :if => !self.new_record?
end
Sadly this does not work: it tells me "undefined method `new_record?''
for Member:Class".
Where''s the problem? Shouldn''t any ActiveRecord class have a method
called ''new_record?''?
Thanks for help.
Josh
--
Posted via http://www.ruby-f...
2011 Jun 15
1
.new_record? and :_destroy
...admin_email_address"
In my ticket model, the method to do the validate looks like the
following and works as expected except for one thing. If the :_destroy
flag on the comment was set in my comment view partial (I want to
delete a comment), it seems like this iterating over the comments with
new_record? somehow resets that :_destroy flag.
Am I doing something wrong here? Or, could someone give me a hint on a
more simple way to do this validation.?
Thanks !!
new_admin_comments = false
self.comments.each do |comment|
new_admin_comments = true if comment.new_record? &&
comment.admin_co...
2006 May 19
5
How to determine if an object has just been created
Is there a built-in way to determine if a model object has just been
created (ie. this object was the one that was originally persisted)? I
can''t see it anywhere in the AR code, but thought I''d check. I want
something like:
p = Person.create
p.original_instance? # true
Is this built-in or should I just patch AR?
-Jonathan.
2008 Jan 31
4
reby-debug and rspec
How do I use the ruby debugger with a specific test (not the whole spec file)? I want to do something like this.
$ rdebug spec/models/user_spec.rb -s "should error if not new_record"
____________________________________________________________________________________
Looking for last minute shopping deals?
Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping
2006 Jul 16
0
Why does belongs_to handle "conflicts" this way?
...to be different.
I made two simple models:
class Foo < ActiveRecord::Base; end
class Bar < ActiveRecord::Base
belongs_to :foo
end
Now here''s a script/console session.
>> f = Foo.create
=> #<Foo:0x270ec10 @attributes={"name"=>nil, "id"=>1},
@new_record=false, @errors=#<ActiveRecord::Errors:0x269fd10
@base=#<Foo:0x270ec10 ...>, @errors={}>>
>> b = Bar.new
=> #<Bar:0x26989d4 @attributes={"foo_id"=>nil}, @new_record=true>
>> b.foo_id = 10
=> 10
>> b.foo = f
=> #<Foo:0x270ec10 @attribute...
2006 Mar 19
2
Multiple polymorphic belongs_to declarations
I have the following models:
class Card < ActiveRecord::Base
belongs_to :deck
belongs_to :front, :polymorphic => true
belongs_to :back, :polymorphic => true
end
class TextContent < ActiveRecord::Base
has_one :card, :as => :front
has_one :card, :as => :back
end
The conflicting has_one declarations don''t work. What I need is
2007 Oct 22
1
self-referential habtm: why are my keys null?
...is isn''t working? I''m using Rails 1.2.5 on MySQL, and
aside from the above code and the database.yml I haven''t touched
anything that "rails app" created.
> ruby script/console
Loading development environment.
>> p = Node.new
=> #<Node:0xb7192348 @new_record=true, @attributes={"name"=>nil}>
>> p.name = ''parent''
=> "parent"
>> c = Node.new
=> #<Node:0xb714a8f4 @new_record=true, @attributes={"name"=>nil}>
>> c.name = ''child''
=> "child">...
2006 Oct 13
3
Validation errors in has_one/belongs_to relationships.
...e validation works on the insured object alone if I create
one and attempt to save it with invalid data.
Why does qi.save! return true below? It''s like it didn''t try to save
the insured object.
In script/console I see:
>> ins = Insured.new
=> #<Insured:0x37345e0 @new_record=true, @attributes={"city"=>"",
"address1"=>""
, "name"=>"", "updated_at"=>nil, "address2"=>nil, "zip_code"=>"",
"dba_name"=>ni
l, "quote_input_id"=>nil,...
2006 Aug 15
3
update or alter cart
I want to modify and update the items in the Depot - "display_cart".
Since the cart is in a session, its a little hard to get at the data.
I just want to create a way to change quantities, prices and
recalculate.
Has someone done this, and could you point me to the right direction.
Thanks
Chas
--
Posted via http://www.ruby-forum.com/.
2006 Feb 09
3
accessing associated models in a validate method
...n associated model in a validate method? I have
some code that looks like the following:
Models:
class Product < ActiveRecord::Base
has_many: upcs
end
class Upc < ActiveRecord::Base
belongs_to :product
def validate
errors.add_on_blank(''upc'') unless product.new_record?
end
end
Controller:
def create
@product = Product.new(params[:product])
@upc = Upc.new(params[:upc])
@product.upcs << @upc unless @upc.upc.empty?
if @product.save
# ...
end
end
When the create method gets called I get the NoMethodError "The error
occured whil...
2007 May 28
2
Rails, respond_to? over anonymous module (extend has_many).
...s, :order => :position, :dependent => :destroy
has_many :assets, :through => :playlist_items, :order => :position do
def << (*assets)
assets.flatten.each do |asset|
item = proxy_owner.playlist_items.build(:asset => asset)
item.save unless proxy_owner.new_record?
proxy_owner.duration += asset.duration
end
proxy_owner.save unless proxy_owner.new_record?
end
def delete_at (position)
pli = proxy_owner.playlist_items.find_by_position(position) rescue nil
unless pli.nil?
duration = pli.asset.duration
prox...
2006 Mar 24
6
Should counter_cache fields be saved in the database?
...hild in the console and verify
the number of children. When I quit and restart the console, however,
the children_size column is 0.
[flashbang:...WebContent/rails/development/test] ryann% ./script/console
Loading development environment.
>> parent = Parent.create
=> #<Parent:0x2385f24 @new_record_before_save=false,
@new_record=false, @errors=#<ActiveRecord::Errors:0x2351dc8
@errors={}, @base=#<Parent:0x2385f24 ...>>, @attributes={"name"=>nil,
"id"=>1, "children_count"=>0}>
>> parent.children.create
=> #<Child:0x234d070 @new_r...
2006 Feb 16
1
validations with associated object
Does anyone know if Rails is supposed to validate associated objects on
creation?
Say you have a User model, with has_many posts, and a Post model which
belongs_to user. Further, the Post model has a validates_uniqueness_of
:title.
u = User.find(1)
# this should pass
u.posts.create :title => ''my new post title''
# this should fail
u.posts.create :title => ''my
2010 Feb 20
23
Rails 3 possible bug in Routing
Hi, I just ran into this ActionController::RoutingError and just
wanted to check if someone can confirm this as a bug in the Rails 3
beta gem.
config/routes.rb contains:
get ''login'' => ''session#new''
post ''login'' => ''session#create'', :as => :login
GET /login works fine:
Started GET
2007 Feb 08
5
a possible bug in Has_many :through using :soucre
I''ve been stumped on this for a few days and I''m not sure if it''s an error
on my end or an actual bug.
I have a system where I have workshops and users. Workshops have students,
presenters, and troubleshooters. I wanted to represent this simply by
using has_many :through with :source.
Workshop
has_many :presenters, :through =>:presenterships, :source=>:user
2006 Feb 12
6
habtm doesn''t save old IDs
...usly existing
Groups, *if* I call it on a User object that has already been added to
the database.
Here''s an entry from the logs:
before save, groups=[#<Group:0x40710a9c @attributes={"name"=>"one",
"id"=>"1"}>, #<Group:0x4066e654 @new_record=true,
@attributes={"name"=>"eight"}>]
This Group gets added:
#<Group:0x4066e654 @new_record=true, @attributes={"name"=>"eight"}>
This Group does not:
#<Group:0x40710a9c @attributes={"name"=>"one", "id"=>...
2007 Nov 14
1
has_many_polymorphs and acts_as_list ?
...osition: "1"
created_at: 2007-11-14 13:19:06
elements:
- &id003 !ruby/object:Page
attributes:
name: P1
updated_at: &id002 2007-11-14 13:18:39.397292 +01:00
id: 1
created_at: *id002
errors: !ruby/object:ActiveRecord::Errors
base: *id003
errors: {}
new_record: false
new_record_before_save: true
- &id005 !ruby/object:Page
attributes:
name: P2
updated_at: &id004 2007-11-14 13:19:06.052972 +01:00
id: 2
created_at: *id004
errors: !ruby/object:ActiveRecord::Errors
base: *id005
errors: {}
new_record: false
new_record...
2006 Mar 16
10
Nubee Callbacks problem
I never want to alter a model(row). When a model has been changed i
want a new copy to be created.
What is the best way to implement this?
I think using callbacks might be the answer.
So model.save will create a new row, and leave the old one unchanged.
Any ideas? I can easily implement this in the controller but i''d rather
it be done transparently. Also errors should be passed back
2009 Aug 23
0
Best way of moving some jQuery from a view helper
...which is proving awkward to achieve in the helper.
[code]
def link_to_create_address(form_builder)
link_to_function ''New address'', {:id => ''new_address_link''} do
|page|
form_builder.fields_for :addresses, Address.new, :child_index =>
''NEW_RECORD'' do |faddress|
html = render(:partial => ''address_container'',
:locals => { :faddress => faddress,
:uid => ''NEW_RECORD'',
:show_edit_form =&...
2009 Jul 01
1
form_for resources with :singular specified
...an error saying "Only get and post requests are allowed.
(ActionController::MethodNotAllowed)"
I tried:
- form_for @equipment, equipment_instance_path(@equipment) do |f|
That gives the same error.
There has to be something better than:
- form_for @equipment, :url => (@equipment.new_record? ?
equipment_path : equipment_instance_path(@equipment)), :html =>
(@equipment.new_record? ? { :method => :post } : { :method => :put })
do |f|
Why does Rails not introspect correctly in this case?
Bryan