我的控制器中有两个不同的动作。
def new
@admin_option=AdminOption.first
@book = Book.new
@book.cover_image = @admin_option.default_book_cover_image
session[:new_book] = @book.to_json
puts session.to_json
render :layout => nil if request.xhr?
end
此时,看看节目:
{"session_id":"46ab9a3e87653e3a61e8d7fae7b5ef58","_csrf_token":"a8EIYjNGSZgEnal9ukHqJL1DjGePer6cU+V7MMT3fPo=","warden.user.user.key":["User",[116],"$2a$10$mkbMIx/MtN7XfbG2.KhjcO"],"new_book":"{\"author_id\":null,\"cover_image\":{\"url\":\"/uploads/tmp/20130211-1510-4506-6510/images.jpeg\",\"feature\":{\"url\":\"/uploads/tmp/20130211-1510-4506-6510/feature_images.jpeg\"},\"large\":{\"url\":\"/uploads/tmp/20130211-1510-4506-6510/large_images.jpeg\"},\"thumb\":{\"url\":\"/uploads/tmp/20130211-1510-4506-6510/thumb_images.jpeg\"}},\"created_at\":null,\"description\":null,\"enabled\":true,\"excerpt\":null,\"featured\":null,\"id\":null,\"publication_date\":null,\"teaser\":null,\"title\":null,\"updated_at\":null}"}
在视图中,我有以下代码:
<%= form_tag('/upload_photo_new',:html => { :multipart => true},:remote=>true) do %>
<input type="button" value="Browse" class="btn_grey" />
<input type="file" name="cover_image" onchange="myurl();" />
<%= submit_tag "Upload"%>
<% end %>
在我收到提交后执行的操作中:
def crop_update
puts session.to_json
end
这是打印的内容:
{"session_id":"46ab9a3e87653e3a61e8d7fae7b5ef58","_csrf_token":"a8EIYjNGSZgEnal9ukHqJL1DjGePer6cU+V7MMT3fPo=","warden.user.user.key":["User",[116],"$2a$10$mkbMIx/MtN7XfbG2.KhjcO"]}
会话丢失了我添加的密钥。
为什么?