Displaying 7 results from an estimated 7 matches for "find_or_create_by".
2006 Mar 14
7
Single form w/ relationships: how do I integrate it?
...9;m creating more noise than I should.
I want to know the easiest way to deal with this scenario:
I have articles. I have categories for the articles.
On the form where you write an article, there needs to be a free-form
field to entire the category.
The create() method will build the article, find_or_create_by_name the
category, and assign it to the article. After that, the article is
saved.
I need to display an error if the category isn''t included, and I need
it to act like a normal form error: add its message to the list of
errors, and highlight the field.
Does anyone know an easy way to do...
2006 Mar 14
1
Dynamic Finders with _or_create Don''t Work?
What could cause this?
>> sdfl=PartNumber.find_by_part_number("1111111")
=> #<PartNumber:0xb78fc744 @attributes={"id"=>"11601",
"part_number"=>"1111111"}>
>> sdfl=PartNumber.find_or_create_by_part_number("1111111")
NoMethodError: undefined method `find_or_create_by_part_number'' for
PartNumber:Class
from /usr/lib/ruby/gems/1.8/gems/activerecord-1.12.2/lib/active_record/base.rb:942:in
`method_missing''
from (irb):5
I could swear this used to wor...
2012 Jun 29
0
Can I make Rails update_attributes with nested form find existing records and add to collections instead of creating new ones?
...ttp://stackoverflow.com/questions/11257662/can-i-make-rails-update-attributes-with-nested-form-find-existing-records-and-ad
I haven''t seen a better answer than one I propose myself but I''d like to
know if it''s possible to enhance accepts_nested_attribute_for to allow a
find_or_create_by behavior for the one-to-many associated collection,
instead of always creating new records.
Thanks!
Yuklai
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To view this discussion on the web visit https://groups.google.com/d/msg...
2006 Oct 21
0
find_or_initialize_by and Nested Resources
...nd_or_intialize_by_country_id(@country)
Since the artist doesn''t exist yet, there will be no ''id'' attribute
yet. However, I have to pass in an id to the url which creates the
song, ie:
new_song_path(@artist)
This will obviously fail since @artist.id is nil. I can use
find_or_create_by instead, but then if the user cancels creating a
song, I will be left with an extra row in the artist table that I
don''t need.
Any ideas?
Shane Vitarana
http://shanesbrain.net
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to t...
2011 Feb 24
1
Rails 3 save parent model and association if nested attributes validation fails for uniqueness
Hi,
Song
has_and_belongs_to_many :people
accepts_nested_attributes_for :people
Person
validates :uniqueness => true
If person record not present, nested attributes working great! in rails way.
i.e., inserting into songs, people and people_songs table correctly.
I am interested in:-
*If there is person exist, it should skip insertion into people table but
data should be inserted in songs and
2008 Feb 08
4
x-post : find_or_initialize_by ActiveRecord bug? Ignores :conditions
....find_by_user_name is actually
Person.find_by_user_name(user_name, options). So you could call
Payment.find_all_by_amount(50, :order => "created_on").
The same dynamic finder style can be used to create the object if it
doesn''t already exist. This dynamic finder is called with
find_or_create_by_ and will return the object if it already exists and
otherwise creates it, then returns it."
Here are a couple of examples. I know these are contrived since I
could use ''find_or_initialize_by_name_and_state()'' however what I am
really trying to show is that the :conditions...
2013 Feb 18
13
Correct Use or Naming of Migrations
Hi Folks,
There is much discussion where I work at present regarding migrations, and
the ''correct'' usage or not of them.
TL;DR
Should migrations be used just to modify schema, and other ''deploy'' tasks
done other ways? If yes, how to ensure no repeat runs of such tasks
(seeds, jobs etc)
Background
Once you''re live there are often additional things