Using time_ago_in_words() in a controller?

I’m getting this error when I try to update a list using ajax after
submitting some data:

undefined method `time_ago_in_words’ for #IdeaController:0x3a38ae8

the LOC is this:
render_text “

  • ” + @params[:idea][:title] + "
    by " +
    @params[:idea][:author] + " | " & time_ago_in_words(Time.now) & " ago |
    " + “
  • Is there something I’m missing? time_ago_in_words(Time.now) works in
    the view…

    thanks!

    k.

    On 8/17/06, kareem [email protected] wrote:

    Is there something I’m missing? time_ago_in_words(Time.now) works in
    [email protected]
    http://lists.rubyonrails.org/mailman/listinfo/rails

    Kareem,

    time_ago_in_words is a method from the helpers of active_view. Those
    methods are not directly exposed in your controller.

    You should resist the temptation to format a response in the
    controller. Pass objects to the view and let them take care of the
    format. This separation of model-view-controller will make testing
    easier and keep everything simple :slight_smile:

    You should resist the temptation to format a response in the
    controller. Pass objects to the view and let them take care of the
    format. This separation of model-view-controller will make testing
    easier and keep everything simple :slight_smile:

    Hi Zack,

    Thanks for the response.

    I’m formatting this data in response to an Ajax request, and want to
    update the page with the formatted data, but without a refresh.

    If this is possible, can you point me in the direction of how I would do
    this by passing an object to the view and formatting it there?

    Thanks much!

    Hammed M. wrote:

    If you use RJS templates to create your view in response to the request,
    you’ll be able to use the active_view helpers.

    This is perfect–thanks!

    If you use RJS templates to create your view in response to the request,
    you’ll be able to use the active_view helpers.

    Hammed

    RJS templates:
    http://www.codyfauser.com/articles/2005/11/20/rails-rjs-templates

    This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

    | Privacy Policy | Terms of Service | Remote Ruby Jobs