Comments (4)
@meskyanichi can you show us the code of lib/ext/acts_as_api/responder.rb ? I run the spec with ruby 2.0 , and did not got the error. and the spec have tested the following action
def index_no_root_no_order
@users = User.all
respond_with @users, :api_template => params[:api_template].to_sym
end
from acts_as_api.
Sure. Sorry I didn't realize it came from my extension. Here's the code:
# -*- encoding : utf-8 -*-
module App::Ext::ActsAsApi::Responder
# Override the #to_html method of the ActsAsApi::Responder
# since we always want to render the layouts/blank when a
# HTML response needs to be made.
def to_html
render "layouts/blank"
end
end
ActsAsApi::Responder.send(:include, App::Ext::ActsAsApi::Responder)
A little background on this extension. I am overriding the to_html method in the ActsAsApi responder since when a HTML request comes in, I always want to render a blank view (a view without any content) so it renders the html layout. The application itself is a single-page application (using a javascript framework with PushState). When a request comes in at for example http://domain.com/some/path
then I basically want Rails to just render the layout without a view, because the layout always contains everything I need, and the view is unnecessary. I wasn't sure how to get that done with ActsAsApi so I simply overwrote the to_html
method to render a blank view to get the same result.
Do you know of a way to render the layout but without the action's view? If not, do you have any idea how I could get the desired result in Ruby 2.0 as I am now like this in Ruby 1.9?
Thanks!
from acts_as_api.
Scratch that. Turns out I could simply do this:
def to_html
render :nothing => true, :layout => true
end
Didn't know you could combine :nothing => true
with :layout => true
. Works though!
from acts_as_api.
Glad you found the problem, thanks for the follow up!
from acts_as_api.
Related Issues (20)
- Rails 5: undefined method `as_api_response' for ActiveRecord_Associations_CollectionProxy HOT 18
- NoMethodError render_for_api with rails 5 api app HOT 7
- DEPRECATION WARNING: Initialization autoloaded the constants ActionText::ContentHelper and ActionText::TagHelper.
- Dynamic template name in extend is not supported. HOT 1
- No options found for Remove functionality. not supporting if condition HOT 1
- InvalidURIError while deploying to heroku
- Rails 3 Responder: undefined method `list_url' HOT 1
- Ruby 2.0, Rails Mongoid, and NoMethodError (undefined method `empty?' for nil:NilClass) HOT 1
- Active Model support HOT 1
- Using class methods in api_accessible definition HOT 1
- Json with all Root nodes HOT 4
- new feature HOT 4
- respond_with not working with after_filter HOT 3
- Does not use model_name when using this without ORM HOT 3
- Parent Name under association HOT 3
- can't modify frozen Hash representing deleted AR objects HOT 1
- DateTime objects are truncating milliseconds HOT 5
- introduction: confuse links
- can i have json without root element? HOT 8
- Completely custom Json output HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from acts_as_api.