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 8153679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:06:06+00:00 2026-06-06T16:06:06+00:00

in one of my controller actions, I am assigning a project to a user,

  • 0

in one of my controller actions, I am assigning a project to a user, and I want to respond to json requests to it with some info about the user and some info about the project. I can, at the moment, see all of their database attributes like this:

    # ruby code...
    # current_user.first_name #=> "Nik" db attr
    # current_user.full       #=> "Nik So" virtual attr
    # @project.name           #=> "buy something"

    format.json { render json: {user:current_user), assignable:@project}}

So in my firebug console, I can see the response object in my console

    // JS code
    success: function(r){window.test = r}

    //in console
    test.user.first_name //"Nik"
    test.assignable.name //"buy something"
    test.user.full       //undefined

Any chance that I can return virtual attributes alongside my models in the JSON response?

Thank You!

  • 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-06-06T16:06:07+00:00Added an answer on June 6, 2026 at 4:06 pm

    Got it!, here’s a solution:

            format.json { render json: {user:current_user.as_json(methods:[:full]), assignable:@project}}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In one of my controller actions, I'm generating some XML. One of the attributes
On my project I have only one controller so I want to do this:
some of my controller actions require a user to be authenticated. Those actions are
One of my controller actions returns a file to the user. I would like
I have some situations where I want to be sure that one controller action
In django, can I have 2 controller actions with the same name, but one
how can i render multiple different actions in one call to a speccific controller?
How can one best test a controller action which receives a file upload using
Can a ASP .NET Controller action method take an interface as one of the
I'm trying to use F# for an ASP.NET MVC application. One my controller actions

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.