Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6948997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:53:48+00:00 2026-05-27T13:53:48+00:00

I currently have this method in a controller: def show property = Property.find(params[:id]) respond_to

  • 0

I currently have this method in a controller:

def show
  property = Property.find(params[:id])
  respond_to do |format|
    format.xml { render :xml => property.to_xml(:except => [:address1, :address2, :analysis_date, :analysis_date_2, ...]) }
    format.json { render :json => property.to_json(:except => [:address1, :address2, :analysis_date, :analysis_date_2, ...]) }
  end
end

It seems like I can refactor this code to use respond_with, but I am not sure how to customize the output. Do I need to override the as_json and to_xml methods in order to customize the returned data? If I override these methods, will property associations still be handled correctly? For example, a property has many tenants and many contractors. I may need to return those elements as well.

I would assume the controller method could then be simplified to this.

def show
  property = Property.find(params[:id])
  respond_with(property)
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:53:48+00:00Added an answer on May 27, 2026 at 1:53 pm

    The respond_with method takes two arguments: the resources*and a &block so you should be able to do this:

    def show
      property = Property.find(params[:id])
      respond_with(property, :except => [:address1, 
                                         :address2, 
                                         :analysis_date, 
                                         :analysis_date_2, 
                                         ...])
    end
    

    And just remember, that in order to us respond_with properly you need to add respond_to :html, :json, :xml in the top of your controller. So that respond_withknows what mimes to respond to.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my kategori controller show action: def show @kategori = Kategori.find(params[:id]) @konkurrancer =
Currently i have this method: static boolean checkDecimalPlaces(double d, int decimalPlaces){ if (d==0) return
I currently have this working but it requires me to have a static method
I have this command that I run every 24 hours currently. find /var/www/html/audio -daystart
I would like to show the state from the skill controller with this method
Paramiko's SFTPClient apparently does not have an exists method. This is my current implementation:
I do not currently have this issue , but you never know, and thought
How would I create a nested list, I currently have this public function getNav($cat,$subcat){
Currently i have this: $(.splitCol).click(function () { $.cookie('whichColumn', 'split'); $(.threeCol .active).removeClass(active); $(.leftCol .active).removeClass(active); $(.splitCol
Note: I'm using Google Chrome Currently I have this test page http://www.evecakes.com/doodles/canvas_size_issue.htm It should

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.