我将我的rails应用程序部署到了Heroku。我正在尝试使用Heroku控制台为我的应用添加类别,但我不知道命令。
控制器:
class PortfolioController < ApplicationController
def index
@posts = Post.all.order("created_at DESC")
end
def about
end
def portfolio
end
def contact
end
def webapp
category = Category.find_by_category('webapp')
@posts = Post.where(category_id: category.id)
end
def art
category = Category.find_by_category('gameart')
@posts = Post.where(category_id: category.id)
end
end
架构:
ActiveRecord::Schema.define(version: 20160910220215) do
create_table "admins", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "admins", ["email"], name: "index_admins_on_email", unique: true
add_index "admins", ["reset_password_token"], name: "index_admins_on_reset_password_token", unique: true
create_table "categories", force: :cascade do |t|
t.string "category"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "posts", force: :cascade do |t|
t.string "title"
t.text "content"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "image_file_name"
t.string "image_content_type"
t.integer "image_file_size"
t.datetime "image_updated_at"
t.integer "category_id"
end
end
答案 0 :(得分:0)
要在表servicesToRun
下的rails / heroku控制台中创建一个类别,只需运行:
Categories
然后:
Category.connection
然后它将创建一个类别:
Category.create(name: "NAME_OF_CATEGORY")