1
私の単純なシステムの編集ページをプルアップしようとしています。'student_id' = RUBY ON RAILSの学生が見つかりませんでした
class StudentsController < ApplicationController
def index
@students = Student.newest_first
end
def show
@student = Student.find(params[:student_id])
end
def new
@student = Student.new
end
def create
@student = Student.new(student_params_create)
if @student.save
flash[:notice] = "Student record created successfully"
redirect_to(students_path)
else
render('new')
end
end
def edit
@student = Student.find(params[:student_id])
end
def update
@student = Student.find(params[:student_id])
if @student.update_attributes(student_params_update)
flash[:notice] = "Students updated"
redirect_to(students_path)
else
render('edit')
end
end
def delete
@student = Student.find(params[:student_id])
end
def destroy
@student = Student.find(params[:student_id])
@student.destroy
end
private
def student_params_create
params.require(:student).permit(:first_name, :last_name, :birthday, :email, :subjects, :username, :password)
end
def student_params_update
params.require(:student).permit(:first_name, :last_name, :birthday, :email, :subjects)
end
end
そして、私はここで私は私の学生の[編集]をクリックすることができ、私のインデックスページがありますしようとしています:ここで
は、学生のための私のコントローラは次のようになります。私が得た私の生徒の一人にhttp://localhost:3000/students/
をクリックし:私は学生のための私のリソースへ行くしようとすると
<h2>Update Subject</h2>
<%= form_for(@student) do |f| %>
<%= f.text_field(:first_name) %>
<%= f.datetime_select(:created_at, :order => [:month, :day, :year]) %><
<%= f.submit("Update Subject") %>
<% end %>
:私のフォームの編集については
<% @students.each do |student|%>
<%= student.first_name %>
<%= student.student_id %>
<%= link_to("Show", student_path(student), :class => 'action show') %>
<%= link_to("Edit", edit_student_path(student), :class => 'action edit') %>
<%= link_to("Delete", delete_student_path(student), :class => 'action delete') %>
<% end %>
は、私はFFを得ましたFF:エラー:何A
任意のアイデア私は間違っていますか?
EDIT:
マイグレーション中に 'id'をfalseに設定しました。
def up
create_table :students, :id => false do |t|
t.integer "student_id",:primary_key => true
t.string "first_name", :limit => 25
t.string "last_name", :limit => 50
t.string "email", :default => ' ', :null => false
t.string "birthday"
t.string "subjects"
t.string "teachers"
t.string "username", :limit => 25
t.string "password_digest"
t.timestamps
end
reversible do |dir|
dir.up { execute "ALTER TABLE students AUTO_INCREMENT = 1000" }
end
# execute "CREATE SEQUENCE students_student_id_seq OWNED BY students.student_id INCREMENT BY 1 START WITH 1001"
end
def down
drop_table :students
# execute "DELETE SEQUENCE students_student_id_seq"
end
ルート:
resources :students do
member do
get :delete
end
end
のようなあなたの
show
アクションを編集できるよう「ID」がfalseに設定された、私は「STUDENT_ID」を介して設定する独自のカスタムIDを使用しています、私は「1000」のidを持つ学生を持っていますし、 '1001' ..なぜ私は 'student_id'になければならないのか、なぜ 'trace'が 'id'であるのか分かりません。実際にはこの '@student = Student.find(params [:student_id])'を指定しています。 –それを試しましたが、それでも私は同じエラーが発生しています –
あなたのルートを表示できますか? – VAD