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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:41:54+00:00 2026-06-13T01:41:54+00:00

Having a bit of trouble with the following ruby on rails code snippet –

  • 0

Having a bit of trouble with the following ruby on rails code snippet – I have books and would like to update a book’s name, here is how I try to do it:

<h1>Edit the book "<%= @book.name %>"</h1>
<%= form_tag action: :update, id: @book do %>
    <p>
        <label for="book_name">Name</label>
        <%= text_field :book, :name %>
        <%= submit_tag 'Save changes' %>
    </p>
<% end %>

This is what I do in the books controller:

def edit
    @book = Book.find(params[:id])
end

def update
    @book = Book.find(params[:id])
    if @book.update_attributes(params[:book])
        redirect_to :action => 'show', id => @book
    else
        @subjects = Subject.find(:all)
        render :action => 'edit'
    end
end

These are my routes:

root to: 'authors#index'
resources :books, :authors

When I click the submit button in the form, it gives me No route matches [POST] "/books/5" and directs to localhost:3000/books/5 instead of staying and localhost:3000/books/5/edit

What am I doing wrong here? Shouldn’t there be a put method for updating stuff somewhere rather than a post method?

  • 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-13T01:41:55+00:00Added an answer on June 13, 2026 at 1:41 am

    Updates should use put not post.

    <%= form_tag( { :controller => :books, :action => :update, :id => @book.id }, { :method => :put } ) do %>
    

    or better yet use form_for

     <%= form_for @book do |f| %>
    

    On your console run “rake routes” and it will print out all available routes.

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

Sidebar

Related Questions

I'm having a bit of trouble with the following code. I have an absolutely
I am having trouble with the following bit of code. //Send Creation email ListServDAO.sendCreateEmail(orgId,
I am having a bit of trouble with the following code that appears to
I am having a little bit trouble with the following. I have multiple form
I am having a bit of trouble with the following include: #include <ntddscsi.h> When
Having a bit of trouble using the List.Find with a custom predicate i have
I am having a bit of trouble getting my head around the following erlang
I'm having a little bit of trouble implementing the following method while handling the
I'm having a bit of trouble with some XML in Java. The following is
I'm having a bit of trouble figuring out what would be the best approach

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.