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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:39:49+00:00 2026-06-15T17:39:49+00:00

I have an action called update_mobile and in it I am preparing a massive

  • 0

I have an action called update_mobile and in it I am preparing a massive amount of instance variables that I use in a RABL JSON request. You can see that if the request contains the params[:last_updated] parameter, then I only get the models that have been updated since then. This seems to disobey the “Fat Models, Skinny Controllers” method. How can I refactor this method?

  def update_mobile
    @last_updated = params[:last_updated]
    if @last_updated.nil?
      @buddies = @user.friends
      @courses = @user.courses
      @friendly_schools = @user.friendly_schools
      @documents = @user.all_notes
      @instructors = @user.current_instructors
      @friendships = @user.friendships
      @questions = @user.current_questions
      @answers = @user.current_answers
      @comments = @user.current_comments
    else
      @buddies = @user.friends.select{ |user| user.updated_at > @last_updated }
      @courses = @user.courses.select{ |course| course.updated_at > @last_updated }
      @friendly_schools = @user.friendly_schools.select{ |school| school.updated_at > @last_updated }
      @documents = @user.all_notes.select{ |note| note.updated_at > @last_updated }
      @instructors = @user.current_instructors.select{ |instructor| instructor.updated_at > @last_updated }
      @friendships = @user.friendships.select{ |friendship| friendship.updated_at > @last_updated }
      @questions = @user.current_questions.select{ |question| question.updated_at > @last_updated }
      @answers = @user.current_answers.select{ |answer| answer.updated_at > @last_updated }
      @comments = @user.current_comments.select{ |comment| comment.updated_at > @last_updated }
    end
  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-06-15T17:39:50+00:00Added an answer on June 15, 2026 at 5:39 pm

    You should move the code out to your model and let your model deal with 1) the parameter being nil and 2) using ActiveRecord to query the database effectively.

    In your controller, have lines like this for each of your variables:

    @friends = @user.friends.updated_since(params[:last_updated])
    

    (I’ve renamed @buddies here to @friends, because we want to maintain consistency in naming the things of the system)

    Then, in your Friend model, define a class method called updated_since that does that logic:

    class Friend < ActiveRecord::Base
      def self.updated_since(last_updated)
        if last_updated.present?
          where("updated_at > ?", last_updated)
        else
          all
        end
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an action method VerifyNewUser() that gets called when the user clicks a
I have a action on my controller (controller name is 'makemagic') called 'dosomething' that
I have code that I want to be executed before every action is called.
I have a class that has an Action<string> called DisplayData ; In various points
So I have a button that is attached to an action called writeToFile: The
I have an action called 'watched' defined on an object 'Movie' (using the inbuilt
I have a controller called Diary with an action called View . If I
Projects have many tasks and a task has a custom RESTful action called 'approve'.
I have an ASP.NET MVC 3 application which has a post action called Create
I have a div called test and mvc action in the client controller The

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.