Rails: How to use ActionMailer by itself?

What approaches can we use to cleanly provide access to both API clients and regular users in a Rails application?

  • We're building a Rails 3 web application that will need to authorize and authenticate regular users who visit the site. Those same users may also use third-party applications to access the site via our API. What approaches can we use to effectively and cleanly provide access to clients as well as users? What strategies have you used in your own Rails applications that also have RESTful APIs? Ideally, we're after a solution which: plays well with Devise and CanCan (which we already use for authn/authz) plays well with Mongoid doesn't pollute our controllers is relatively simple to install and configure, if it's a gem or plugin

  • Answer:

    I'm a relative newcomer to Ruby and Rails, but have been doing software development in various languages for over 20 years, and web development for about as long as the web has been around. That said, it seems to me that the best strategy would be to put your business logic into services, rather than what seems to be the standard practice of putting it in the controllers. Then, your controllers can just do authn/authz, and delegate the business logic to the services. You'll likely have different controllers for the browser users vs. the API, but they can share the business logic implemented by the services. This is a fairly standard approach in other languages/frameworks.

Rich Freedman at Quora Visit the source

Was this solution helpful to you?

Other answers

Devise has built in support for token authentication, you can provide your user with an auth token much like a lot of other Apis out there so ur user will have a key and secret the secret is the token devise generated and the key I'd the I'd of the user it's called single sign on. So u still have 1 users table and 1 identity.

Sakchai Grouch Siripanyawuth

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.