링크를 클릭하면 뷰 HTML에서이 코드를 팝업으로 가져오고 싶습니다. Ruby on Rails에서 가능합니까? 데프뷰에서 코드를 뷰어로 가져 오기
<%= link_to "Link", comment, :remote => true %>
Comments
<% end %></div></div>
<div id ="modal" class = "comments"><% if post.comments.exists? %>
<% post.comments.each do |comment| %>
<%= link_to comment.user.name, comment.user %>
<span class="timestamp"><%= time_ago_in_words(comment.created_at) %> ago</span>
<span class="content2"><%= comment.comment_content %></span>
<% end %>
<% end %></div>
추가를 _comment_form.html.erb 의견 컨트롤러로 보여
<div class = "comments"><% if post.comments.exists? %>
<% post.comments.each do |comment| %>
<%= image_tag("http://www.gravatar.com/someavatarlink %) <!-- Retrieves Gravatar -->
<%= link_to comment.user.name, comment.user %>
<span class="timestamp"><%= time_ago_in_words(comment.created_at) %> ago</span>
<span class="content2"><%= comment.comment_content %></span>
<% end %>
<% end %></div>
추가 Ajax 호출 : 이미 팝업이 작동하지만이 코드는 단지 의견을 보여 대해 궁금하네요 있습니다
class CommentsController < ApplicationController
def new
@post = post.new(params[:post])
end
def show
@comment = Comment.find(params[:id])
respond_to do |format|
format.js
end
def create
@post = post.find(params[:micropost_id])
@comment = Comment.new(params[:comment])
@comment.post = @post
@comment.user = current_user
if @comment.save
redirect_to(:back)
else
render 'shared/_comment_form'
end
end
end
만든 show.erb.js와 '댓글'과 '공유'폴더
에 넣어그런 다음 마지막으로 의견/_comment.html.erb에있는 나의 부분을 썼다
<% if post.comments.exists? %>
<% post.comments.each do |comment| %>
<%= link_to comment.user.name, comment.user %>
<span class="timestamp"><%= time_ago_in_words(comment.created_at) %> ago</span>
<span class="content2"><%= comment.comment_content %></span>
<% end %>
<% end %>
하지만 빠른 질문이 있습니다. 내 원본 게시물에 위의 코드를 '공유/주석'에 넣었으며 파일 이름은 _comment.html.erb입니다. 여기에서 <% = link_to %>를 사용하여 팝업에서보기를 렌더링 할 수 있습니까? – user2159586
참고 - 팝업 만들기는 이미 작동하고 있습니다 (나는 facebox를 사용하고 있습니다). 내 문제는 link_to 코드가 원래 게시물에 위의 코드가 주어져야하는지 파악하려고 시도하고 있습니다. – user2159586
링크는 "원격"링크 여야합니다. 나는 대답을 업데이트했다. 나는 당신이 보여주고 싶은 것을 조금 혼란스러워합니다. 그것은 '사용자'또는 '의견'입니까? 코드를 수정하는 방법을 알아낼 것입니다. – deepflame