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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:57:28+00:00 2026-06-18T03:57:28+00:00

In Rails, we define the create action 2 ways. What are the difference? def

  • 0

In Rails, we define the create action 2 ways. What are the difference?

def create
  @shop = Shop.new(params[:shop])
  if @shop.save
    flash[:success] = 'Thanks for adding new shop.'
    redirect_to @shop
  else
    flash[:error] = 'Error adding review,  please try again.'
    redirect_to @shop
  end
end

# or

def create
  @shop = Shop.create(params[:shop])
  if @shop.save
    flash[:success] = 'Thanks for adding new shop.'
    redirect_to @shop
  else
    flash[:error] = 'Error adding review,  please try again.'
    redirect_to @shop
  end
end

Considering we already have:

def new
  @shop = Shop.new
end

Which is more proper?

  • 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-18T03:57:29+00:00Added an answer on June 18, 2026 at 3:57 am

    If you used Model.create, you don’t need to save the object explicitly. The create method will do that for you.
    If you used Model.new, you need to save the object by doing @object.save. The new
    method does not do that for you.

    Using Model.new:

    def create
      @shop = Shop.new(params[:shop])
       if @shop.save
        flash[:success] = 'Thanks for adding new shop.'
        redirect_to @shop
      else
        flash[:error] = 'Error adding review,  please try again.'
        redirect_to @shop
      end
    end
    

    Using Model.create:

    def create
      @shop = Shop.create(params[:shop])
       # if @shop.save (This is not required)
      if @shop 
        flash[:success] = 'Thanks for adding new shop.'
        redirect_to @shop
      else
        flash[:error] = 'Error adding review,  please try again.'
        redirect_to @shop
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a create action like so in a rails controller: def create @user
In rails 3.1, I implement as: 1. Define test action in post controller: def
Under rails 3.1 If I create a fresh new rails project, and scaffold a
Since Rails 2.1, if you define a new column in a migration with the
Basically I want to implement a simple Rails extension to define the seriousness of
In a Rails 3.2 app I define the page title using <% title Title
When I'm using the Rails console in Ubuntu for a long session I define
I'm having a lot of trouble trying to define a mock for a rails
I'm creating test data for a Rails app. How do I define the value
I'm trying to understand the new arel engine in Rails 3 and I've got

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.