Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 4 如何将此html输出转换为json builder one RAILS_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails 4 如何将此html输出转换为json builder one RAILS

Ruby on rails 4 如何将此html输出转换为json builder one RAILS,ruby-on-rails-4,Ruby On Rails 4,我在将html输出转换为json时遇到了这个问题。我知道如何使用嵌套jBUILDER,而且有很多,但这一个不同,我必须通过朋友id获取用户名,因为我做了一个有很多:通过关联 用户协会 联谊会 这条线 <%=h friendship.friend.name %> shows the name of the user is befriended while this line <% for user in @user.inverse_friends %> show the

我在将html输出转换为json时遇到了这个问题。我知道如何使用嵌套jBUILDER,而且
有很多
,但这一个不同,我必须通过
朋友id
获取
用户名,因为我做了一个
有很多:通过关联

用户协会 联谊会 这条线

<%=h friendship.friend.name %> shows the name of the user is befriended
 while this line
<% for user in @user.inverse_friends %> show the name the ofthe user the inverse of of friendships
   <li><%=h user.name %></li>
<% end %>
这是我的回购协议

belongs_to :user
belongs_to :friend, :class_name => "User"
<%=h friendship.friend.name %> shows the name of the user is befriended
 while this line
<% for user in @user.inverse_friends %> show the name the ofthe user the inverse of of friendships
   <li><%=h user.name %></li>
<% end %>
json.extract! @user, :id, :name

json.projects @user.projects, :id, :name, :descriptions, :startDate, :dueDate, :created_at, :updated_at, :user_id, :project_confirm

json.friendships @user.friendships,:user_id, :friend_id

json.inverse_friendships @user.inverse_friendships, :user_id, :friend_id