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

  • Home
  • SEARCH
  • 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 8874533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:44:44+00:00 2026-06-14T18:44:44+00:00

I am making a simple rails site that will store some date and perform

  • 0

I am making a simple rails site that will store some date and perform basic conditional checks. I wrote a few methods below and was told I could make them more efficient. I have been scratching my head and I’m not sure how to do this. Should I make entry.find global? or is there a more obvious solution? Thanks in advance

 def name
     @fname = params[:fst_name]
     @lname = params[:lst_name]
     @entry = Entry.create({:first_name => @fname, :last_name =>  @lname})
  end

  def attribs
     @person = Entry.find(:last)
     @fname = @person.first_name
     @lname = @person.last_name
     @person.update_attributes({:address => params[:st_name], 
         :salary => params[:salary], :loan => params[:loan], 
         :loan_reason => params[:reason]})
     if !@person.address.nil? then render "show" end
  end

 def show
     @person = Entry.find(:last)
 end

  def modify
     @person = Entry.find(:last)
     @fname = @person.first_name
     @lname = @person.last_name
     @entry = Entry.create({:first_name => @fname, :last_name =>  @lname,  
                            :salary => params[:salary], :loan => params[:loan]})
  end

 def borrow
     @person = Entry.find(:last)
     if !@person.salary.nil? then
       if (@person.salary *  3) < @person.loan
            then @message = "You have asked for too much"
       else  @message = "No problem" 
       end
    else @message = "empty record?"
    end
 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-14T18:44:45+00:00Added an answer on June 14, 2026 at 6:44 pm
    • Use a before_filter for the cases where you are repeatedly using @person = Entry.find(:last)

    • Don’t make every variable an instance variable: for name: you don’t need to acces @fname in the view, you can do @entry.first_name if you need to.

    • Don’t use inline if then, use do_something if condition. Also remove the then from your other ifs too.

    • You may want to move the Event creation into the model. Something like self.create_from_person_and_modify_params

    • Use Event.last instead of Event.find(:last)

    • Use if @person.salary instead of if !@person.salary.nil?

    • Move the if (@person.salary * 3) < @person.loan condition into the model. Something like asks_for_reasonable_raise?

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

Sidebar

Related Questions

in making a simple cgi server for a course. To do that in some
I have a simple List-style Backbone app that I'm making with a Rails backend.
I'm making a simple search form in rails. In my search view I have
I'm making a simple mediaplayer app that downloads a song from a predetermined URL
I am developing a rails application that will eventually contain products, users, and orders.
I'm making a simple blog Rails app and am trying to output links to
So, I wrote a simple Ruby class, and put it in my rails /lib
I'm making a simple to-do list application to teach myself Ruby on Rails, however
I am new to rails and am making a simple form. In the form
I'm making very simple ROR (rails 2.3.5) application and using jQuery plugin jRails. 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.