Forum: Ruby on Rails RoR programming question

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Cdb765f639f8b2def103edd44d9b110f?d=identicon&s=25 Mike Riley (wdperson)
on 2007-06-15 05:16
Hello all,

     I am working on a sample ruby on rails application just to get an
idea on the framework.  Here is where I am having a problem:

I have set up users on the site and am using acts_as_authenticated. I
set up the ability to have user A send a message to user B on the
website. I have set up a form that allows this and it is functional.
What I am trying to do now is to set up the form so that before it saves
the input into MySQL that it checks to see if the recipient user is
valid.  So, what I have done is:

in my create method in my message controller, I set up an if statement
that calls the message model:

if (Usermessage.valid_recipient(@message.recipient))

Usermessage is the model, valid_recipient is the method in the model and
I am passing it a parameter of the input from the text box (recipient)
on the form.

The problem is that it does not matter what username I put into the text
box, it submits the form to the database.  It doesn't throw the second
part of the if statement which is a simple render_text "not a valid
user."  I put another render_text into the first part after the that displays the results of
(Usermessage.valid_recipient(@message.recipient)).  Doing this renders
the "#" sign to the browser.

One problem I have is I need to put some unit tests into the application
and I haven't done this yet (I know this isn't good, but I have to learn
about testing and doing it the right way)....

thanks for any help.
This topic is locked and can not be replied to.