我一直试图让这个表格工作很长时间,但我似乎无法让它工作。最烦人的部分是一切似乎都正常工作,但数据库中没有任何显示。
控制器:
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)
路线
根 :to => 'posts#index' 匹配 '/posts', :to => 'posts#index' 资源:帖子做 会员做 发布“上传” 结尾 结尾 匹配 '/posts/:id', :to => 'posts#show', :format => false 匹配 '/add_post', :to => 'posts#add_post'