Chris,

Why don't you use (or check how it's done) restful easy messages?
Alternatively, LOVD (lovdbyless.com) does it all.

Cheers, Sazima

On Feb 19, 10:35 pm, Christoph Jasinski
<christoph.jasin...@googlemail.com> wrote:
> Hi,
>
> I'm trying to create an web app where users can write messages to each
> other. I use the restful_authentication plugin for the users. So they have
> an user_id. How ever the messages should have a:
> - sender
> - receiver
> - content
>
> As i saw in some screencast the association use the user_id to connect users
> to something. But in my model there would be 2 user_id column which
> obviously doesn't work. So how do I do it?
>
> My workaround was to create a receiver and sender model which contained a
> user_id and a message_id. Then the message contained a sender_id,
> receiver_id and the content. However now I'm stuck somehow. *Maybe it's
> because 2:30am here and I should be in bed*. I don't know. Is there an
> easier workaround? Some tutorials, maybe?
>
> How do I collect my mails? Have a controller named messages where I tried
> this, but it doesn't work (I thing my association declaration are the
> cause):
> @inbox = current_user.message.find_by_receiver_id(:user)
>
> *The Models:*
>
> class *Message* < ActiveRecord::Base
>   belongs_to :sender
>   has_one :receiver
>
>   validates_presence_of :sender
>   validates_presence_of :receiver
>   validates_length_of :content, :maximum => 4096
> end
>
> class *Receiver* < ActiveRecord::Base
>   belongs_to :message
> end
>
> class *Sender* < ActiveRecord::Base
>   has_many :message
> end
>
> class *User* < ActiveRecord::Base (restful_authentication plugin)
>   # Virtual attribute for the unencrypted password
>   attr_accessor :password
>   ...
>   attr_accessible :login, :email, :password, :password_confirmation
>   ...
> end
>
> Greetings and thanks for any kind of help
>
> Chris
--~--~---------~--~----~------------~-------~--~----~
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 rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to