Coder Social home page Coder Social logo

Comments (4)

niedhui avatar niedhui commented on September 23, 2024

@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.

mrrooijen avatar mrrooijen commented on September 23, 2024

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.

mrrooijen avatar mrrooijen commented on September 23, 2024

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.

fabrik42 avatar fabrik42 commented on September 23, 2024

Glad you found the problem, thanks for the follow up!

from acts_as_api.

Related Issues (20)

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.