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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:59:12+00:00 2026-05-15T23:59:12+00:00

Say I have an Article model, and in the article ‘new’ view I have

  • 0

Say I have an Article model, and in the article ‘new’ view I have two buttons, “Publish” and “Save Draft”.

My question is how can I know which button is clicked in the controller.

I already have a solution but I think there must be a better way.
What I currently used in the view is:

<div class="actions">
  <%= f.submit "Publish" %>
  <%= f.submit "Save Draft", :name => "commit" %>
</div>

So in the controller, I can use the params[:commit] string to handle that action.

def create
  @article = Article.new(params[:article])
  if params[:commit] == "Publish"
    @article.status = 'publish'
    // detail omitted
  end

  @article.save
end

But I think using the view related string is not good. Could you tell me another way to accomplish this?

UPDATE: Since these buttons are in the same form, they’re all going to the ‘create’ action, and that’s OK for me. What I want is to handle that within the create action, such as give the Article model a ‘status’ column and holds ‘public’ or ‘draft’.

  • 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-15T23:59:13+00:00Added an answer on May 15, 2026 at 11:59 pm

    This was covered in Railscast episode 38. Using the params hash to detect which button was clicked is the correct approach:

    View:

    <%= submit_tag 'Create' %>
    <%= submit_tag 'Create and Add Another', name: 'create_and_add' %>
    

    Controller:

    if params[:create_and_add]
      # Redirect to new form, for example.
    
    else
      # Redirect to show the newly created record, for example.
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have two models, Article and Category: class Article(models.Model): category = models.ForeignKey(Category, related_name='articles')
Got a question. Say I have two models in a many-to-many relationship (Article, Publication).
Let's say I have a set of Django Models: class Article(models.Model): title = models.CharField(max_length=100,
Let's say we have an Article model and a Comment model. Article: columns: body:
Let's say I have to model the meals of a diner. A meal can
Let's say I have a model called Article: class Article < ActiveRecord::Base end And
Let's say I have two ActiveRecord models: LineItem and Article. class LineItem < ActiveRecord::Base
Let's say I have two entities in my Symfony2 project : Category and Article
Let's say you have a blog and a user can Like and article. On
Say that I have an article with multiple pages. Each page has a short

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.