我尝试访问我的@user 对象中数组的第一个元素并从该数组中获取第一个对象。我只是让它不工作。这是代码:
<%= form_for(@user) do |f| %>
<% if @user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
<ul>
<% @user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<% if params[:redirect_to] -%>
<%= hidden_field_tag 'redirect_to', params[:redirect_to] %>
<% end -%>
#Thats not working
Last booking: <%= f.text_field Booking.where("user_id="+ @user.id+").order('start_date DESC').first%>
<% end %>