当我创建一个新事件时,似乎所有内容都保存在我的Rails 4应用程序上(使用simple_form),但是当我尝试更新现有事件时(通过转到events/3/edit
),它没有'保存任何更改。
这是我的控制台日志:
Started PATCH "/events/3" for 12.43.117.2 at 2015-06-17 19:28:34 +0000
Started PATCH "/events/3" for 12.43.117.2 at 2015-06-17 19:28:34 +0000
Processing by EventsController#update as HTML
Processing by EventsController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"tdCaXgxDSLNJg2qcsB91W9No3fJpu7Z7XDxktXGGJ5A=", "event"=>{"event_name"=>"Salute Miami’s Bicycling Heroes: Reception for Kirk Munroe & Wilson Larkins", "location"=>"Coco Plum Woman's Club, 1375 Sunset Road, Miami, FL 33143", "event_date_time(1i)"=>"2015", "event_date_time(2i)"=>"6", "event_date_time(3i)"=>"17", "event_date_time(4i)"=>"12", "event_date_time(5i)"=>"03", "description"=>"Honor Kirk Munroe,\r\nblahbicycblah", "organizer"=>"blah", "category"=>"Community Event"}, "commit"=>"Update Event", "id"=>"3"}
Parameters: {"utf8"=>"✓", "authenticity_token"=>"tdCaXgxDSLNJg2qcsB91W9No3fJpu7Z7XDxktXGGJ5A=", "event"=>{"event_name"=>"Salute Miami’s Bicycling Heroes: Reception for Kirk Munroe & Wilson Larkins", "location"=>"Coco Plum Woman's Club, 1375 Sunset Road, Miami, FL 33143", "event_date_time(1i)"=>"2015", "event_date_time(2i)"=>"6", "event_date_time(3i)"=>"17", "event_date_time(4i)"=>"12", "event_date_time(5i)"=>"03", "description"=>"Honor Kirk Munroe,\r\nblahbicycblah", "organizer"=>"blah", "category"=>"Community Event"}, "commit"=>"Update Event", "id"=>"3"}
Rendered events/update.html.erb within layouts/application (0.1ms)
Rendered events/update.html.erb within layouts/application (0.1ms)
Completed 200 OK in 173ms (Views: 171.3ms | ActiveRecord: 0.0ms)
Completed 200 OK in 173ms (Views: 171.3ms | ActiveRecord: 0.0ms)
发生这种情况后,我得到一个空白的更新事件页面,上面没有表单字段。然后我返回到事件索引并返回到单个事件,只是发现它是最初的方式。无论它在做什么,它似乎都是两次发送信息(原始信息先发布然后更新),但由于某种原因,更新似乎并不坚持。
对于它的价值,事件控制器的def update
部分是空的,我使用的是postgresql数据库。
Github回购:https://github.com/yamilethmedina/wheels_registration 测试服务器:https://wheels-registration-yamilethmedina.c9.io/
答案 0 :(得分:0)
这是我最终做的,基于此(用user
替换单词event
):https://www.railstutorial.org/book/updating_and_deleting_users#sec-unsuccessful_edits
events_controller.rb
:
def update
@event = Event.find(params[:id])
if @event.update_attributes(event_params)
# Handle a successful update.
else
render 'update'
end
end
也许删除else render 'update'
可能会避免空白"更新事件"我执行此操作后显示的页面,但这更像是一个后端功能(用户不会有编辑这些事件的链接)并且它接受更改,因此我是内容。