This is more of a question of "the right tool for the job". If you are building a javascript client, your back end should be an API.
So the real question here is: is Rails good for building APIs? Yes. Are there other alternatives that may be better? Yes.