Closed ethicalhack3r closed 10 years ago
I haven't really tried the gem against Rails 4.1 but it seems they have changed some internals rendering. Can you provide the template and the controller as well so I can look into it?
Thank you for reporting this.
My API code is based on this tutorial found here - http://railsware.com/blog/2013/04/08/api-with-ruby-on-rails-useful-tricks/
Here is my base controller:
# http://railsware.com/blog/2013/04/08/api-with-ruby-on-rails-useful-tricks/
class Api::V1::BaseController < ActionController::Metal
include ActionController::Rendering # enables rendering
include ActionController::MimeResponds # enables serving different content types like :xml or :json
include AbstractController::Callbacks # callbacks for your authentication logic
include ActionController::ImplicitRender # https://github.com/rails-api/rails-api/issues/93
include AbstractController::Rendering # for append_view_path Rails > 4.1
append_view_path "#{Rails.root}/app/views" # you have to specify your views location as well
before_filter :set_content_type, :set_cors_headers
private
def set_content_type
headers['Content-Type'] = 'application/json'
end
def set_cors_headers
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Methods'] = 'GET'
headers['Access-Control-Request-Method'] = 'GET'
headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept'
end
end
An API end-point controller which uses the base controller above (also tested without the friendly_id gem):
class Api::V1::PluginsController < Api::V1::BaseController
def show
@plugin = Plugin.friendly.find(params[:id])
end
end
And the view (show.rabl):
object @plugin
attribute :name => :name
attribute :public_id => :id
attributes :title, :created_at, :source
child :vulnerabilities do
attributes :id, :title
attribute :osvdb, :unless => lambda { |m| m.osvdb.blank? }
attribute :secunia, :unless => lambda { |m| m.secunia.blank? }
attribute :cve, :unless => lambda { |m| m.cve.blank? }
attribute :references, :unless => lambda { |m| m.references.blank? }
attribute :fixed_in, :unless => lambda { |m| m.fixed_in.blank? }
end
It seems that if I change ActionController::Metal
to ActionController::Base
in the base controller, my specs pass without error. Doesn't seem to be caused by this gem, instead looks like I may need to include another AbstractController
and/or ActionController
class which ActionController::Metal
doesn't include anymore in version 4.1.
@ethicalhack3r : Did you figure out what needs to be included in the ActionController::Metal?
I am facing the same issue. Followed the same tutorial.
I am building my app on Rails 4.1.6
@alankrit in the end I ended up including so many components I just ended up going back to using ActionController::Base
So my first line of my controller looks like:
class Api::V1::BaseController < ActionController::Base
Has anyone tried running rabl-rails 0.9.3 with Rails 4.1?
Since upgrading to Rails 4.1 any specs that have RABL templates are failing with the following error:
Full Stack Trace:
My hunch is that this error is due to rabl-rails not supporting Rails 4.1 yet? I could be wrong and the error might be related to something else, thought I'd see if anyone else here had encountered this error with rabl-rails and Rails 4.1.