0
없이 레일 CRUD 작업을 수행하는 방법 :보석에서 비계 명령
gem 'simple_form', '~> 3.2', '>= 3.2.1'
gem 'haml', '~> 4.0', '>= 4.0.7'
모델 :
컨트롤러에서ActiveRecord::Schema.define(version: 20160706040748) do
create_table "jobs", force: :cascade do |t|
t.string "title"
t.text "description"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
end
:
class JobController < ApplicationController
before_action :find_job, only: [:show, :edit, :update, :destroy]
def index
end
def show
end
def new
@job = Job.new
end
def create
@job = Job.new(jobs_params)
if @job.save
redirect_to @job
else
render "New"
end
end
def edit
end
def update
end
def destroy
end
private
def jobs_params
params.require(:job).permit(:title, :description)
end
def find_job
@job = Job.find(params[:id])
end
end
경로에서 :
resources :job
root 'job#index'
부분보기 (양식)에서
%h1 New Job
= render 'form'
= link_to "Back", root_path
:보기 (새)에서
simple_form 보석 ***를 사용하여 **** 내가 http://localhost:3000/job/new
NoMethodError in Job#new
undefined method `jobs_path' for #<#<Class:0x007ffcf6241328>:0x007ffcfe176bc0>
= simple_form_for(@job, html: { class: 'form-horizontal'}) do |f|
= f.input :title, label: "Course Title"
= f.input :description, label: "Course description"
%br/
= f.button :submit
으로 실행
= simple_form_for(@job, html: { class: 'form-horizontal'}) do |f|
= f.input :title, label: "Course Title"
= f.input :description, label: "Course description"
%br/
= f.button :submit
오 세상에,이 한 줄의 코드로 하루를 절약하십시오. ') 저는 거의 하루 동안 수색되었습니다. – Osp
@Osp 오신 것을 환영합니다. 답변을 수락하는 것을 고려하십시오. 지침을 참조하십시오. http://meta.stackexchange.com/a/5235/249307 – SoAwesomeMan