Ruby on rails 我如何从Rails中的这种响应中获得键、值?
从控制器端,它发送这样的数据Ruby on rails 我如何从Rails中的这种响应中获得键、值?,ruby-on-rails,Ruby On Rails,从控制器端,它发送这样的数据 {:room_id=>383, :title=>"111's new appointment", :description=>"new content", :organizer=>"4444 1111", :appointment_id=>"266", :is_owner=>true, :roomtype=>"1", :c onference_time=>"12.12 10:00 ~ 12.12 23:00", :ma
{:room_id=>383, :title=>"111's new appointment", :description=>"new content", :organizer=>"4444 1111", :appointment_id=>"266", :is_owner=>true, :roomtype=>"1", :c
onference_time=>"12.12 10:00 ~ 12.12 23:00", :maximun_users=>"3", :current_user_list=>[#<Client firstname: "4444", lastname: "1111">], :users=>"1 / 3"}
{:room_id=>383,:title=>111的新约会,:description=>“新内容”,:organizer=>“4444441111”,:约会_id=>“266”,:is_owner=>true,:roomtype=>“1”,:c
会议时间=>“12.12 10:00~12.12 23:00”,:最大用户=>“3”;:当前用户列表=>[#],:用户=>“1/3”}
我知道如何获取其他数据,但我的问题是
:current_user_list=>[#<Client firstname: "4444", lastname: "1111">]
:当前用户列表=>[#]
我如何在这里获得密钥和值
<% @appointments.each do |appointment| %>
<%=Rails.logger.debug("**********APPOINTEMTN : : : : : : : ******"+appointment[:current_user_list].to_s)%>
<% if appointment[:is_owner] %>
<tr class="roomlist_myrow">
<td><%=h appointment[:room_id] %></td>
<td><%=h appointment[:title] %></td>
<td><%=h get_roomtype_from_room_list().rassoc(appointment[:roomtype])[0] %></td>
<td><%=h appointment[:users] %></td>
<td style="color: #a9a9a9"><%=h appointment[:organizer] %></td>
<td style="color: #3c3c3c"><%=h appointment[:conference_time] %></td>
<td>
<% url = get_appointment_server(appointment[:appointment_id]) %>
<%= button_to_function "Enter", "enter_room('#{appointment[:room_id]}','#{url}')"%>
<%= link_to ("<button>Modify</button>".html_safe), make_params({ :action => :edit, :id => appointment[:appointment_id] }) %>
<%= link_to ("<button>Delete</button>".html_safe), make_params({ :action => :destroy, :id => appointment[:appointment_id] }),
method: :delete, data: { confirm: 'Are you sure?' } %>
</td>
</tr>
<%else%>
<tr class="roomlist_row">
<td><%=h appointment[:room_id] %></td>
<td><%=h appointment[:title] %></td>
<td><%=h get_roomtype_from_room_list().rassoc(appointment[:roomtype])[0] %></td>
<td><%=h appointment[:users] %></td>
<td style="color: #a9a9a9"><%=h appointment[:organizer] %></td>
<td style="color: #3c3c3c"><%=h appointment[:conference_time] %></td>
<td id="roomlist_notowner_td">
<% url = get_appointment_server(appointment[:appointment_id]) %>
<%= button_to_function "Enter", "enter_room('#{appointment[:room_id]}','#{url}')"%>
</td>
</tr>
<%end%>
<% end %>
:编辑,:id=>appointment[:appointment\u id]})%>
:destroy,:id=>appointment[:appointment\u id]}),
方法::删除,数据:{确认:'确定吗?}%>
如果我把它打印出来
<%=Rails.logger.debug("**********APPOINTEMTN : : : : : : : ******"+appointment[:current_user_list].to_s)%>
**********APPOINTEMTN : : : : : : : ******#<ActiveRecord::Relation:0x4d48880>
**********任命人******#
有什么好的解决方案吗?循环它:
约会[:当前用户列表]。每个do | user |
然后打印它user.firstname
或其他什么。如果约会[:当前用户列表]
是一个数组对象,那么您可以尝试以下公共方法:
hash.each_key{| key_value_数组| block}
迭代散列,为每个键调用一次块,将键和值作为参数传递
还是这个
hash.each{键,值|块}
迭代哈希,为每个键调用一次块,将键值作为两个元素数组传递
可在此处找到: