~~~ Solution found! ~~~ I changed my def new method in jean_controller.rb to
def new
@jean = Jean.create(params[:id])
end
and capitalized my Model and Description inside my _form partial (to match the capitalize Model and Description inside my migration file)
Thanks for all the help everyone!
~~~~~~~~~~~~~~~~~
So I have looked extensively for a solution to my problem, but to no avail. It drove me to create an account specifically to ask this question. I am using rails 4.2.0
I am using this tutorial https://mackenziechild.me/12-in-12/4/ to build a Pinterest clone, but I run into this error with my _form.html.haml partial:
ActionController::UrlGenerationError in Jeans#new /app/views/jeans/_form.html.haml where line #1 raised: No route matches {:action=>"show", :controller=>"jeans"} missing required keys: [:id]
I've tried a variety of solutions with input_html:, changing my models, jeans_controller...etc
Here is my partial code: (the first line is indented correctly, but I don't know how to get it to display properly on stackoverflow)
= simple_form_for @jean, html: { multipart: true } do |f|
- if @jean.errors.any?
#errors
%h2
= pluralize(@jean.errors.count, "error")
prevented this Jean Model from saving
%ul
- @jean.errors.full_messages.each do |msg|
%li= msg
.form-group
= f.input :model, input_html: { class: 'form-control' }
.form-group
= f.input :description, input_html: { class: 'form-control' }
.form-group
= f.input :price, input_html: { class: 'form-control' }
= f.button :submit, class: "btn btn-primary"
and here is my controller code:
class JeansController < ApplicationController
def index
end
def show
@jean=Jean.find(params[:id])
end
def new
@jean = Jean.new
end
def create
@jean = Jean.new(jean_params)
end
private
def jean_params
params.require(:jean).permit(:model, :description, :price)
end
end
and my routes.rb
Rails.application.routes.draw do
resources :jeans
root "jeans#index"
end
Can anyone help me? :(:
_form
partial to yourjean
? like to show it? – Yan Foto