【发布时间】:2017-09-04 00:46:05
【问题描述】:
我正在关注 ruby on rails 教程。我的帖子信息显示在帖子标题旁边的括号中。如果您知道如何解决它,请帮助!
Example=> "PHOTOGRAM 上的第一篇文章![#
]"
帖子控制器
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
app/views/posts/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 %>
【问题讨论】:
-
我不知道这是否能解决您发布的问题,但
<%= @posts.each do |post| %>应该使用<%作为开始标签。
标签: ruby-on-rails ruby rubygems paperclip ruby-on-rails-5