我使用了类似于basis的post,但每次都收到空响应。怎么了?
基本控制器:
class Api::V1::BaseController < ActionController::Metal
include AbstractController::Rendering
include AbstractController::Callbacks
include AbstractController::Helpers
include ActionController::HttpAuthentication::Token::ControllerMethods
include ActionController::Rendering
include ActionController::Renderers::All
include ActionController::MimeResponds
include ActionController::Instrumentation
append_view_path "#{Rails.root}/app/views"
respond_to :json
end控制器:
class Api::V1::UsersController < Api::V1::BaseController
def index
@user = User.find(params[:id])
end
endRABL模板:
object @user
attributes :first_name发布于 2014-08-12 16:38:48
尝试包含以下内容:
include ActionController::ImplicitRender我已经使用rails 4.0.4和ruby 2.1.0对其进行了测试
发布于 2014-12-25 08:21:25
这是适用于我在Rails 4.1.8中的最小设置
class Api::V1::BaseController < ActionController::Metal
include AbstractController::Rendering # Basic rendering
include ActionView::Rendering # Finds view using lookup_context and append_view_path
include ActionController::Rendering # Support respond_to and render formats
include ActionController::MimeResponds # MIME type for respond_to
include ActionController::ImplicitRender # Implicitly calls render so you don't
include ActionController::Instrumentation # Sets Content-Type header amongst others
append_view_path "#{Rails.root}/app/views" # Get views from here
end您可以根据自己的喜好添加模块。
https://stackoverflow.com/questions/24854701
复制相似问题