我是rails的新手,我想实现Post功能。我也使用主动管理员。 所以我的想法是在我的迁移文件中添加一个新的字符串,所以我可以给帖子一个主题来区分我的帖子并显示一个带主题的帖子" xyz"在网站" xyz"。但是,如果我尝试创建一个新帖子,它会给我错误:
未定义的方法`主题' for #Post:0x000000000f37b2c0并抛出post.rb中的错误:f.input:theme
我的迁移文件如下:
class CreatePosts < ActiveRecord::Migration[5.1]
def change
create_table :posts do |t|
t.string :title
t.text :body
t.string :theme
t.timestamps
end
和来自活动管理员的post.rb:
ActiveAdmin.register Post do
permit_params :title, :body, :theme, :publisher_id
permit_params :title, :body, :theme, :image
show do |t|
attributes_table do
row :title
row :body
row :theme
row :image do
post.image? ? image_tag(post.image.url, height: '100') : content_tag(:span, "No photo yet")
end
end
end
form :html => { :enctype => "multipart/form-data"} do |f|
f.inputs do
f.input :title
f.input :body
f.input :theme
f.input :image, hint: f.post.image? ? image_tag(post.image.url, height: '100') : content_tag(:span, "Upload JPG/PNG/GIF image" )
end
f.actions
end
以后我想做类似
的事情if posts.theme = xyz do
<h1><%= @post.title %></h1>
<h2> <%= @post.body %></h2>
end
我做错了什么?