Hello all, I’m new to ruby and I am having trouble with adding new data
(name, height, weight, etc). Everytime I try to save my data, I get
this error:
No route matches [POST] “/home/new”
Rails.root: C:/Users/Bob/blog
Request
Parameters:
{“utf8”=>“✓”,
“authenticity_token”=>“Vgkmt3PPEobQFpJyWNIoHNnXtkmq2Uyk4vjMvgl8ZdhwIvc516BzXUfDs05OZ/8LLfkyKTxca90qiA2LBYBnwQ==”,
“@input”=>{“name”=>“asd”,
“weight”=>“233”,
“height”=>“23”,
“color”=>“red”,
“age”=>“23”},
“commit”=>“Save @input”}
I am able to view index and enter the information, but when I submit, I
get this problem. Any help would be appreciated! Thank you
home_controller.rb
class HomeController < ApplicationController
def index
@inputs = Person.all
end
def new
@input = Person.new
end
def create
@input = Person.new(input_params)
if @article.save
redirect_to @input
else
render ‘new’
end
end
def show
@input = Person.find(params[:id])
end
def edit
@input = Person.find(params[:id])
end
def update
@input = Person.find(params[:id])
respond_to do |x|
if @input.update(input_params)
x.html {redirect_to :action => ‘index’}
else
x.html {render :edit}
end
end
end
private
def input_params
params.require(:inputs).permit(:name, :weight, :height, :color,
:age)
end
end
=================================================================
new.html.erb
New People
<%= render ‘form’ %>
<%= link_to ‘Back’, home_index_path %>
=================================================================
_form.html.erb
<%= form_for :@input do |person| %>
<%= person.text_field :name %>
<%= person.number_field :weight %>
<%= person.number_field :height %>
<%= person.text_field :color %>
<%= person.number_field :age %>
=================================================================
index.html.erb
<%= notice %>
Listing People
Name | Weight | Height | Color | Age | ||
---|---|---|---|---|---|---|
<%= person.name %> | <%= person.weight %> | <%= person.height %> | <%= person.color %> | <%= person.age %> | <%= link_to 'Show',home_path(person.id) %> | <%= link_to 'Edit', edit_home_path(person.id) %> |
<%= link_to 'New Person', new_home_path %>
=================================================================
my routes.db has
resources :home
root ‘home#index’