我已经采用了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
end
RABL模板:
object @user
attributes :first_name
答案 0 :(得分:0)
尝试包括:
include ActionController::ImplicitRender
我已经使用rails 4.0.4和ruby 2.1.0
测试了它答案 1 :(得分:0)
这是在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
随意添加适合您口味的模块。