# RoR programming question

**URL:** <https://www.ruby-forum.com/t/ror-programming-question/106899>\
**Category:** Rails\
**Created:** [June 15, 2007, 5:16am UTC](https://www.ruby-forum.com/t/ror-programming-question/106899 "2007-06-15T05:16:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![randall](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b38774/32.png) [@randall](https://www.ruby-forum.com/u/randall)\
**Post date:** [June 15, 2007, 5:16am UTC](https://www.ruby-forum.com/t/ror-programming-question/106899/1 "2007-06-15T05:16:03Z")

</div>

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  
@message.save 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.  
Mike
