Ruby on rails 4 如何将此html输出转换为json builder one RAILS
我在将html输出转换为json时遇到了这个问题。我知道如何使用嵌套jBUILDER,而且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
有很多
,但这一个不同,我必须通过朋友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