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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:00:04+00:00 2026-05-17T22:00:04+00:00

In my controller, I’m building a json object for books. I want to show

  • 0

In my controller, I’m building a json object for books. I want to show truncate(book.content, 250).

This doesn’t work in a rails controller. And given it’s a JSON render, I don’t use a view. So how does one truncate? I don’t want my JSON object to be huge :)!

  • 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-17T22:00:05+00:00Added an answer on May 17, 2026 at 10:00 pm

    You can use many ways to accomplish this. The most conviniet one would be to just include the proper helper in the controller. In this it would be:

    class BooksController < ApplicationController
      include ActionView::Helpers::TextHelper
      ...
    end
    

    Alternatively you can also create a partial which generates the code you need, for example _truncate.html.erb with proper code:

    <%= truncate (@book, :length => 250) %>
    

    And then render it in your view:

    result = render_to_string :partial => 'truncate'
    

    Hope this helps.

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

Sidebar

Related Questions

my controller is like this $content = View::factory('user/biochemistryTestForm') ->bind('result', $result); $this->template->content = $content; //here
My controller returns this string like so: return Json(indication.Model.PrepaymentExport); I append it to the
controller code that doesn't work: @mailings = Mailing.find(:all, :conditions => [created_at.month = ?, m])
controller: def get_nodes ... render :text => nodes.to_json.to_s end which renders valid JSON (
Controller First I tried this: [HttpPost] public ActionResult Edit(JournalEntry journalentry) { if (ModelState.IsValid) {
My controller, in a nutshell is this: chart1.SeriesCollection.Add(SC); using (MemoryStream ms = chart1.GetChartStream()) {
Controller A's view contains a UIScrollview which contains a UIButton. The content scrolls vertically
Controller function delete_payment($payment_id) { $this->sale_lib->delete_payment($payment_id); $this->_reload(); } View <?php echo anchor(sales/delete_payment/$payment_id,'['.$this->lang->line('common_delete').']');?> It is possible
my controller is $data['qna'] = $this->Ivote_model->get_qa(); view foreach($qna as $k=>$v){ echo $v['question']. '<br/>'; echo
Controller function login() { // Don't show the error message if no data has

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.