我一直在試圖讓這種形式現在工作多年,我似乎無法得到它的工作。最令人討厭的部分是,一切似乎正常工作,但沒有出現在數據庫中。導軌形式不保存到數據庫中
控制器:
def create
@post = Post.new(params[:post])
respond_to do |format|
if @post.save!
format.html { redirect_to @post, notice: 'Lesson was successfully created.' }
format.json { render json: @post, status: :created, location: @post }
else
format.html { render action: "new" }
format.json { render json: @post.errors, status: :unprocessable_entity }
end
end
end
型號
attr_accessible :userID, :groupID, :postTime, :postText
查看添加後
#uploadStyle
= form_for Post.new do |f|
= f.label :postText, 'PostText'
= f.text_area :postText
%br
= f.label :postTime, 'PostTime'
= f.text_area :postTime
%br
= f.label :userID, 'UserID'
= f.text_area :userID
%br
= f.label :groupID, 'GroupID'
= f.text_area :groupID
%br
= submit_tag 'Submit'
日誌
Started POST "/posts" for 127.0.0.1 at 2013-10-10 22:04:32 -0700
Processing by PostsController#index as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"AUq6mt54N7kA67M1L9wQdqhl2UPRxhOEZOv/LSowcJU=", "post"=>{"postText"=>"work please", "postTime"=>"2013-01-01 04:24:23", "userID"=>"1", "groupID"=>"1"}, "commit"=>"Submit"}
Post Load (0.1ms) SELECT "posts".* FROM "posts" ORDER BY "posts"."id" DESC LIMIT 1
Post Load (0.2ms) SELECT "posts".* FROM "posts"
Rendered posts/index.html.haml within layouts/application (12.5ms)
Completed 200 OK in 40ms (Views: 24.8ms | ActiveRecord: 0.7ms)
條
路線
root :to => 'posts#index' match '/posts', :to => 'posts#index' resources :posts do member do post 'upload' end end match '/posts/:id', :to => 'posts#show', :format => false match '/add_post', :to => 'posts#add_post'
你可以添加你的路線的問題?他們看起來很奇怪 - 甚至沒有進入你的「創造」行動。 '通過PostsController處理#索引'它也不像它那樣行事 - 你的代碼說你要麼再次看到表單,要麼進入Post頁面,並且你沒有得到那些結果。 – sevenseacat
根據要求添加 –
您是否對任何後期模型屬性有任何約束?保存!如果存在驗證問題,方法不會將任何內容保存到數據庫中。嘗試使用rails控制檯手動創建記錄(從命令提示符/終端的項目根目錄鍵入rails c)。 – rb512