Displaying 20 results from an estimated 20000 matches similar to: ""Overriding" association build methods"
2007 Apr 24
6
Questions about table association while using acts_as_ferret
Hi all,
I''m quite new to ferret and acts_as_ferret and what to see if I can
implement the following requirement using them.
Suppose I have two model classes: Article and Comment. It''s obvious that
one article may have many comments, so this is a one-many relationship.
If I want to add full text search to these models, I''m supposed to use
acts_as_ferret in both of the
2010 Aug 18
11
When after_save isn't after the save....
I have a Production model, which represents a farmer''s crop. After
create (via after_save) I call a method that creates one or more
Supply models, which represent a week of anticipated product harvest.
After each of those are created, a class method gets called that tries
to match each new Supply with outstanding orders for the same time
period. If a match is made, a transaction (an
2007 Mar 17
3
How is this done with REST (blinksale account)?
In Blinksale, the settings link in the top right takes you to the /
account url. From there, the side nav takes you to /account;templates /
account;reminders , etc.
>From what I''ve read, ;templates and ;reminders are custom rest actions
for a given resource. But the controller (account) does not appear to
be of rest nature. Also, when creating a new account, the url is /
firms/new .
2007 Jun 21
1
Validation Through Multiple Models from one Form
Hey All,
I have a form that submits data to multiple models.
I have
class Man < ActiveRecord::Base
has_many :notes
has_many :contacts
validates_associated :contacts, :notes
validates_presence_of :first_name
validates_presence_of :last_name
class Contact < ActiveRecord::Base
belongs_to :man
validates_presence_of :contact_info
class Note < ActiveRecord::Base
2007 Feb 01
4
Automatically Indexing Associated Models
PROBLEM
I have two models, Blog and BlogComment. When a blog is initially
created, it has no comments. Upon creation, the title and body are
automatically added to the ferret index and directly searchable.
However, when a comment is added to a blog, that comment does not get
added to the index and is therefore not ferretable. The desired behavior
is that when a comment is added to a blog, that the
2004 Jun 30
12
New addition to FAQ
Greetings,
I was on IRC about 7 hours ago and suggested that the FAQ be updated slightly.
Rather than sit on my ass and complain I figured I'd ask a few people, and see
if the idea was worth the time.
Here's what Ive started with:
http://www.dimension.net.nz/theora.html
I'll be adding to it over the next 24 hours - mostly in the area of Playback
and Encoding.
Just threw it together
2009 Mar 29
2
after_create and after_save
Hi,
AFAIK after_create is called after_save if the entry does not exist in
the DB.
Is there a way to tell if a specific model is new or not in
after_save?
I have to do something like:
def after_save
add_to_history ''save''
end
def after_create
add_to_history ''create''
end
However after_save is called when creating too.
--
cheers,
M.
2006 Jul 17
2
Very strange after_save problem. Please help.
I have a very strange problem here. I do not get this. So any help is
greatly appreciated.
Basically I have a model that calls a method in the background
process in the "after_save" method. Let''s call the model products. So
what happens is this:
1. I create a new product.
2. Everything works and the product is saved with id 13.
3. A method is called in my background
2006 Jul 17
2
after_save deletes is an exception is raised?
Does after_save in a model delete if an exception is raised in there?
I simply did
def after_save
raise ''hmmm''
end
and it raised the exception but there was nothing in the database. I
removed that entire method and its in the database. Is this correct?
Thank You,
Ben Johnson
E: bjohnson@contuitive.com
-------------- next part --------------
An HTML attachment was
2006 Jul 17
5
Keeping attributes of two models in sync
Hi,
I have a Product and a corresponding Keyword (1:1 via belongs_to and
has_one). I want to ensure, that two attributes (:name) of the two
models alway stay in sync. What''s the easiest way to accomplish that?
I did play around with before_/after_save hooks and with
AR::Observers but in the end I''d always get infinite recursion...
Thanks,
Timo
2012 Jul 07
18
Problem processing text file after uploading
I''ve got a web-app currently partially working. The user uploads a .txt,
.docx or .doc file to the server.
Currently the model handles those files, saves some metadata (the
extention and orig filename) then saves the file to the hard drive. Next
it converts the doc and docx files to plain text and saves the output to
a txt file.
My problem is I want to copy the plain text contents of
2006 May 09
2
handling file upload onto local filesystem.
Hi,
I have a multipart form upload field uploaded through <%=
file_field("profile", "profile") %>
Once a submit happens, the action basically does something like:
profile = Profile.new(params["picture"])
This invokes the models = to method:
def picture=(picture_field)
...do a bunch of assignments here
end
def validate
... do a bunch of validations
2006 Aug 23
5
validation, concurrency, and transactions
Hi,
Something has been bothering me about model validation: how do I know that
the database has not changed in between when I validate my model''s data, and
when it actually gets saved to the database? As a simple example, say I have
a User model like:
class User
validates_uniqueness_of :username
end
When this gets saved to the database, the validation code checks that there is
2010 Jul 28
1
paperclip, authlogic and callback issue
I use authlogic for authentication and paperclip for handling user''s
profile picture attachments.
I use the following method to get the current_user
def current_user_session
return @current_user_session if defined?
(@current_user_session)
@current_user_session = UserSession.find
end
def current_user
return @current_user if defined?(@current_user)
2007 Nov 26
6
Model setters, override attribute=(attribute)?
Hi,
I have a model similar Basket shown below. If customer_type is set
then it should also set customer to nil. Likewise, if I set customer,
it should inspect the customer_type attached to the customer and set
accordingly within Basket. However implementing it as below doesn''t
seem to work.
Am I missing a better way to achieve this? I had also considered using
a before_save
2006 Jun 03
1
Can I tell if the associated record is new in a belongs_to save?
In a belongs_to association, is there a way to tell if the associated object
was newly created?
Hopefully this will explain my question:
A Firm class declares
has_many<http://api.rubyonrails.com/classes/ActiveRecord/Associations/ClassMethods.html#M000530>:clients
and a
client class declares
2010 May 12
2
How to add an after_save callback on runtime on a particular instance
class User < AR
end
user = User.new
Let''s say that I have a user instance with me. After this record is
saved I want an after_save callback which would print the id of the
record.
The only catch is that I am not allowed to change the User class. How
can I accomplish my goal? Is that even possible to add an after_save
callback on a particular instance object. Any metaprogramming
2007 May 06
3
Using session-type data in an ActiveRecord callback...
Any suggestions on how best to gain access to session-type information
while in an ActiveRecord callback, such as after_save?
I am encrypting some information in the database, using the
generalized encryption/decryption handler in "Agile Web Development
With Rails" (p 375ff). I got it working, and now I want to reference
a session field (a user PIN) which is NOT stored in the
2007 May 20
1
beating a dead horse - proper association selection
okay... i have two models
employee
- id
- username
order
- id
- number
- created_by
- approved_by
now created_by and approved_by are both id''s of employees. in most
cases, two different employees.
currently i do something like
//controller
@open_orders = Order.open_orders
//model
def self.open_orders
find(:all, :conditions => [''is_open = ?'', true],
2009 Mar 04
5
[PATCH 0/2] ocfs2: two bug fixes about xattr and inline-data
Mark and Joel,
I found two serious bugs about xattr and inline-data.
the first bug:
in ocfs2_mknod(), we check and found the ACL or security xattr entry
could be set into inode in ocfs2_calc_xattr_init(), then don't reserve
block for them. But in ocfs2_mknod_locked(), if we found ocfs2 support
inline-data, then set id_count with the max_inline_data. After that, we
set acl/security xattr