1
저는 실제로 응용 프로그램에 Active Model Serializers
을 구현하고 있습니다. 모든 것이 예상대로 작동했지만 지금은 (JSON) html 부분을 내 데이터와 함께 보내야합니다. 여기에 내가 무슨 짓을 :활성 모델 시리얼 라이저 : link_to가 작동하지 않습니다.
class ActivitySerializer < ActiveModel::Serializer
include Rails.application.routes.url_helpers
attributes :id, :kind, :data, :created_at, :html
has_many :comments
def html
controller = ApplicationController.new
controller.render_to_string(
partial: 'activities/post',
layout: false,
formats: :html,
locals: { activity: object }
)
end
end
문제는이 코드가 undefined method 'host' for nil:NilClass
을 올릴 것입니다. 위의 코드에서 볼 수 있듯이 include Rails.application.routes.url_helpers
을 시도했지만 행운은 없었습니다. 여전히 작동하지 않습니다.
나는 레일 애플 리케이션을 재시작하려했지만 운이 없다. 이 문제를 해결하는 방법에 대한
%article.comment-item.m-t
= link_to profile_url(activity.user), class: "pull-left thumb-sm avatar" do
= display_picture_for activity.user, resizing_by: "36x36"
아이디어 : 문제가 내 부분에 사용하고있어 link_to
방법에서 오는이 날 것으로 보인다거야?
멋진 동료, 당신은 내 일했다. 감사 – lkartono