2017-09-04 3 views
0

나는 루비 온 레일스 튜토리얼을 따르고있다. 게시물에 캡션 옆에 대괄호 안에 내 게시물 정보가 표시됩니다. 고칠 방법을 알고 있다면 도와주세요! 예 =>레일에 게시물 정보가 표시되는 대괄호?

"! PHOTOGRAM 첫 소식 [# < 우편 번호 : 1, 자막"PHOTOGRAM 첫 포스트 "created_at :"2017년 9월 4일 3시 24분 25초 "updated_at : "2017-09-04 03:24:25", image_file_name : "instagram.jpg", image_content_type : "image/jpeg", image_file_size : 64169, image_updated_at : "2017-09-04 03:24:24 ">]"

소식 제어기

class PostsController < ApplicationController 

    def index 
    @posts = Post.all 
    end 
    def new 
    @post = Post.new 
    end 

    def create 
    @post = Post.create(post_params) 
    redirect_to posts_path 
    end 

    private 

    def post_params 
    params.require(:post).permit(:image, :caption) 
    end 
end 
,745,

응용 프로그램/조회/게시물/index.html.erb

<h1> Photogram </h1> 

<%= @posts.each do |post| %> 
    <%= image_tag post.image.url(:medium) %> 
    <%= post.caption %> 
<% end %> 

new.html.erb

<%= form_for(@post) do |f| %> 
    <%= f.file_field :image %> 
    <%= f.text_field :caption %> 
    <%= f.submit %> 
<% end %> 
+4

(이 대답은 그냥 발언과 설명과 함께, 자신의 의견에 말을 "최대 pleaner"기본적으로) @ posts.each do | post | %>'는'<%'을 여는 태그로 사용해야합니다. –

답변

0

변경하여 index.html.erb

<% @posts.each do |post| %> 
    <%= image_tag post.image.url(:medium) %> 
    <%= post.caption %> 
<% end %> 

에 (된 = 참고 제거됨)

루비에서 모든 진술에 대한 답변이 있습니다 값. nil 일 수도 있지만 다른 프로그래밍 언어로 알려진 void은 없습니다. ERB 열기 태그 <%=은 다음 루비 코드를 출력합니다. 따라서이 코드 줄은 @posts에있는 모든 게시물을 출력합니다.

이 당신이 있지만 '<% = 약 게시하는 문제를 해결할 수 있는지 모르겠어요