After changing the edit and new forms to use the _form partial, I get this error on trying to edit a record (I changed article to artwork for the examples):
No route matches [POST] “/artworks/2/edit” Rails.root: c:/Users/bburns/Desktop/arttour Application Trace | Framework Trace | Full Trace Routes Routes match in priority from top to bottom Helper HTTP Verb Path Controller#Action Path / Url
welcome_index_path GET /welcome/index(.:format) welcome#index artworks_path GET /artworks(.:format) artworks#index POST /artworks(.:format) artworks#create new_artwork_path GET /artworks/new(.:format) artworks#new edit_artwork_path GET /artworks/:id/edit(.:format) artworks#edit artwork_path GET /artworks/:id(.:format) artworks#show PATCH /artworks/:id(.:format) artworks#update PUT /artworks/:id(.:format) artworks#update DELETE /artworks/:id(.:format) artworks#destroy root_path GET / welcome#index Request Parameters: {“utf8”=>“?”, “authenticity_token”=>“0+8G5XLT4b6/3U1v6K4p0GnpcSxjsti8wid/+akAlDrFEQEfeVvnwp9Jte+ohyJGFUIw0vqYGnPcQxAP4rEijA==”, “artwork”=>{“artist”=>“inness”, “year”=>“1889”, “title”=>“moonrise”, “about”=>“”}, “commit”=>“Save Artwork”} And adding a new record gets a similar error -
No route matches [POST] "/artworks/new"
I’m new to Rails so not sure what might be going wrong - thanks in advance for any pointers
routes.rb:
Rails.application.routes.draw do get ‘welcome/index’ resources :artworks root ‘welcome#index’ end
artworks_controller.rb:
class ArtworksController < ApplicationController
def index @artworks = Artwork.all end
def show @artwork = Artwork.find(params[:id]) end
def new @artwork = Artwork.new end
def edit @artwork = Artwork.find(params[:id]) end
def create @artwork = Artwork.new(artwork_params) if @artwork.save redirect_to @artwork else render ‘new’ end end
def update @artwork = Artwork.find(params[:id])
if @artwork.update(artwork_params) redirect_to @artwork else render ‘edit’ end
endprivate def artwork_params params.require(:artwork).permit(:artist, :title, :year, :about) end
end
edit.html.erb:
Editing artwork
<%= render 'form' %> <%= link_to 'Back', artworks_path %>
_form.html.erb: