1

I'm new to Ruby and want to echo some texts in a controller then abort.

In PHP, I would do

echo "something"; exit;

How do I do it in RoR?

I've tried

render :text => "something"
abort()

The result page only displays "exit"

4

1 回答 1

4

Just return from your action. Don't abort().

As an aside, there are far, far better ways of debugging Rails programs. Look into pry or just logger.info.

Ideally, if you've hit some error state, you should be raising an appropriate exception, and leaving that in your codebase. You can then temporarily add binding.pry or logging statements for debugging, which should come out of your codebase when you've got that area working correctly. It is virtually never correct to simply dump a textual error string to the browser and "exit" with a successful response code.

于 2013-06-18T19:57:22.503 回答