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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:14:13+00:00 2026-05-28T14:14:13+00:00

In my controller I have: @pakkes = Pakke.where(navn like ?, %#{params[:q]}%) respond_to do |format|

  • 0

In my controller I have:

@pakkes = Pakke.where("navn like ?", "%#{params[:q]}%")

respond_to do |format|
  format.html # index.html.erb
  format.xml  { render :xml => @pakkes }
  format.json { render :json => @pakkes.map(&:attributes) }
end

How do I change the attribute navn to name when rendering JSON?

  • 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-28T14:14:14+00:00Added an answer on May 28, 2026 at 2:14 pm

    You can do this with a one-line method in Pakke:

    def as_json(*args)
        super.tap { |hash| hash["name"] = hash.delete "navn" }
    end
    

    Calling super will generate json hash as usual, then before it’s returned you’ll swoop in and change the key of the “navn” entry.

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

Sidebar

Related Questions

In my controller I have some methods which return json as well as xml
In my controller I have: def search @kategoris = Kampagner.where(titel like ?, %#{params[:q]}%) @kate
I have controller method: def do_it @result = some <b>another</b> respond_to do | format
I have controller with a page named list.html.erb when a user clicks a link
In my Rails controller I have something like: def authenticate_user! if not current_user #
I have a manageUser page, the route is like that: map.manageUsers manageUsers, :controller =>
I have a spring controller (MyController) which servers data as json. With a few
I have controller action. It's called via ajax request. Action should return json object.
i have a usercenter/users_controller,in this controller have code like belows def login end def
I have a view controller which is assigned as a rootViewController like below :

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.