Speak now
Please Wait Image Converting Into Text...
Embark on a journey of knowledge! Take the quiz and earn valuable credits.
Challenge yourself and boost your learning! Start the quiz now to earn credits.
Unlock your potential! Begin the quiz, answer questions, and accumulate credits along the way.
General Tech Learning Aids/Tools 2 years ago
Posted on 16 Aug 2022, this text provides information on Learning Aids/Tools related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.
Turn Your Knowledge into Earnings.
I am working on an edit page which works. However, when I click the save button to save the changes I make, in rails 4, I get the following message: No route matches [PATCH] "/book.17" Any advice on how to fix this? I have been researching for a while and believe that it has something to do with my routes and not directing to the right page. Just not sure how I should change it. I have tried using patch/put instead of get for my edit action or putting patch 'books#update' to update but get the same error message. Any help will be appreciated! Here is the code:
Controller:
class BooksController < ApplicationController def new #@book = Book.all @book = Book.new @authors = Author.all end def edit @book = Book.find_by_id(params[:id]) @authors = Author.all end def update @book = Book.find_by_id(params[:id]) if @book.update_attributes(book_params) flash[:success] = "Book Updated!" redirect_to @book else render 'edit' end end
Routes Page:
Rails.application.routes.draw do root 'welcome#index' get 'author' => 'authors#new' get 'name' => 'authors#show' get 'book' => 'books#new' get 'show' => 'books#show' patch 'edit' => 'books#update' resources :authors resources :books
Edit Page:
<div class="move"> <h1>Update a book entryh2> <div class="row"> <div class="col-md-6 col-md-offset-3"> <%= form_for(@book) do |f| %> <%= render 'form' %> <div class="form-group"> <%= f.label :title %> <%= f.text_field :title, class: 'form-control' %> div> <div class="form-group"> <%= f.label :pub_date %> <%= f.text_field :pub_date, class: 'form-control' %> div> <div class="form-group"> <%= f.label :publisher %> <%= f.text_field :publisher, class: 'form-control' REPLY 0 views 0 likes 0 shares Facebook Twitter Linked In WhatsApp
Change the route
patch 'edit' => 'books#update'
to
patch '/book.:id/' => 'books#update'
it solves the problem
No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.
General Tech 10 Answers
General Tech 7 Answers
General Tech 3 Answers
General Tech 9 Answers
General Tech 2 Answers
Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.