Giter Club home page Giter Club logo

rails-api's Introduction

Rails::API

Build Status

IMPORTANT: Rails::API has been merged into Rails

Rails::API is a subset of a normal Rails application, created for applications that don't require all functionality that a complete Rails application provides. It is a bit more lightweight, and consequently a bit faster than a normal Rails application. The main example for its usage is in API applications only, where you usually don't need the entire Rails middleware stack nor template generation.

Using Rails for API-only Apps

This is a quick walk-through to help you get up and running with Rails::API to create API-only Apps, covering:

  • What Rails::API provides for API-only applications
  • How to decide which middlewares you will want to include
  • How to decide which modules to use in your controller

What is an API app?

Traditionally, when people said that they used Rails as an "API", they meant providing a programmatically accessible API alongside their web application. For example, GitHub provides an API that you can use from your own custom clients.

With the advent of client-side frameworks, more developers are using Rails to build a backend that is shared between their web application and other native applications.

For example, Twitter uses its public API in its web application, which is built as a static site that consumes JSON resources.

Instead of using Rails to generate dynamic HTML that will communicate with the server through forms and links, many developers are treating their web application as just another client, consuming a simple JSON API.

This guide covers building a Rails application that serves JSON resources to an API client or client-side framework.

Why use Rails for JSON APIs?

The first question a lot of people have when thinking about building a JSON API using Rails is: "isn't using Rails to spit out some JSON overkill? Shouldn't I just use something like Sinatra?"

For very simple APIs, this may be true. However, even in very HTML-heavy applications, most of an application's logic is actually outside of the view layer.

The reason most people use Rails is that it provides a set of defaults that allows us to get up and running quickly without having to make a lot of trivial decisions.

Let's take a look at some of the things that Rails provides out of the box that are still applicable to API applications.

Handled at the middleware layer:

  • Reloading: Rails applications support transparent reloading. This works even if your application gets big and restarting the server for every request becomes non-viable.
  • Development Mode: Rails application come with smart defaults for development, making development pleasant without compromising production-time performance.
  • Test Mode: Ditto test mode.
  • Logging: Rails applications log every request, with a level of verbosity appropriate for the current mode. Rails logs in development include information about the request environment, database queries, and basic performance information.
  • Security: Rails detects and thwarts IP spoofing attacks and handles cryptographic signatures in a timing attack aware way. Don't know what an IP spoofing attack or a timing attack is? Exactly.
  • Parameter Parsing: Want to specify your parameters as JSON instead of as a URL-encoded String? No problem. Rails will decode the JSON for you and make it available in params. Want to use nested URL-encoded params? That works too.
  • Conditional GETs: Rails handles conditional GET, (ETag and Last-Modified), processing request headers and returning the correct response headers and status code. All you need to do is use the stale? check in your controller, and Rails will handle all of the HTTP details for you.
  • Caching: If you use dirty? with public cache control, Rails will automatically cache your responses. You can easily configure the cache store.
  • HEAD requests: Rails will transparently convert HEAD requests into GET requests, and return just the headers on the way out. This makes HEAD work reliably in all Rails APIs.

While you could obviously build these up in terms of existing Rack middlewares, I think this list demonstrates that the default Rails middleware stack provides a lot of value, even if you're "just generating JSON".

Handled at the ActionPack layer:

  • Resourceful Routing: If you're building a RESTful JSON API, you want to be using the Rails router. Clean and conventional mapping from HTTP to controllers means not having to spend time thinking about how to model your API in terms of HTTP.
  • URL Generation: The flip side of routing is URL generation. A good API based on HTTP includes URLs (see the GitHub gist API for an example).
  • Header and Redirection Responses: head :no_content and redirect_to user_url(current_user) come in handy. Sure, you could manually add the response headers, but why?
  • Basic, Digest and Token Authentication: Rails comes with out-of-the-box support for three kinds of HTTP authentication.
  • Instrumentation: Rails 3.0 added an instrumentation API that will trigger registered handlers for a variety of events, such as action processing, sending a file or data, redirection, and database queries. The payload of each event comes with relevant information (for the action processing event, the payload includes the controller, action, params, request format, request method and the request's full path).
  • Generators: This may be passé for advanced Rails users, but it can be nice to generate a resource and get your model, controller, test stubs, and routes created for you in a single command.
  • Plugins: Many third-party libraries come with support for Rails that reduces or eliminates the cost of setting up and gluing together the library and the web framework. This includes things like overriding default generators, adding rake tasks, and honoring Rails choices (like the logger and cache backend).

Of course, the Rails boot process also glues together all registered components. For example, the Rails boot process is what uses your config/database.yml file when configuring ActiveRecord.

The short version is: you may not have thought about which parts of Rails are still applicable even if you remove the view layer, but the answer turns out to be "most of it".

The Basic Configuration

If you're building a Rails application that will be an API server first and foremost, you can start with a more limited subset of Rails and add in features as needed.

NOTE: rails-api only supports Ruby 1.9.3 and above.

For new apps

Install the gem if you haven't already:

gem install rails-api

Then generate a new Rails::API app:

rails-api new my_api

This will do two main things for you:

  • Make ApplicationController inherit from ActionController::API instead of ActionController::Base. As with middleware, this will leave out any ActionController modules that provide functionality primarily used by browser applications.
  • Configure the generators to skip generating views, helpers and assets when you generate a new resource.

Rails includes all of the sub-frameworks (ActiveRecord, ActionMailer, etc) by default. Some API projects won't need them all, so at the top of config/application.rb, you can replace require 'rails/all' with specific sub-frameworks:

# config/application.rb
# require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
# require "sprockets/railtie"
require "rails/test_unit/railtie"

This can also be achieved with flags when creating a new Rails::API app:

rails-api new my_api --skip-active-record --skip-sprockets

Note: There are references to ActionMailer and ActiveRecord in the various config/environment files. If you decide to exclude any of these from your project its best to comment these out in case you need them later.

# comment out this in config/environments/development.rb
config.active_record.migration_error = :page_load
config.action_mailer.raise_delivery_errors = false

# comment out this in config/environments/test.rb
config.action_mailer.delivery_method = :test

For already existing apps

If you want to take an existing app and make it a Rails::API app, you'll have to do some quick setup manually.

Add the gem to your Gemfile:

gem 'rails-api'

And run bundle to install the gem.

Change app/controllers/application_controller.rb:

# instead of
class ApplicationController < ActionController::Base
end

# do
class ApplicationController < ActionController::API
end

And comment out the protect_from_forgery call if you are using it. (You aren't using cookie-based authentication for your API, are you?)

If you want to use the Rails default middleware stack (avoid the reduction that rails-api does), you can just add config.api_only = false to config/application.rb file.

Serialization

We suggest using ActiveModel::Serializers to serialize your ActiveModel/ActiveRecord objects into the desired response format (e.g. JSON).

Choosing Middlewares

An API application comes with the following middlewares by default.

  • ActionDispatch::DebugExceptions: Log exceptions.
  • ActionDispatch::ParamsParser: Parse XML, YAML and JSON parameters when the request's Content-Type is one of those.
  • ActionDispatch::Reloader: In development mode, support code reloading.
  • ActionDispatch::RemoteIp: Protect against IP spoofing attacks.
  • ActionDispatch::RequestId: Makes a unique request id available, sending the id to the client via the X-Request-Id header. The unique request id can be used to trace a request end-to-end and would typically end up being part of log files from multiple pieces of the stack.
  • ActionDispatch::ShowExceptions: Rescue exceptions and re-dispatch them to an exception handling application.
  • Rack::Cache: Caches responses with public Cache-Control headers using HTTP caching semantics.
  • Rack::Head: Dispatch HEAD requests as GET requests, and return only the status code and headers.
  • Rack::ConditionalGet: Supports the stale? feature in Rails controllers.
  • Rack::ETag: Automatically set an ETag on all string responses. This means that if the same response is returned from a controller for the same URL, the server will return a 304 Not Modified, even if no additional caching steps are taken. This is primarily a client-side optimization; it reduces bandwidth costs but not server processing time.
  • Rack::Lock: If your application is not marked as threadsafe (config.threadsafe!), this middleware will add a mutex around your requests.
  • Rack::Runtime: Adds a header to the response listing the total runtime of the request.
  • Rack::Sendfile: Uses a front-end server's file serving support from your Rails application.
  • Rails::Rack::Logger: Log the request started and flush all loggers after it.

Other plugins, including ActiveRecord, may add additional middlewares. In general, these middlewares are agnostic to the type of app you are building, and make sense in an API-only Rails application.

You can get a list of all middlewares in your application via:

rake middleware

Other Middlewares

Rails ships with a number of other middlewares that you might want to use in an API app, especially if one of your API clients is the browser:

  • Rack::MethodOverride: Allows the use of the _method hack to route POST requests to other verbs.
  • ActionDispatch::Cookies: Supports the cookie method in ActionController, including support for signed and encrypted cookies.
  • ActionDispatch::Flash: Supports the flash mechanism in ActionController.
  • ActionDispatch::BestStandards: Tells Internet Explorer to use the most standards-compliant available renderer. In production mode, if ChromeFrame is available, use ChromeFrame.
  • Session Management: If a config.session_store is supplied and config.api_only = false, this middleware makes the session available as the session method in ActionController.

Any of these middlewares can be added via:

config.middleware.use Rack::MethodOverride

Removing Middlewares

If you don't want to use a middleware that is included by default in the API middleware set, you can remove it using config.middleware.delete:

config.middleware.delete ::Rack::Sendfile

Keep in mind that removing these features may remove support for certain features in ActionController.

Choosing Controller Modules

An API application (using ActionController::API) comes with the following controller modules by default:

  • ActionController::UrlFor: Makes url_for and friends available
  • ActionController::Redirecting: Support for redirect_to
  • ActionController::Rendering: Basic support for rendering
  • ActionController::Renderers::All: Support for render :json and friends
  • ActionController::ConditionalGet: Support for stale?
  • ActionController::ForceSSL: Support for force_ssl
  • ActionController::RackDelegation: Support for the request and response methods returning ActionDispatch::Request and ActionDispatch::Response objects.
  • ActionController::DataStreaming: Support for send_file and send_data
  • AbstractController::Callbacks: Support for before_filter and friends
  • ActionController::Instrumentation: Support for the instrumentation hooks defined by ActionController (see the source for more).
  • ActionController::Rescue: Support for rescue_from.

Other plugins may add additional modules. You can get a list of all modules included into ActionController::API in the rails console:

ActionController::API.ancestors - ActionController::Metal.ancestors

Adding Other Modules

All Action Controller modules know about their dependent modules, so you can feel free to include any modules into your controllers, and all dependencies will be included and set up as well.

Some common modules you might want to add:

  • AbstractController::Translation: Support for the l and t localization and translation methods. These delegate to I18n.translate and I18n.localize.
  • ActionController::HttpAuthentication::Basic::ControllerMethods (or Digest or Token): Support for basic, digest or token HTTP authentication.
  • ActionView::Layouts: Support for layouts when rendering.
  • ActionController::MimeResponds (and ActionController::ImplicitRender for Rails 4): Support for content negotiation (respond_to, respond_with).
  • ActionController::Cookies: Support for cookies, which includes support for signed and encrypted cookies. This requires the cookie middleware.

The best place to add a module is in your ApplicationController. You can also add modules to individual controllers.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Maintainers

License

MIT License.

Mailing List

https://groups.google.com/forum/?fromgroups#!forum/rails-api-core

rails-api's People

Contributors

aarongray avatar adomokos avatar bearded avatar buddhamagnet avatar carlesjove avatar carlosantoniodasilva avatar davidpaulhunt avatar dgsan avatar dpowell avatar fsmanuel avatar harlow avatar jmonteiro avatar joshk avatar kjg avatar knoopx avatar litch avatar lukaszx0 avatar mauricio avatar michaelrkn avatar philm avatar rafaelfranca avatar rmaksymczuk avatar semmons99 avatar sidane avatar spastorino avatar steveklabnik avatar tamird avatar vipulnsward avatar wintery avatar xsuchy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rails-api's Issues

Version 1.0.0

Since this is just a subset of Rails, with a few opinions thrown in, this gem is probably 1.0.0 already instead of 0.0.1.

Support OAuth / OAuth2 ?

An API often needs some kind of authorization and user authentication.
It would be nice if rails-api would support OAuth / OAuth2 out of the box.

Missing "respond_to do |format|"

A common idiom in Rails controllers is to do:

respond_to do |format|
  format.xml { render :xml=> ... }
  format.json { render :json=> ... }
end

This was one of the first things I missed when I first tried Rails::API. It also causes problems when gems expect respond_to to be there. (See for example https://github.com/voomify/egregious/blob/master/lib/egregious.rb#L173)

I think respond_to should be added back in. It's common to build APIs that must respond to different formats, such as both JSON and XML. If one's API is JSON-only, the functionality can always be ignored.

Problem reinserting ActionDispatch::Cookies

I like the idea of having an ActionController::Base to serve the usual kind of frontend solution and ActionController::API for the service REST part. But when I want to restore ActionDispatch::Cokies

application.rb
config.middleware.insert_after ActionDispatch::Cookies

I get a:

/gems/actionpack-3.2.3/lib/action_dispatch/middleware/stack.rb:120:in assert_index': No such middleware to insert after: ActionDispatch::Cookies (RuntimeError) from /home/matias/.rvm/gems/ruby-1.9.3-p194@logservice/gems/actionpack-3.2.3/lib/action_dispatch/middleware/stack.rb:91:ininsert_after'
from /home/matias/.rvm/gems/ruby-1.9.3-p194@logservice/gems/railties-3.2.3/lib/rails/configuration.rb:38:in block in merge_into' from /home/matias/.rvm/gems/ruby-1.9.3-p194@logservice/gems/railties-3.2.3/lib/rails/configuration.rb:37:ineach'
from /home/matias/.rvm/gems/ruby-1.9.3-p194@logservice/gems/railties-3.2.3/lib/rails/configuration.rb:37:in merge_into' from /home/matias/.rvm/gems/ruby-1.9.3-p194@logservice/gems/railties-3.2.3/lib/rails/engine.rb:469:inapp'
from /home/matias/.rvm/gems/ruby-1.9.3-p194@logservice/gems/railties-3.2.3/lib/rails/application/finisher.rb:31:in block in <module:Finisher>' from /home/matias/.rvm/gems/ruby-1.9.3-p194@logservice/gems/railties-3.2.3/lib/rails/initializable.rb:30:ininstance_exec'
from /home/matias/.rvm/gems/ruby-1.9.3-p194@logservice/gems/railties-3.2.3/lib/rails/initializable.rb:30:in run' from /home/matias/.rvm/gems/ruby-1.9.3-p194@logservice/gems/railties-3.2.3/lib/rails/initializable.rb:55:inblock in run_initializers'
from /home/matias/.rvm/gems/ruby-1.9.3-p194@logservice/gems/railties-3.2.3/lib/rails/initializable.rb:54:in each' from /home/matias/.rvm/gems/ruby-1.9.3-p194@logservice/gems/railties-3.2.3/lib/rails/initializable.rb:54:inrun_initializers'
from /home/matias/.rvm/gems/ruby-1.9.3-p194@logservice/gems/railties-3.2.3/lib/rails/application.rb:136:in initialize!' from /home/matias/.rvm/gems/ruby-1.9.3-p194@logservice/gems/railties-3.2.3/lib/rails/railtie/configurable.rb:30:inmethod_missing'
from /home/matias/workspace/ayla/logservice/config/environment.rb:5:in <top (required)>' from /home/matias/.rvm/gems/ruby-1.9.3-p194@logservice/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:inrequire'
from /home/matias/.rvm/gems/ruby-1.9.3-p194@logservice/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in block in require' from /home/matias/.rvm/gems/ruby-1.9.3-p194@logservice/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:236:inload_dependency'
from /home/matias/.rvm/gems/ruby-1.9.3-p194@logservice/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in require' from /home/matias/workspace/ayla/logservice/config.ru:4:inblock in

'
from /home/matias/.rvm/gems/ruby-1.9.3-p194@logservice/gems/rack-1.4.1/lib/rack/builder.rb:51:in instance_eval' from /home/matias/.rvm/gems/ruby-1.9.3-p194@logservice/gems/rack-1.4.1/lib/rack/builder.rb:51:ininitialize'
from /home/matias/workspace/ayla/logservice/config.ru:1:in new' from /home/matias/workspace/ayla/logservice/config.ru:1:in'
from /home/matias/.rvm/gems/ruby-1.9.3-p194@logservice/gems/rack-1.4.1/lib/rack/builder.rb:40:in eval' from /home/matias/.rvm/gems/ruby-1.9.3-p194@logservice/gems/rack-1.4.1/lib/rack/builder.rb:40:inparse_file'
from /home/matias/.rvm/gems/ruby-1.9.3-p194@logservice/gems/rack-1.4.1/lib/rack/server.rb:200:in app' from /home/matias/.rvm/gems/ruby-1.9.3-p194@logservice/gems/railties-3.2.3/lib/rails/commands/server.rb:46:inapp'
from /home/matias/.rvm/gems/ruby-1.9.3-p194@logservice/gems/rack-1.4.1/lib/rack/server.rb:301:in wrapped_app' from /home/matias/.rvm/gems/ruby-1.9.3-p194@logservice/gems/rack-1.4.1/lib/rack/server.rb:252:instart'
from /home/matias/.rvm/gems/ruby-1.9.3-p194@logservice/gems/railties-3.2.3/lib/rails/commands/server.rb:70:in start' from /home/matias/.rvm/gems/ruby-1.9.3-p194@logservice/gems/railties-3.2.3/lib/rails/commands.rb:55:inblock in <top (required)>'
from /home/matias/.rvm/gems/ruby-1.9.3-p194@logservice/gems/railties-3.2.3/lib/rails/commands.rb:50:in tap' from /home/matias/.rvm/gems/ruby-1.9.3-p194@logservice/gems/railties-3.2.3/lib/rails/commands.rb:50:in<top (required)>'
from script/rails:6:in require' from script/rails:6:in'

Pagination

I have been working on a "rails-api" application for a few weeks now. I am at the point where I need to implement pagination as part of my REST API collections. I have started using kaminari for pagination on the model, but I am not sure how I should implement pagination as part of the HTTP response. I want to be able to send back the number of pages, results per page, etc. so that the client can create pagination to be displayed client-side. Do you have any recommendations on how I should handle this?

This brings me to an idea...it would be nice if there was a place where I (and others) could go to read about best practices for building an API with Rails. I know there are more than one way to create an API but it would be nice if there was some documentation, or a wiki which listed different approaches to handling a common situation. That way, the rails-api gem wouldn't necessarily need to provide the solution, rather, there would be ideas/documentation on how one could handle this themselves.

P.S. Sorry for posting this here since it's not really an "issue". I would have posted this in a mailing list, but it doesn't look like there is a mailing list for this project.

Minor update to README related to fragment caching for JSON building

In the sales/marketing part of the rails-api documentation when it states:

"Caching: Rails provides page, action and fragment caching. Fragment caching is especially helpful when building up a nested JSON object."

I think this is misleading because people may think they need to use Rails views and then get sidetracked by implementing to_json, then as_json, then using other gems such as RABL in order to deserialize objects into JSON, when instead they should consider use of active_model_serializers (AMS). Would it make sense to update this part of the documentation to indicate that AMS can be used?

I'd do a pull request, but I'm not quite sure how to phrase it. I do think this might be a point of confusion to those planning to use rails-api though. With AMS, it is much easier to deserialize objects into JSON for the response. I understand that AMS is also listed under the rails-api group in GitHub and people should hopefully just see it (and they'll be using it in Rails 4), but I think a mention in the rails-api README wouldn't hurt.

ActionController::RoutingError: No route matches [...]

First : This is a dupe from rspec/rspec-rails#671 but I'm posting here too since I don't really know what's going on and if this is related to rails-api or rspec.
if this is not rails-api related feel free to close.

I'm writting an API for a pet project of mine and was running rails 3.2.9
I decided to update rails in order to avoid security problems but I suddenly ran into some problems.

I've been able to resolve most of them but I keep getting this and don't know what to do with it.

I am using RSPEC to test a json API and until this upgrade everything was going just fine and all routes were working perfectly.

I'm not sure wether it's a bug or a bad usage from me, so I'm sorry if it's the former.
Here is my code :

Routes :

Fake::Application.routes.draw do
    namespace :api do
        namespace :v1 do
            scope '/user' do
                match "signup" => "registrations#create", :via => :post
                match "delete" => "registrations#destroy", :via => :delete

                match "login"  => "sessions#create", :via => :post
                match "logout" => "sessions#destroy", :via => :delete
            end
        end
    end
end

Spec :

require 'spec_helper'

describe Api::V1::SessionsController do
    before do
        @user = {
            :email => Faker::Internet::email,
            :pseudo => Faker::Internet::user_name,
            :password => Faker::Lorem::words(2).join
        }
        user = User.create @user
    end

    context 'should login in' do

        it 'should be ok ' do
            post '/api/v1/user/login', :user => @user
            JSON.parse(response.body)["success"].should == true
        end

        it 'should fail without credentials' do
            post '/api/v1/user/login', {}
            JSON.parse(response.body)["success"].should == false
        end
    end
end

And the result :

± rspec spec/controllers/sessions_controller_spec.rb                                                                                                                    5:21:10 PM
Rack::File headers parameter replaces cache_control after Rack 1.5.
FF

Failures:

  1) Api::V1::SessionsController should login in should be ok with auth_token
     Failure/Error: post '/api/v1/user/login', :user => @user
     ActionController::RoutingError:
       No route matches {:user=>{:email=>"[email protected]", :pseudo=>"linwood_gislason", :password=>"repellendusaliquid"}, :controller=>"api/v1/sessions", :action=>"/api/v1/user/login"}
     # ./spec/controllers/sessions_controller_spec.rb:17:in `block (3 levels) in <top (required)>'

  2) Api::V1::SessionsController should login in should fail without credentials
     Failure/Error: post '/api/v1/user/login', {}
     ActionController::RoutingError:
       No route matches {:controller=>"api/v1/sessions", :action=>"/api/v1/user/login"}
     # ./spec/controllers/sessions_controller_spec.rb:22:in `block (3 levels) in <top (required)>'

Finished in 0.50905 seconds
2 examples, 2 failures

Failed examples:

rspec ./spec/controllers/sessions_controller_spec.rb:15 # Api::V1::SessionsController should login in should be ok with auth_token
rspec ./spec/controllers/sessions_controller_spec.rb:21 # Api::V1::SessionsController should login in should fail without credentials

Edit :

Rails version : 3.2.11
Rspec version : 2.12.2
Ruby version : ruby 1.9.3p0

uninitialized constant Rails::Engine (NameError) when launching sidekiq

It looks like rails-api somehow interferes with rails loading Rails::Engine when running sidekiq. When I try to run bundle exec sidekiq from command line or Procfile, I get the following error. If I comment out gem 'rails-api' from the Gemfile and change my ApplicationController to inherit from ActionController::Base instead of ActionController::API, everything works.

I, [2012-05-23T20:50:41.508564 #51739]  INFO -- : Shutdown completed cleanly
/Users/JackC/.rvm/gems/ruby-1.9.3-p194@kickpuncher/gems/sidekiq-1.2.1/lib/sidekiq/rails.rb:14:in `<module:Sidekiq>': uninitialized constant Rails::Engine (NameError)
  from /Users/JackC/.rvm/gems/ruby-1.9.3-p194@kickpuncher/gems/sidekiq-1.2.1/lib/sidekiq/rails.rb:1:in `<top (required)>'
  from /Users/JackC/.rvm/gems/ruby-1.9.3-p194@kickpuncher/gems/sidekiq-1.2.1/lib/sidekiq.rb:10:in `require'
  from /Users/JackC/.rvm/gems/ruby-1.9.3-p194@kickpuncher/gems/sidekiq-1.2.1/lib/sidekiq.rb:10:in `<top (required)>'
  from /Users/JackC/.rvm/gems/ruby-1.9.3-p194@kickpuncher/gems/sidekiq-1.2.1/lib/sidekiq/cli.rb:30:in `require'
  from /Users/JackC/.rvm/gems/ruby-1.9.3-p194@kickpuncher/gems/sidekiq-1.2.1/lib/sidekiq/cli.rb:30:in `<top (required)>'
  from /Users/JackC/.rvm/gems/ruby-1.9.3-p194@kickpuncher/gems/sidekiq-1.2.1/bin/sidekiq:3:in `require_relative'
  from /Users/JackC/.rvm/gems/ruby-1.9.3-p194@kickpuncher/gems/sidekiq-1.2.1/bin/sidekiq:3:in `<top (required)>'
  from /Users/JackC/.rvm/gems/ruby-1.9.3-p194@kickpuncher/bin/sidekiq:19:in `load'
  from /Users/JackC/.rvm/gems/ruby-1.9.3-p194@kickpuncher/bin/sidekiq:19:in `<main>'
  from /Users/JackC/.rvm/gems/ruby-1.9.3-p194@kickpuncher/bin/ruby_noexec_wrapper:14:in `eval'
  from /Users/JackC/.rvm/gems/ruby-1.9.3-p194@kickpuncher/bin/ruby_noexec_wrapper:14:in `<main>'

NoMethodError: undefined method `wrap_parameters' for ActionController::API:Class

I've integrated rails-api into an existing Rails app. I got this error on app startup and narrowed the problem down to this chunk of auto-generated code in the Rails app:

config/initializers/wrap_parameters.rb:

# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
ActiveSupport.on_load(:action_controller) do
  wrap_parameters :format => [:json]
end

It turns out that ActionController::API also fires the :action_controller on_load Railties event. I've worked around the issue by doing this:

ActiveSupport.on_load(:action_controller) do
  if self == ActionController::Base
    wrap_parameters :format => [:json]
  end
end

...but it seems sensible that the problem should be fixed in rails-api.

I'm not sure what the correct approach would be. Perhaps fire a different event?

on_load(:action_controller_api)

Including HttpAuthentication problem

class Api::V1::ApplicationController < ActionController::API
  include ActionController::HttpAuthentication::Basic::ControllerMethods

  before_filter :require_token

  private

  def require_token
    authenticate_or_request_with_http_token do |key, options|
      @current_user = Token.find_by_key(key).account if Token.exists?(key: key)
    end
  end
end

This results in the error:

NoMethodError: undefined method `authenticate_or_request_with_http_token' for #<Api::V1::AccountsController:0x007ffc81a50818>
    /Users/krainboltgreene/Code/Ruby/manacurve-api/app/controllers/api/v1/application_controller.rb:9:in `require_token'

As I understand it, including that module should allow me access to the Token auth.

Browser related middleware present in rails4 api app

An app generated from master rails-api, to get rails4 skeleton, uses middleware that is not used for a rails3 one. This is the difference:

use Rack::MethodOverride
use ActionDispatch::Cookies
use ActionDispatch::Session::CookieStore
use ActionDispatch::Flash

Shouldn't those middlewares be filtered out for an api-only app, as they are for rails3?

Devise Undefined method `helper'

When I run integration tests, I get the following error

Running: test/integration/event_integration_test.rb
/Users/wintery/.rvm/gems/ruby-1.9.3-p194/gems/devise-2.0.4/app/controllers/devise_controller.rb:5:in `<class:DeviseController>': undefined method `helper' for DeviseController:Class (NoMethodError)
  from /Users/wintery/.rvm/gems/ruby-1.9.3-p194/gems/devise-2.0.4/app/controllers/devise_controller.rb:2:in `<top (required)>'

unable to intall gem

Hey
I am unable to install the gem with gem install rails-api
It throws an error which reads like this

ERROR: While executing gem ... (NoMethodError)
undefined method `request_uri' for #URI::Generic:0x9308744

I have already updated my rubygems version to 1.8.24 but still not worked out.

scaffold raises exception creating functional test for controller

I run "rails-api new todo;cd todo;rails g scaffold task name". The following is the truncated output generating scaffold.

  invoke  active_record
  create    db/migrate/20120602011756_create_ytasks.rb
  create    app/models/ytask.rb
  invoke    test_unit
  create      test/unit/ytask_test.rb
  create      test/fixtures/ytasks.yml
   route  resources :ytasks, except: :edit
  invoke  scaffold_controller
  create    app/controllers/ytasks_controller.rb
  invoke    test_unit
  create      test/functional/ytasks_controller_test.rb

(erb):22:in block in template': undefined local variable or methodattributes_
hash' for #TestUnit::Generators::ScaffoldGenerator:0x36fe970 (NameError)
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/thor-0.14.6/li
b/thor/actions/file_manipulation.rb:259:in call' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/thor-0.14.6/li b/thor/actions/file_manipulation.rb:259:inblock in capture'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/thor-0.14.6/li
b/thor/actions/file_manipulation.rb:264:in `with_output_buffer'

The generated model and controller work fine, just the functional test is not generated.

As you can see from the paths above, I am running windows. My config is

rake about

About your application's environment
Ruby version 1.9.3 (i386-mingw32)
RubyGems version 1.8.16
Rack version 1.4
Rails version 3.2.1
Active Record version 3.2.1
Action Pack version 3.2.1
Active Resource version 3.2.1
Action Mailer version 3.2.1
Active Support version 3.2.1
Middleware ActionDispatch::Static, Rack::Lock, #<ActiveSupport::C
ache::Strategy::LocalCache::Middleware:0x398b8a8>, Rack::Runtime, ActionDispatch
::RequestId, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch
::DebugExceptions, ActionDispatch::RemoteIp, ActionDispatch::Reloader, ActionDis
patch::Callbacks, ActiveRecord::ConnectionAdapters::ConnectionManagement, Active
Record::QueryCache, ActionDispatch::ParamsParser, ActionDispatch::Head, Rack::Co
nditionalGet, Rack::ETag

gem list --local

actionmailer (3.2.1)
actionpack (3.2.5, 3.2.1)
activemodel (3.2.5, 3.2.1)
activerecord (3.2.1)
activerecord-sqlserver-adapter (3.2.1)
activeresource (3.2.1)
activesupport (3.2.5, 3.2.1)
arel (3.0.2)
bcrypt-ruby (3.0.1 x86-mingw32)
bigdecimal (1.1.0)
builder (3.0.0)
bundler (1.0.22)
coffee-rails (3.2.2)
coffee-script (2.2.0)
coffee-script-source (1.3.3, 1.2.0)
erubis (2.7.0)
execjs (1.4.0, 1.3.2, 1.3.0)
hashie (1.2.0)
hike (1.2.1)
i18n (0.6.0)
io-console (0.3)
journey (1.0.3, 1.0.2)
jquery-rails (2.0.2)
json (1.7.3, 1.5.4)
mail (2.4.4, 2.4.1)
mime-types (1.18, 1.17.2)
minitest (2.5.1)
multi_json (1.3.6, 1.3.5, 1.1.0)
oauth (0.4.6)
omniauth (1.1.0)
omniauth-identity (1.0.0)
omniauth-oauth (1.0.1)
omniauth-twitter (0.0.11)
pg (0.13.2 x86-mingw32, 0.13.1 x86-mingw32)
polyglot (0.3.3)
rack (1.4.1)
rack-cache (1.2, 1.1)
rack-ssl (1.3.2)
rack-test (0.6.1)
rails (3.2.1)
rails-api (0.0.1)
railties (3.2.1)
rake (0.9.2.2)
rb-readline (0.4.2)
rdoc (3.12, 3.9.4)
rubyzip (0.9.6.1)
sass (3.1.19, 3.1.18)
sass-rails (3.2.5)
sprockets (2.1.3, 2.1.2)
sqlite3 (1.3.6 x86-mingw32, 1.3.5 x86-mingw32)
sqlite3-ruby (1.3.3)
thor (0.14.6)
tilt (1.3.3)
tiny_tds (0.5.1 x86-mingw32)
treetop (1.4.10)
tzinfo (0.3.33, 0.3.31)
uglifier (1.2.4)

The 3.2.5 versions of ActiveXXX were installed with the rails-api gem.

I am happy to provide any additional info that would be useful.

Capistrano "No such file or directory" warnings

I am using Capistrano for deployment. I am using a relatively standard Capistrano configuration and since rails-api removes some standard Rails directories, I am getting notices that they don't exist. The directories that it's mentioning are the public/images, public/stylesheets, public/javascripts directories. Here's the command that causes these warnings:

* executing "find /web/vhosts/dev.api.example.com/releases/20120510184852/public/images /web/vhosts/dev.api.example.com/releases/20120510184852/public/stylesheets /web/vhosts/dev.api.example.com/releases/20120510184852/public/javascripts -exec touch -t 201205101848.54 {} ';'; true"

Is this something that should be configured as part of my deploy.rb script?

rails-api application.rb throwing error on "rails s" command

melih:api monvural$ rails s
/opt/local/lib/ruby/gems/1.8/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251:in `require': /opt/local/lib/ruby/gems/1.8/gems/rails-api-0.0.3/lib/rails-api/application.rb:51: odd number list for Hash (SyntaxError)
metastore: "rails:/",
^
/opt/local/lib/ruby/gems/1.8/gems/rails-api-0.0.3/lib/rails-api/application.rb:51: syntax error, unexpected ':', expecting '}'
metastore: "rails:/",
^
/opt/local/lib/ruby/gems/1.8/gems/rails-api-0.0.3/lib/rails-api/application.rb:51: syntax error, unexpected ',', expecting kEND
/opt/local/lib/ruby/gems/1.8/gems/rails-api-0.0.3/lib/rails-api/application.rb:52: syntax error, unexpected ',', expecting kEND
/opt/local/lib/ruby/gems/1.8/gems/rails-api-0.0.3/lib/rails-api/application.rb:164: syntax error, unexpected $end, expecting kEND

API Versioning

I'm not sure if it's within the scope of this project, but versioning is an important component of a good API design. Have you seen Versionist? It does a pretty good job of allowing the version to be specified in the Accept header, path, or param. The problems that Versionist and Rails::API solve are complimentary and it may be beneficial to integrate some versioning best practices into this gem or at least lay the groundwork to make it easier to version the API for your app's specific needs.

Add ActionController::MimeResponds by default?

I'm curious to know what the rational of leaving this middleware out. It makes writing API code much easier. If the middleware does enable other mimetypes is it possible to get this changed for Rails 4.0 so that happens outside of this middleware?

uninitialized constant Rails::ApiApplication

The README states for existing apps to change the Application class to inherit from Rails::ApiApplication instead of Rails::Application, but this results in the above error. It looks like that section of the README should just be deleted. I'd be happy to issue a PR if that's the case.

FYI: Use NewRelic in rails-api based app

I needed this code to enable newrelic web transaction tracking.
It's not rails-api issue though.

class ActionController::API
  include NewRelic::Agent::Instrumentation::ControllerInstrumentation
  include NewRelic::Agent::Instrumentation::Rails3::ActionController
end

Draper doesn't like ActionController::API

$ rails console
/Users/krainboltgreene/.rvm/gems/ruby-1.9.3-p194@manacurve-api/gems/draper-0.14.0/lib/draper/railtie.rb:51:in `block in <class:Railtie>': undefined method `set_current_view_context' for #<ApplicationController:0x007f9cdd7931b0> (NoMethodError)
    from /Users/krainboltgreene/.rvm/gems/ruby-1.9.3-p194@manacurve-api/gems/railties-3.2.3/lib/rails/railtie.rb:179:in `call'
    from /Users/krainboltgreene/.rvm/gems/ruby-1.9.3-p194@manacurve-api/gems/railties-3.2.3/lib/rails/railtie.rb:179:in `block in load_console'
    from /Users/krainboltgreene/.rvm/gems/ruby-1.9.3-p194@manacurve-api/gems/railties-3.2.3/lib/rails/railtie.rb:179:in `each'
    from /Users/krainboltgreene/.rvm/gems/ruby-1.9.3-p194@manacurve-api/gems/railties-3.2.3/lib/rails/railtie.rb:179:in `load_console'
    from /Users/krainboltgreene/.rvm/gems/ruby-1.9.3-p194@manacurve-api/gems/railties-3.2.3/lib/rails/engine.rb:429:in `block in load_console'
    from /Users/krainboltgreene/.rvm/gems/ruby-1.9.3-p194@manacurve-api/gems/railties-3.2.3/lib/rails/application/railties.rb:8:in `each'
    from /Users/krainboltgreene/.rvm/gems/ruby-1.9.3-p194@manacurve-api/gems/railties-3.2.3/lib/rails/application/railties.rb:8:in `all'
    from /Users/krainboltgreene/.rvm/gems/ruby-1.9.3-p194@manacurve-api/gems/railties-3.2.3/lib/rails/engine.rb:429:in `load_console'
    from /Users/krainboltgreene/.rvm/gems/ruby-1.9.3-p194@manacurve-api/gems/railties-3.2.3/lib/rails/application.rb:153:in `load_console'
    from /Users/krainboltgreene/.rvm/gems/ruby-1.9.3-p194@manacurve-api/gems/railties-3.2.3/lib/rails/commands/console.rb:27:in `start'
    from /Users/krainboltgreene/.rvm/gems/ruby-1.9.3-p194@manacurve-api/gems/railties-3.2.3/lib/rails/commands/console.rb:8:in `start'
    from /Users/krainboltgreene/.rvm/gems/ruby-1.9.3-p194@manacurve-api/gems/railties-3.2.3/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

OData support

Are there any thoughts on making it a convention to use the OData format for API's built using the Rails-API gem?

I feel this will become increasingly important with the advent of JS libraries like BreezeJS (http://www.breezejs.com/) making it super easy to sync/cache data with a server.

I would love hear your thoughts on it.

NameError in production with Foreman + Unicorn

If I use thin and rails server in production, it's all fine. Also works fine with Foreman and Unicorn in development.

Here's the stack:

E, [2012-05-11T12:09:33.376805 #4581] ERROR -- : uninitialized constant ActionDispatch::SSL (NameError)
/Users/samsoffes/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/rails-api-0.0.1/lib/rails-api/application.rb:14:in `block in default_middleware_stack'
/Users/samsoffes/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/rails-api-0.0.1/lib/rails-api/application.rb:7:in `tap'
/Users/samsoffes/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/rails-api-0.0.1/lib/rails-api/application.rb:7:in `default_middleware_stack'
/Users/samsoffes/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/engine.rb:469:in `app'
/Users/samsoffes/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/application/finisher.rb:31:in `block in <module:Finisher>'
/Users/samsoffes/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/initializable.rb:30:in `instance_exec'
/Users/samsoffes/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/initializable.rb:30:in `run'
/Users/samsoffes/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/initializable.rb:55:in `block in run_initializers'
/Users/samsoffes/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/initializable.rb:54:in `each'
/Users/samsoffes/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/initializable.rb:54:in `run_initializers'
/Users/samsoffes/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/application.rb:136:in `initialize!'
/Users/samsoffes/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/railtie/configurable.rb:30:in `method_missing'
/Users/samsoffes/Code/redacted/config/environment.rb:5:in `<top (required)>'
config.ru:2:in `require'
config.ru:2:in `block in <main>'
/Users/samsoffes/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:51:in `instance_eval'
/Users/samsoffes/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:51:in `initialize'
config.ru:1:in `new'
config.ru:1:in `<main>'
/Users/samsoffes/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/unicorn-4.3.1/lib/unicorn.rb:44:in `eval'
/Users/samsoffes/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/unicorn-4.3.1/lib/unicorn.rb:44:in `block in builder'
/Users/samsoffes/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/unicorn-4.3.1/bin/unicorn_rails:139:in `call'
/Users/samsoffes/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/unicorn-4.3.1/bin/unicorn_rails:139:in `block in rails_builder'
/Users/samsoffes/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/unicorn-4.3.1/lib/unicorn/http_server.rb:696:in `call'
/Users/samsoffes/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/unicorn-4.3.1/lib/unicorn/http_server.rb:696:in `build_app!'
/Users/samsoffes/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/unicorn-4.3.1/lib/unicorn/http_server.rb:569:in `init_worker_process'
/Users/samsoffes/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/unicorn-4.3.1/lib/unicorn/http_server.rb:589:in `worker_loop'
/Users/samsoffes/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/unicorn-4.3.1/lib/unicorn/http_server.rb:487:in `spawn_missing_workers'
/Users/samsoffes/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/unicorn-4.3.1/lib/unicorn/http_server.rb:137:in `start'
/Users/samsoffes/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/unicorn-4.3.1/bin/unicorn_rails:209:in `<top (required)>'
/Users/samsoffes/.rbenv/versions/1.9.3-p125/bin/unicorn_rails:19:in `load'
/Users/samsoffes/.rbenv/versions/1.9.3-p125/bin/unicorn_rails:19:in `<main>'

ActionController::ParamsWrapper is not on by default

The generated config/initializers/wrap_parameters files says that ActionController::ParamsWrapper is enabled by default, but it is not.

Perhaps it should be enabled by default, because when consuming JSON requests its pretty nice to not require the root object. If that's not going to happen, the generator should be modified so that it states that this module is disabled by default.

Digest Authentication test fails using ActionController::API

I'm testing digest authentication using rails-api and it fails for me under ActionController::API but not under ActionController:Base.

I created a stripped down version of the app here: https://github.com/natebird/rails-digest-auth-example. You can run the test to see it fail with the following error:

test_a_POST_to_:digest_auth_with_proper_authentication(AuthControllerTest):
NameError: undefined method `process_with_new_base_test' for class `AuthController'
    /Users/me/app/test/test_helper.rb:22:in `instance_eval'
    /Users/me/app/test/test_helper.rb:22:in `instance_eval'
    /Users/me/app/test/test_helper.rb:22:in `authenticate_with_http_digest'
    /Users/me/app/test/test_helper.rb:9:in `setup_digest_auth'
    /Users/me/app/test/functional/auth_controller_test.rb:5:in `block in <class:AuthControllerTest>'

If you change application_controller to inherit from ActionController::Base it will pass. The readme contains more information about the sample app and the key additions. The error is related to authenticate_with_http_digest method in the test_helper.rb.

Am I forgetting to include something in the application_controller that would enable this to pass or am I just going about this all wrong? :-)

Having trouble creating mailers

Hello,

I'm not sure if this is a configuration issue on my part or if I'm missing some middleware, but I am having trouble getting mailers set up in my Rails API project. I used the rails-api new command to generate a new rails app. I don't have a lot of experience with Rails so it could be user error, but I wanted to check and see if you knew if you removed something that mailers depend on.

This is the error that I'm getting:

ActionView::MissingTemplate (Missing template network_mailer/private_message with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder]}. Searched in:
  * "/usr/local/rvm/gems/ruby-1.9.2-p320/gems/kaminari-0.13.0/app/views"
):
  app/mailers/network_mailer.rb:115:in `block in private_message'
  app/mailers/network_mailer.rb:114:in `private_message'
  app/controllers/network/email_templates_controller.rb:4:in `create'

Using rails-api as an isolated engine

Using rails-api as an isolated engine and mounting it in a normal rails application I'm getting this error

wrong argument type Module (expected Class)

with this code

module Api
  class ApplicationController < ActionController::API
  end
end

And the trace gives me this:

app/controllers/api/application_controller.rb:2:in `<module:Api>'

Somehow it seems like it expects the wrapping module to be a class. However switching to ActionController::Base solves it. Any idea why? Maybe I'm missing some controller module that's needed for that to work?

Thanks!

"already initialized constant JSON" with Rails 4.0.0.beta

Hi

I've been playing with a test app using Rails 4.0.0 (rails/rails@153f0cb2b24a).

I've added rails-api to the mix and I get a warning : "already initialized constant JSON"

Here is my Gemfile :

source 'https://rubygems.org'

gem 'rails',     :github => 'rails/rails'
gem 'journey',   :github => 'rails/journey'
gem 'arel',      :github => 'rails/arel'
gem 'activerecord-deprecated_finders', :github => 'rails/activerecord-deprecated_finders'

gem "active_model_serializers", :github => "rails-api/active_model_serializers"

gem 'mysql2', '~> 0.3.11'

gem 'rails-api'

group :development do
  gem 'g'
  gem 'ruby_gntp'
  gem 'awesome_print', :require => 'ap'
  gem 'pry'
  gem 'pry-rails'
end

gem 'multi_json'
gem 'yajl-ruby', :require => 'yajl'

and my Gemfile.lock :


GIT
  remote: git://github.com/rails-api/active_model_serializers.git
  revision: 6780cd3df5b14d85a7fd032af961853a9eb7c2cf
  specs:
    active_model_serializers (0.5.2)
      activemodel (>= 3.0)

GIT
  remote: git://github.com/rails/activerecord-deprecated_finders.git
  revision: 2125c7b4f959c1aa025f61bdfb5f95b5d6a52b51
  specs:
    activerecord-deprecated_finders (0.0.1)

GIT
  remote: git://github.com/rails/arel.git
  revision: 38d0a222e275d917a2c1d093b24457bafb600a00
  specs:
    arel (3.0.2.20120819075748)

GIT
  remote: git://github.com/rails/journey.git
  revision: e64274443f8420df2518cf2206a2c640d9d8e196
  specs:
    journey (2.0.0.20120723141804)

GIT
  remote: git://github.com/rails/rails.git
  revision: 153f0cb2b24ae72a22e3bfbd26e77f66be290831
  specs:
    actionmailer (4.0.0.beta)
      actionpack (= 4.0.0.beta)
      mail (~> 2.5.3)
    actionpack (4.0.0.beta)
      activesupport (= 4.0.0.beta)
      builder (~> 3.1.0)
      erubis (~> 2.7.0)
      journey (~> 2.0.0)
      rack (~> 1.4.1)
      rack-test (~> 0.6.1)
    activemodel (4.0.0.beta)
      activesupport (= 4.0.0.beta)
      builder (~> 3.1.0)
    activerecord (4.0.0.beta)
      activemodel (= 4.0.0.beta)
      activerecord-deprecated_finders (= 0.0.1)
      activesupport (= 4.0.0.beta)
      arel (~> 3.0.2)
    activesupport (4.0.0.beta)
      i18n (~> 0.6)
      minitest (~> 4.1)
      multi_json (~> 1.3)
      thread_safe (~> 0.1)
      tzinfo (~> 0.3.33)
    rails (4.0.0.beta)
      actionmailer (= 4.0.0.beta)
      actionpack (= 4.0.0.beta)
      activerecord (= 4.0.0.beta)
      activesupport (= 4.0.0.beta)
      bundler (>= 1.2.2, < 2.0)
      railties (= 4.0.0.beta)
      sprockets-rails (~> 2.0.0.rc1)
    railties (4.0.0.beta)
      actionpack (= 4.0.0.beta)
      activesupport (= 4.0.0.beta)
      rake (>= 0.8.7)
      rdoc (~> 3.4)
      thor (>= 0.15.4, < 2.0)

GEM
  remote: https://rubygems.org/
  specs:
    atomic (1.0.1)
    awesome_print (1.1.0)
    builder (3.1.4)
    coderay (1.0.8)
    erubis (2.7.0)
    g (1.7.1)
    hike (1.2.1)
    i18n (0.6.1)
    json (1.7.5)
    mail (2.5.3)
      i18n (>= 0.4.0)
      mime-types (~> 1.16)
      treetop (~> 1.4.8)
    method_source (0.8.1)
    mime-types (1.19)
    minitest (4.3.3)
    multi_json (1.5.0)
    mysql2 (0.3.11)
    polyglot (0.3.3)
    pry (0.9.10)
      coderay (~> 1.0.5)
      method_source (~> 0.8)
      slop (~> 3.3.1)
    pry-rails (0.2.2)
      pry (>= 0.9.10)
    rack (1.4.1)
    rack-test (0.6.2)
      rack (>= 1.0)
    rails-api (0.0.3)
      actionpack (>= 3.2.6)
      railties (>= 3.2.6)
      tzinfo (~> 0.3.31)
    rake (10.0.3)
    rdoc (3.12)
      json (~> 1.4)
    ruby_gntp (0.3.4)
    slop (3.3.3)
    sprockets (2.8.2)
      hike (~> 1.2)
      multi_json (~> 1.0)
      rack (~> 1.0)
      tilt (~> 1.1, != 1.3.0)
    sprockets-rails (2.0.0.rc1)
      actionpack (>= 3.0)
      activesupport (>= 3.0)
      sprockets (~> 2.8)
    thor (0.16.0)
    thread_safe (0.1.0)
      atomic
    tilt (1.3.3)
    treetop (1.4.12)
      polyglot
      polyglot (>= 0.3.1)
    tzinfo (0.3.35)
    yajl-ruby (1.1.0)

PLATFORMS
  ruby

DEPENDENCIES
  active_model_serializers!
  activerecord-deprecated_finders!
  arel!
  awesome_print
  g
  journey!
  multi_json
  mysql2 (~> 0.3.11)
  pry
  pry-rails
  rails!
  rails-api
  ruby_gntp
  yajl-ruby

It's definitely no big deal, but I wanted to let you know.

secret_key_base not defined

A new rails4 API app raises an error because secret_key_base is not defined.

I've taken a look at the rails code and it seems that secret_key_base or the deprecated secret_token must be defined (correct me if I'm wrong).

Rails-api doesn't define either of them. I'm not sure if it should for an api-only app.

So, should one of those config values be defined in the app skeleton? Or should rails-api try to ignore them for an api-only app?

Another Devise error

Happens only in rails s —environment=production.

undefined local variable or method mimes_for_respond_to' for DeviseController:Class (NameError)`

full trace:

/Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/devise-2.1.0/app/controllers/devise_controller.rb:13:in `<class:DeviseController>': undefined local variable or method `mimes_for_respond_to' for DeviseController:Class (NameError)
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/devise-2.1.0/app/controllers/devise_controller.rb:2:in `<top (required)>'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `require'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `block in require'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `require'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:359:in `require_or_load'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:502:in `load_missing_constant'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:192:in `block in const_missing'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:190:in `each'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:190:in `const_missing'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/devise-2.1.0/app/controllers/devise/confirmations_controller.rb:1:in `<top (required)>'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `require'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `block in require'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `require'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:359:in `require_or_load'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:313:in `depend_on'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:225:in `require_dependency'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/engine.rb:439:in `block (2 levels) in eager_load!'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/engine.rb:438:in `each'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/engine.rb:438:in `block in eager_load!'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/engine.rb:436:in `each'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/engine.rb:436:in `eager_load!'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/application/railties.rb:8:in `each'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/application/railties.rb:8:in `all'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/engine.rb:434:in `eager_load!'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/application/finisher.rb:53:in `block in <module:Finisher>'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/initializable.rb:30:in `instance_exec'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/initializable.rb:30:in `run'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/initializable.rb:54:in `each'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/initializable.rb:54:in `run_initializers'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/application.rb:136:in `initialize!'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /Users/paul/Development/rails/ostio/config/environment.rb:5:in `<top (required)>'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `require'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `block in require'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `require'
    from /Users/paul/Development/rails/ostio/config.ru:4:in `block in <main>'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:51:in `instance_eval'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:51:in `initialize'
    from /Users/paul/Development/rails/ostio/config.ru:1:in `new'
    from /Users/paul/Development/rails/ostio/config.ru:1:in `<main>'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:40:in `eval'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:40:in `parse_file'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:200:in `app'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/commands/server.rb:46:in `app'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:301:in `wrapped_app'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:252:in `start'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/commands/server.rb:70:in `start'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/commands.rb:55:in `block in <top (required)>'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/commands.rb:50:in `tap'
    from /Users/paul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/commands.rb:50:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

Caching issue

What do I need to add back in to get caches_page and cache_sweeper working in a controller? The error I'm receiving is:

ActionController::RoutingError (undefined method `caches_page' for WidgetsController:Class)

My controller looks like this:

class WidgetsController < ApplicationController

  caches_page :index, :show
  before_filter(only: [:index, :show]) { @page_caching = true }
  cache_sweeper :widget_sweeper

  # actions omitted

end

I'm using memcached and the dalli gem for the cache_store and session_store, which is working beautifully in a regular ActionController::Base project.

remove :new and :edit from default actions in router

Would it be possible to remove :new and :edit from default actions when declaring routes?

For now I have resources :users, :except => [:new, :edit] all over my router.

I tried to wrap in scope :except => [:new, :edit] but it is not very flexible.

Use with only a subset of controllers?

My API is contained within a larger Rails app. They all inherit from a common parent class, so I can easily change them to use ActionController::API, however I'm unsure what to do about the Rails::ApiApplication setup step?

Cheers

Add ActionController::API to any desired controllers

Why I cannot add ActionController::API to any controller?

Here an example:

# /app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
   # normal rails code with all middleware stack
end

# /app/controllers/public_area/api_controller.rb
class PublicArea::ApiController < ActionController::API
   # only required middleware stack
end

I get a Template missing error on the root route localhost:3000. My root route is application#index. If I remove this gem and the ActionController::API from the app all works fine.

Can we still use the asset pipeline?

I want to use ember.js with rails and rails-api looks promising for this. All my views will be rendered with ember and aren't needed in rails. I threw your gem in my app and the asset pipeline isn't being compiled anymore; it is still enabled in my application.rb though.

Is there a way to still use the asset pipeline with this gem?

missing helper_method

when i try to integrate rails-api with devise, it show an error like this

/Users/bobbyadiprabowo/.rvm/gems/ruby-1.9.2-p180@kulinr-rails-api/gems/devise-2.0.4/lib/devise/controllers/helpers.rb:8:in block in <module:Helpers>': undefined methodhelper_method' for ActionController::API:Class (NoMethodError)

maybe helper_method is not included in ActionController::API:Class

disabled asset_host?

What would one have to do in order to use (development.rb):
config.action_controller.asset_host

I am not really using assets but it would be nice to use image_tag which should normally use config.action_controller.asset_host, but I believe this gem disables it somehow.

Any ideas?

Edge rails breaks

When running rails s:

Users/steve/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-5cb2edce7fb1/railties/lib/rails/railtie/configuration.rb:95:in `method_missing': undefined method `allow_concurrency' for #<Rails::Application::Configuration:0x007fcecb166240> (NoMethodError)
    from /Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/rails-api-0.0.2/lib/rails-api/application.rb:25:in `block in default_middleware_stack'
    from /Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/rails-api-0.0.2/lib/rails-api/application.rb:7:in `tap'
    from /Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/rails-api-0.0.2/lib/rails-api/application.rb:7:in `default_middleware_stack'
    from /Users/steve/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-5cb2edce7fb1/railties/lib/rails/engine.rb:489:in `app'
    from /Users/steve/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-5cb2edce7fb1/railties/lib/rails/application/finisher.rb:33:in `block in <module:Finisher>'
    from /Users/steve/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-5cb2edce7fb1/railties/lib/rails/initializable.rb:30:in `instance_exec'
    from /Users/steve/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-5cb2edce7fb1/railties/lib/rails/initializable.rb:30:in `run'
    from /Users/steve/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-5cb2edce7fb1/railties/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /Users/steve/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/tsort.rb:150:in `block in tsort_each'
    from /Users/steve/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component'
    from /Users/steve/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/tsort.rb:219:in `each_strongly_connected_component_from'
    from /Users/steve/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/tsort.rb:182:in `block in each_strongly_connected_component'
    from /Users/steve/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/tsort.rb:180:in `each'
    from /Users/steve/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/tsort.rb:180:in `each_strongly_connected_component'
    from /Users/steve/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/tsort.rb:148:in `tsort_each'
    from /Users/steve/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-5cb2edce7fb1/railties/lib/rails/initializable.rb:54:in `run_initializers'
    from /Users/steve/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-5cb2edce7fb1/railties/lib/rails/application.rb:185:in `initialize!'
    from /Users/steve/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-5cb2edce7fb1/railties/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /Users/steve/src/get_a_job/config/environment.rb:5:in `<top (required)>'
    from /Users/steve/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-5cb2edce7fb1/activesupport/lib/active_support/dependencies.rb:227:in `require'
    from /Users/steve/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-5cb2edce7fb1/activesupport/lib/active_support/dependencies.rb:227:in `block in require'
    from /Users/steve/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-5cb2edce7fb1/activesupport/lib/active_support/dependencies.rb:212:in `load_dependency'
    from /Users/steve/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-5cb2edce7fb1/activesupport/lib/active_support/dependencies.rb:227:in `require'
    from /Users/steve/src/get_a_job/config.ru:4:in `block in <main>'
    from /Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/builder.rb:51:in `instance_eval'
    from /Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/builder.rb:51:in `initialize'
    from /Users/steve/src/get_a_job/config.ru:1:in `new'
    from /Users/steve/src/get_a_job/config.ru:1:in `<main>'
    from /Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/builder.rb:40:in `eval'
    from /Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/builder.rb:40:in `parse_file'
    from /Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/server.rb:200:in `app'
    from /Users/steve/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-5cb2edce7fb1/railties/lib/rails/commands/server.rb:46:in `app'
    from /Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/server.rb:301:in `wrapped_app'
    from /Users/steve/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-5cb2edce7fb1/railties/lib/rails/commands/server.rb:71:in `start'
    from /Users/steve/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-5cb2edce7fb1/railties/lib/rails/commands.rb:85:in `block in <top (required)>'
    from /Users/steve/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-5cb2edce7fb1/railties/lib/rails/commands.rb:80:in `tap'
    from /Users/steve/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-5cb2edce7fb1/railties/lib/rails/commands.rb:80:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

Remove unrelated folders

Hello there,

I just would like to know whether we should not have the following folders/files:

$ rails-api new tests-rails-api
      create  
      ...
      create  lib/tasks/.gitkeep
>>>>> create  lib/assets
>>>>> create  lib/assets/.gitkeep
      create  log
      create  log/.gitkeep
>>>>> create  public
>>>>> create  public/404.html
>>>>> create  public/422.html
>>>>> create  public/500.html
>>>>> create  public/favicon.ico
>>>>> create  public/index.html
>>>>> create  public/robots.txt
      create  script
      ...
         run  bundle install

I don't thing we still need to keep assets and statics files when building APIs, don't you?

Improved default serializer class lookup

It would be a nice addition if the default serializer determined by the controller would be looked up using some kind of convention, for example by scoping first the serializer class using the controller scope. This way you could have different serializers for different API versions.

Example:

For the controller app/controllers/api/v1/posts_controller.rb:

class Api::V1::PostsController < ActionController::API
end

It would be really nice if, by default, tried to use: app/serializers/api/v1/post_serializer.rb instead of app/serializers/post_serializer.rb and then, in case of missing constant, fallback to the actual implementation.

Rails 4

Is there or will there be a rails4 branch that keeps up with the latest changes towards rails4?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.