如何将会话中的数据保存到数据库?
我目前正在使用 Rails 3 应用程序。我应该如何将数据从会话保存到数据库?
这是我的控制器:
def step2
@cart = current_cart
checkin = params[:checkin]
checkout = params[:checkout]
@amenities = Amenity.available(checkin, checkout)
session[:checkin] = checkin
session[:checkout] = checkout
end
和我的观点:
<%= form_for(@transaction, :validate => true) do |f| %>
<%= f.hidden_field :Transaction_Date, :value => Time.now %>
<%= f.hidden_field :rsv_type, :value => "Online" %>
<%= f.hidden_field :rsv_status, :value => "Pending" %>
<%= f.hidden_field :checkin, :value => session[:checkin] %>
<%= f.hidden_field :checkout, :value => session[:checkout] %>
<% end %>
I'm currently using rails 3 app. How am I supposed to save data from session to the database?
Here's my controller:
def step2
@cart = current_cart
checkin = params[:checkin]
checkout = params[:checkout]
@amenities = Amenity.available(checkin, checkout)
session[:checkin] = checkin
session[:checkout] = checkout
end
and my view:
<%= form_for(@transaction, :validate => true) do |f| %>
<%= f.hidden_field :Transaction_Date, :value => Time.now %>
<%= f.hidden_field :rsv_type, :value => "Online" %>
<%= f.hidden_field :rsv_status, :value => "Pending" %>
<%= f.hidden_field :checkin, :value => session[:checkin] %>
<%= f.hidden_field :checkout, :value => session[:checkout] %>
<% end %>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
其实你的问题我也不是很清楚。
如果你想从会话中获取一些数据,然后将其保存到数据库中,就像你写的那样:
如果你想将会话存储在数据库中,你应该配置你的rails应用程序:
Actually I am not very clear about your question.
If you want to fetch some data from session, then save it into database, just like what you wrote:
And if you want to store the session in database , you should config your rails application: