How to pass a variable from a model method to a controller

Hi there,

how can I pass a variable from a model method to the controller that
calls this method?

In the below code, I tried by placing "return @errormessage" in the
model method and then trying to retrieve it in the controller, but it's
wrong. What's the correct way to do that?

Here's what it looks like until now (simplified)...

In my controller:

You got that right, I'm not (yet) an experienced ruby programmer, but
you've just helped me to get a step further - so thanks a lot, bro !

Not 100% sure I understand what you’re trying to do, but here are a couple of items that strike me based on the code posted.

First, your model method has two return statements. I don’t know
whether Ruby will throw up some kind of parsing error to that, but
certainly the second of those will never be executed.

Second, putting error message text in the model is probably not what
you want to be doing. Your error messages are not part of your
business logic. Most people put these things in the controller,
although strictly speaking, they probably belong in the view (though
Rails doesn’t make it very easy to put them there and keep your code
looking good).

Finally, I assume your controller is taking in some input as HTTP request params before it runs this “does_my_check_pass?” method. If so, then I guess your check should actually be a part of the standard ActiveRecord validation process. In that case, inputs will be checked every time you create or update a new User object rather than in any case you remember to call it. The proper flow control through the controller action should be pretty standard: rececive inputs, delegate validation to the model, perform necessary model operations (CRUD), and render/redirect user output.

Hope that is helpful to you.