Giter Site home page Giter Site logo

Comments (7)

josevalim avatar josevalim commented on May 21, 2024

There is no way to pass serialization options, but you don't need to overwrite your whole action, just the required pieces.

And if you have always to pass the same options, you should also consider overwriting your models or creating your own responder.

from inherited_resources.

mrroach avatar mrroach commented on May 21, 2024

It's not always the same options, the options depend on parameters passed in by the user. I'm assuming that by overwriting "the required pieces" you mean like this:

def index
  index! do |format|
    format.xml { render :xml => collection.to_xml(to_xml_parameters) }
  end
end

Is that correct? It kind of sucks to have to repeat myself in all my controllers that way; perhaps a responder is a better choice...

The stuff under legacy hurts my brain :-). Do I need to create an ActionController::Responder or an ActionController::MimeResponds::Responder?

from inherited_resources.

josevalim avatar josevalim commented on May 21, 2024

If you need to add the same line in all controllers, you can put the logic in a module and include the module in your controllers:

module ToXmlParameters
def index
index! do |format|
format.xml { render :xml => collection.to_xml(to_xml_parameters) }
end
end

def to_xml_parameters
  # implement your logic here
end

end

And include this module in your controllers. If you want to go the responders road, I would suggest you to inherit from InheritedResources::Responder and add the logic you want. The ActionController::Responder is the one what you should look to know what to overwrite though.

When you are done, do:

InheritedResources::Base.responder = YourResponder

from inherited_resources.

mrroach avatar mrroach commented on May 21, 2024

Thanks for your help. I think the responder route is going to work well for me

from inherited_resources.

jpshackelford avatar jpshackelford commented on May 21, 2024

I too am finding that I am doing--or am about to do--the following in many controllers.

def index 
  index! do |format|
    format.xml{  render :xml  => collection.to_xml(  render_options ) }
    format.json{ render :json => collection.to_json( render_options ) }        
  end
end

def show
  show! do |format|
    format.xml{ render :xml  => resource.to_xml(  render_options ) }
    format.xml{ render :json => resource.to_json( render_options ) }
  end
end

mrroach, how did your Respondor solution work out? Care to share a snippet? Jose, these seems a fairly typical scenario. Would you accept a patch to do something about this in inherited_resources itself?

from inherited_resources.

josevalim avatar josevalim commented on May 21, 2024

The customization does not belong to Inherited Resources. It should be at the Responders level. Take a look at responders documentation and blog posts available. :)

from inherited_resources.

jpshackelford avatar jpshackelford commented on May 21, 2024

Jose,

I have attempted this at https://github.com/jpshackelford/resource_inclusion . I'll be interested in your feedback.

John-Mason

from inherited_resources.

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.