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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:44:28+00:00 2026-05-30T15:44:28+00:00

Is this action ok? Can it be improved in any way? Should I extract

  • 0

Is this action ok? Can it be improved in any way? Should I extract the setting up of the order to a private method and just call that? Or is it fine and in line with the ‘Rails way’?

def create
  @order = Order.new(params[:order])
  @product = Product.find(session[:product])
  @order.amount = session[:total_amount]
  @order.ip_address = request.remote_ip
  @order.product_id = @product.id
  @order.product_price = @product.price
  @order.voucher = @voucher_value
  @order.friend_id = session[:friend_id]
  if @order.save
    if @order.purchase
      render :action => "success"
      reset_friend_session_codes
    else
      render :action => "failure"
    end
  else
    render :action => 'new'
  end
end

TIA.

  • 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-30T15:44:30+00:00Added an answer on May 30, 2026 at 3:44 pm

    I would factor out as much as I could into a private method in the order model and call it with one of the model hooks, such as before_validation. That’s too much logic for an action, and tramples all over MVC.

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

Sidebar

Related Questions

I have an URL like this /home/action/id How can I access this id in
Given some typical search form, I can't construct this form action when submitting a
Hello can anybody solve this please I'm creating the object in the action class
I can't seem to get a custom action working. I might be doing this
What does the SQL Action keyword do? Can I use this keyword in a
How can I upload files to server using JSP/Servlet? I tried this: <form action="upload"
Given an html form like this: <form action='/example/' id='example_form' method='POST' name='example_form'> <fieldset> <legend>Example form</legend>
I have a model, smth like this: class Action(models.Model): def can_be_applied(self, user): #whatever return
this action is generated in symfony 1.2 when you create a module: public function
I have to do through Action like this: Action action = () => {

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.