Admin::Colleges#index 中的 ActiveRecord::StatementInvalid
这是我第一次使用 Active Admin 添加后端。我的 Rails 应用程序的用户端 http://localhost:3000/colleges 工作正常,但在我的管理部分 http://localhost:3000/admin/colleges 它会出现以下错误。我已经尝试了堆栈溢出的一些解决方案,但到目前为止没有答案与我的错误有关。
ActiveRecord::StatementInvalid in Admin::Colleges#index
Showing /home/.../.rvm/gems/ruby-2.6.3/gems/activeadmin-2.9.0/app/views/active_admin/resource/index.html.arb where line #2 raised:
SQLite3::SQLException: no such table: rates: SELECT "rates".* FROM "rates"
#
def prepare sql
stmt = SQLite3::Statement.new( self, sql )
return stmt unless block_given?
begin
这是我的文件 Colleges/index.html.erb
<h1>Colleges</h1>
<% @colleges.in_groups_of(5) do |group| %>
<div class="row">
<% group.compact.each do |college| %>
<div class="col-md-4">
<%= image_tag college.picture_url, width: '100%' if college.picture.present? %>
<h4><%= link_to college.name, college %></h4>
<%= college.description %>
</div>
<% end %>
</div>
<% end %>
<p id="notice"><%= notice %></p>
下面是我的 Colleges_controller.rb
class CollegesController < ApplicationController
before_action :set_college, only: %i[ show edit update destroy ]
# GET /colleges or /colleges.json
def index
@colleges = College.all
end
# GET /colleges/1 or /colleges/1.json
def show
@comments = @college.comments.all
@comment = @college.comments.build
end
# GET /colleges/new
def new
@college = College.new
end
# GET /colleges/1/edit
def edit
end
# POST /colleges or /colleges.json
def create
@college = College.new(college_params)
respond_to do |format|
if @college.save
format.html { redirect_to college_url(@college), notice: "College was successfully created." }
format.json { render :show, status: :created, location: @college }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @college.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /colleges/1 or /colleges/1.json
def update
respond_to do |format|
if @college.update(college_params)
format.html { redirect_to college_url(@college), notice: "College was successfully updated." }
format.json { render :show, status: :ok, location: @college }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @college.errors, status: :unprocessable_entity }
end
end
end
# DELETE /colleges/1 or /colleges/1.json
def destroy
@college.destroy
respond_to do |format|
format.html { redirect_to colleges_url, notice: "College was successfully destroyed." }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_college
@college = College.find(params[:id])
end
# Only allow a list of trusted parameters through.
def college_params
params.require(:college).permit(:name, :description, :picture, :rating, :apply)
end
end
schema.rb
ActiveRecord::Schema.define(version: 2022_03_02_115834) do
create_table "admin_users", 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.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["email"], name: "index_admin_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_admin_users_on_reset_password_token", unique: true
end
create_table "colleges", force: :cascade do |t|
t.string "region"
t.string "name"
t.text "description"
t.string "picture"
t.string "apply"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "seralno"
end
create_table "comments", force: :cascade do |t|
t.string "user_name"
t.text "body"
t.string "college_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "users", 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.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end
end
stacktrace
sqlite3 (1.4.2) lib/sqlite3/database.rb:147:in `initialize'
sqlite3 (1.4.2) lib/sqlite3/database.rb:147:in `new'
sqlite3 (1.4.2) lib/sqlite3/database.rb:147:in `prepare'
activerecord (5.2.6.2) lib/active_record/connection_adapters/sqlite3_adapter.rb:228:in `block (2 levels) in exec_query'
activesupport (5.2.6.2) lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads'
activesupport (5.2.6.2) lib/active_support/concurrency/share_lock.rb:187:in `yield_shares'
activesupport (5.2.6.2) lib/active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads'
activerecord (5.2.6.2) lib/active_record/connection_adapters/sqlite3_adapter.rb:213:in `block in exec_query'
activerecord (5.2.6.2) lib/active_record/connection_adapters/abstract_adapter.rb:581:in `block (2 levels) in log'
/home/gatwiri/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/monitor.rb:230:in `mon_synchronize'
activerecord (5.2.6.2) lib/active_record/connection_adapters/abstract_adapter.rb:580:in `block in log'
activesupport (5.2.6.2) lib/active_support/notifications/instrumenter.rb:23:in `instrument'
activerecord (5.2.6.2) lib/active_record/connection_adapters/abstract_adapter.rb:571:in `log'
activerecord (5.2.6.2) lib/active_record/connection_adapters/sqlite3_adapter.rb:212:in `exec_query'
activerecord (5.2.6.2) lib/active_record/connection_adapters/abstract/database_statements.rb:482:in `select_prepared'
activerecord (5.2.6.2) lib/active_record/connection_adapters/abstract/database_statements.rb:68:in `select_all'
activerecord (5.2.6.2) lib/active_record/connection_adapters/abstract/query_cache.rb:104:in `block in select_all'
activerecord (5.2.6.2) lib/active_record/connection_adapters/abstract/query_cache.rb:127:in `block in cache_sql'
/home/gatwiri/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/monitor.rb:230:in `mon_synchronize'
activerecord (5.2.6.2) lib/active_record/connection_adapters/abstract/query_cache.rb:113:in `cache_sql'
activerecord (5.2.6.2) lib/active_record/connection_adapters/abstract/query_cache.rb:104:in `select_all'
activerecord (5.2.6.2) lib/active_record/querying.rb:41:in `find_by_sql'
activerecord (5.2.6.2) lib/active_record/relation.rb:560:in `block in exec_queries'
activerecord (5.2.6.2) lib/active_record/relation.rb:584:in `skip_query_cache_if_necessary'
activerecord (5.2.6.2) lib/active_record/relation.rb:547:in `exec_queries'
activerecord (5.2.6.2) lib/active_record/relation.rb:422:in `load'
activerecord (5.2.6.2) lib/active_record/relation.rb:200:in `records'
activerecord (5.2.6.2) lib/active_record/relation/delegation.rb:71:in `each'
formtastic (4.0.0) lib/formtastic/inputs/base/collections.rb:58:in `map'
formtastic (4.0.0) lib/formtastic/inputs/base/collections.rb:58:in `collection'
activeadmin (2.9.0) lib/active_admin/inputs/filters/select_input.rb:43:in `collection'
formtastic (4.0.0) lib/formtastic/inputs/select_input.rb:173:in `select_html'
formtastic (4.0.0) lib/formtastic/inputs/select_input.rb:168:in `block in to_html'
actionview (5.2.6.2) lib/action_view/helpers/capture_helper.rb:41:in `block in capture'
actionview (5.2.6.2) lib/action_view/helpers/capture_helper.rb:205:in `with_output_buffer'
actionview (5.2.6.2) lib/action_view/helpers/capture_helper.rb:41:in `capture'
activeadmin (2.9.0) lib/active_admin/inputs/filters/base.rb:12:in `input_wrapping'
formtastic (4.0.0) lib/formtastic/inputs/select_input.rb:166:in `to_html'
formtastic (4.0.0) lib/formtastic/helpers/input_helper.rb:239:in `input'
activeadmin (2.9.0) lib/active_admin/filters/forms.rb:14:in `filter'
activeadmin (2.9.0) lib/active_admin/filters/forms.rb:64:in `block (2 levels) in active_admin_filters_form_for'
activeadmin (2.9.0) lib/active_admin/filters/forms.rb:57:in `each'
activeadmin (2.9.0) lib/active_admin/filters/forms.rb:57:in `block in active_admin_filters_form_for'
actionview (5.2.6.2) lib/action_view/helpers/capture_helper.rb:41:in `block in capture'
actionview (5.2.6.2) lib/action_view/helpers/capture_helper.rb:205:in `with_output_buffer'
actionview (5.2.6.2) lib/action_view/helpers/capture_helper.rb:41:in `capture'
actionview (5.2.6.2) lib/action_view/helpers/form_helper.rb:452:in `form_for'
activeadmin (2.9.0) lib/active_admin/filters/forms.rb:56:in `active_admin_filters_form_for'
arbre (1.5.0) lib/arbre/element.rb:183:in `method_missing'
activeadmin (2.9.0) lib/active_admin/filters/resource_extension.rb:168:in `block in filters_sidebar_section'
activeadmin (2.9.0) lib/active_admin/views/components/sidebar_section.rb:25:in `instance_exec'
activeadmin (2.9.0) lib/active_admin/views/components/sidebar_section.rb:25:in `build_sidebar_content'
activeadmin (2.9.0) lib/active_admin/views/components/sidebar_section.rb:13:in `build'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:31:in `block in build_tag'
arbre (1.5.0) lib/arbre/context.rb:94:in `with_current_arbre_element'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:50:in `with_current_arbre_element'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:27:in `build_tag'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:40:in `insert_tag'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:15:in `sidebar_section'
activeadmin (2.9.0) lib/active_admin/views/components/sidebar.rb:9:in `map'
activeadmin (2.9.0) lib/active_admin/views/components/sidebar.rb:9:in `build'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:31:in `block in build_tag'
arbre (1.5.0) lib/arbre/context.rb:94:in `with_current_arbre_element'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:50:in `with_current_arbre_element'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:27:in `build_tag'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:40:in `insert_tag'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:15:in `sidebar'
activeadmin (2.9.0) lib/active_admin/views/pages/base.rb:84:in `block in build_page_content'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:32:in `block in build_tag'
arbre (1.5.0) lib/arbre/context.rb:94:in `with_current_arbre_element'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:50:in `with_current_arbre_element'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:27:in `build_tag'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:40:in `insert_tag'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:15:in `div'
activeadmin (2.9.0) lib/active_admin/views/pages/base.rb:82:in `build_page_content'
activeadmin (2.9.0) lib/active_admin/views/pages/base.rb:59:in `block (2 levels) in build_page'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:32:in `block in build_tag'
arbre (1.5.0) lib/arbre/context.rb:94:in `with_current_arbre_element'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:50:in `with_current_arbre_element'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:27:in `build_tag'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:40:in `insert_tag'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:15:in `div'
activeadmin (2.9.0) lib/active_admin/views/pages/base.rb:55:in `block in build_page'
arbre (1.5.0) lib/arbre/context.rb:94:in `with_current_arbre_element'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:50:in `with_current_arbre_element'
activeadmin (2.9.0) lib/active_admin/views/pages/base.rb:54:in `build_page'
activeadmin (2.9.0) lib/active_admin/views/pages/base.rb:9:in `build'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:31:in `block in build_tag'
arbre (1.5.0) lib/arbre/context.rb:94:in `with_current_arbre_element'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:27:in `build_tag'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:40:in `insert_tag'
activeadmin (2.9.0) app/views/active_admin/resource/index.html.arb:2:in `block in __home_gatwiri__rvm_gems_ruby_______gems_activeadmin_______app_views_active_admin_resource_index_html_arb__856722158634028848_70301165774920'
arbre (1.5.0) lib/arbre/context.rb:47:in `instance_eval'
arbre (1.5.0) lib/arbre/context.rb:47:in `initialize'
activeadmin (2.9.0) app/views/active_admin/resource/index.html.arb:1:in `new'
activeadmin (2.9.0) app/views/active_admin/resource/index.html.arb:1:in `__home_gatwiri__rvm_gems_ruby_______gems_activeadmin_______app_views_active_admin_resource_index_html_arb__856722158634028848_70301165774920'
actionview (5.2.6.2) lib/action_view/template.rb:159:in `block in render'
activesupport (5.2.6.2) lib/active_support/notifications.rb:170:in `instrument'
actionview (5.2.6.2) lib/action_view/template.rb:354:in `instrument_render_template'
actionview (5.2.6.2) lib/action_view/template.rb:157:in `render'
actionview (5.2.6.2) lib/action_view/renderer/template_renderer.rb:54:in `block (2 levels) in render_template'
actionview (5.2.6.2) lib/action_view/renderer/abstract_renderer.rb:44:in `block in instrument'
activesupport (5.2.6.2) lib/active_support/notifications.rb:168:in `block in instrument'
activesupport (5.2.6.2) lib/active_support/notifications/instrumenter.rb:23:in `instrument'
activesupport (5.2.6.2) lib/active_support/notifications.rb:168:in `instrument'
actionview (5.2.6.2) lib/action_view/renderer/abstract_renderer.rb:43:in `instrument'
actionview (5.2.6.2) lib/action_view/renderer/template_renderer.rb:53:in `block in render_template'
actionview (5.2.6.2) lib/action_view/renderer/template_renderer.rb:61:in `render_with_layout'
actionview (5.2.6.2) lib/action_view/renderer/template_renderer.rb:52:in `render_template'
actionview (5.2.6.2) lib/action_view/renderer/template_renderer.rb:16:in `render'
actionview (5.2.6.2) lib/action_view/renderer/renderer.rb:44:in `render_template'
actionview (5.2.6.2) lib/action_view/renderer/renderer.rb:25:in `render'
actionview (5.2.6.2) lib/action_view/rendering.rb:103:in `_render_template'
actionpack (5.2.6.2) lib/action_controller/metal/streaming.rb:219:in `_render_template'
actionview (5.2.6.2) lib/action_view/rendering.rb:84:in `render_to_body'
actionpack (5.2.6.2) lib/action_controller/metal/rendering.rb:52:in `render_to_body'
actionpack (5.2.6.2) lib/action_controller/metal/renderers.rb:142:in `render_to_body'
actionpack (5.2.6.2) lib/abstract_controller/rendering.rb:25:in `render'
actionpack (5.2.6.2) lib/action_controller/metal/rendering.rb:36:in `render'
actionpack (5.2.6.2) lib/action_controller/metal/instrumentation.rb:46:in `block (2 levels) in render'
activesupport (5.2.6.2) lib/active_support/core_ext/benchmark.rb:14:in `block in ms'
/home/gatwiri/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/benchmark.rb:308:in `realtime'
activesupport (5.2.6.2) lib/active_support/core_ext/benchmark.rb:14:in `ms'
actionpack (5.2.6.2) lib/action_controller/metal/instrumentation.rb:46:in `block in render'
actionpack (5.2.6.2) lib/action_controller/metal/instrumentation.rb:87:in `cleanup_view_runtime'
activerecord (5.2.6.2) lib/active_record/railties/controller_runtime.rb:31:in `cleanup_view_runtime'
actionpack (5.2.6.2) lib/action_controller/metal/instrumentation.rb:45:in `render'
responders (3.0.1) lib/action_controller/responder.rb:240:in `default_render'
responders (3.0.1) lib/action_controller/responder.rb:172:in `to_html'
responders (3.0.1) lib/responders/flash_responder.rb:109:in `to_html'
responders (3.0.1) lib/action_controller/responder.rb:165:in `respond'
responders (3.0.1) lib/action_controller/responder.rb:158:in `call'
responders (3.0.1) lib/action_controller/respond_with.rb:213:in `respond_with'
inherited_resources (1.13.1) lib/inherited_resources/actions.rb:7:in `index'
activeadmin (2.9.0) lib/active_admin/resource_controller/streaming.rb:12:in `index'
actionpack (5.2.6.2) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
actionpack (5.2.6.2) lib/abstract_controller/base.rb:194:in `process_action'
actionpack (5.2.6.2) lib/action_controller/metal/rendering.rb:30:in `process_action'
actionpack (5.2.6.2) lib/abstract_controller/callbacks.rb:42:in `block in process_action'
activesupport (5.2.6.2) lib/active_support/callbacks.rb:132:in `run_callbacks'
actionpack (5.2.6.2) lib/abstract_controller/callbacks.rb:41:in `process_action'
actionpack (5.2.6.2) lib/action_controller/metal/rescue.rb:22:in `process_action'
actionpack (5.2.6.2) lib/action_controller/metal/instrumentation.rb:34:in `block in process_action'
activesupport (5.2.6.2) lib/active_support/notifications.rb:168:in `block in instrument'
activesupport (5.2.6.2) lib/active_support/notifications/instrumenter.rb:23:in `instrument'
activesupport (5.2.6.2) lib/active_support/notifications.rb:168:in `instrument'
actionpack (5.2.6.2) lib/action_controller/metal/instrumentation.rb:32:in `process_action'
actionpack (5.2.6.2) lib/action_controller/metal/params_wrapper.rb:256:in `process_action'
activerecord (5.2.6.2) lib/active_record/railties/controller_runtime.rb:24:in `process_action'
actionpack (5.2.6.2) lib/abstract_controller/base.rb:134:in `process'
actionview (5.2.6.2) lib/action_view/rendering.rb:32:in `process'
actionpack (5.2.6.2) lib/action_controller/metal.rb:191:in `dispatch'
actionpack (5.2.6.2) lib/action_controller/metal.rb:252:in `dispatch'
actionpack (5.2.6.2) lib/action_dispatch/routing/route_set.rb:52:in `dispatch'
actionpack (5.2.6.2) lib/action_dispatch/routing/route_set.rb:34:in `serve'
actionpack (5.2.6.2) lib/action_dispatch/journey/router.rb:52:in `block in serve'
actionpack (5.2.6.2) lib/action_dispatch/journey/router.rb:35:in `each'
actionpack (5.2.6.2) lib/action_dispatch/journey/router.rb:35:in `serve'
actionpack (5.2.6.2) lib/action_dispatch/routing/route_set.rb:840:in `call'
warden (1.2.9) lib/warden/manager.rb:36:in `block in call'
warden (1.2.9) lib/warden/manager.rb:34:in `catch'
warden (1.2.9) lib/warden/manager.rb:34:in `call'
rack (2.2.3) lib/rack/tempfile_reaper.rb:15:in `call'
rack (2.2.3) lib/rack/etag.rb:27:in `call'
rack (2.2.3) lib/rack/conditional_get.rb:27:in `call'
rack (2.2.3) lib/rack/head.rb:12:in `call'
actionpack (5.2.6.2) lib/action_dispatch/http/content_security_policy.rb:18:in `call'
rack (2.2.3) lib/rack/session/abstract/id.rb:266:in `context'
rack (2.2.3) lib/rack/session/abstract/id.rb:260:in `call'
actionpack (5.2.6.2) lib/action_dispatch/middleware/cookies.rb:670:in `call'
actionpack (5.2.6.2) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (5.2.6.2) lib/active_support/callbacks.rb:98:in `run_callbacks'
actionpack (5.2.6.2) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
actionpack (5.2.6.2) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (5.2.6.2) lib/action_dispatch/middleware/debug_exceptions.rb:61:in `call'
web-console (3.7.0) lib/web_console/middleware.rb:135:in `call_app'
web-console (3.7.0) lib/web_console/middleware.rb:30:in `block in call'
web-console (3.7.0) lib/web_console/middleware.rb:20:in `catch'
web-console (3.7.0) lib/web_console/middleware.rb:20:in `call'
actionpack (5.2.6.2) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (5.2.6.2) lib/rails/rack/logger.rb:38:in `call_app'
railties (5.2.6.2) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (5.2.6.2) lib/active_support/tagged_logging.rb:71:in `block in tagged'
activesupport (5.2.6.2) lib/active_support/tagged_logging.rb:28:in `tagged'
activesupport (5.2.6.2) lib/active_support/tagged_logging.rb:71:in `tagged'
railties (5.2.6.2) lib/rails/rack/logger.rb:26:in `call'
sprockets-rails (3.4.2) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (5.2.6.2) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
request_store (1.5.1) lib/request_store/middleware.rb:19:in `call'
actionpack (5.2.6.2) lib/action_dispatch/middleware/request_id.rb:27:in `call'
rack (2.2.3) lib/rack/method_override.rb:24:in `call'
rack (2.2.3) lib/rack/runtime.rb:22:in `call'
activesupport (5.2.6.2) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (5.2.6.2) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (5.2.6.2) lib/action_dispatch/middleware/static.rb:127:in `call'
rack (2.2.3) lib/rack/sendfile.rb:110:in `call'
railties (5.2.6.2) lib/rails/engine.rb:524:in `call'
puma (3.12.6) lib/puma/configuration.rb:227:in `call'
puma (3.12.6) lib/puma/server.rb:706:in `handle_request'
puma (3.12.6) lib/puma/server.rb:476:in `process_client'
puma (3.12.6) lib/puma/server.rb:334:in `block in run'
puma (3.12.6) lib/puma/thread_pool.rb:135:in `block in spawn_thread'
model.rb
class College < ApplicationRecord
has_many :comments
ratyrate_rateable 'culture', 'original_score', 'resources', 'academic_support'
mount_uploader :picture, PictureUploader
end
This is my first time working on Adding a back-end with Active Admin. The user side of my rails app http://localhost:3000/colleges is working fine but in my admin section http://localhost:3000/admin/colleges it's bringing up the following error. I have tried some solutions from stack overflow but no answer is relating to my error so far.
ActiveRecord::StatementInvalid in Admin::Colleges#index
Showing /home/.../.rvm/gems/ruby-2.6.3/gems/activeadmin-2.9.0/app/views/active_admin/resource/index.html.arb where line #2 raised:
SQLite3::SQLException: no such table: rates: SELECT "rates".* FROM "rates"
#
def prepare sql
stmt = SQLite3::Statement.new( self, sql )
return stmt unless block_given?
begin
here is my files
colleges/index.html.erb
<h1>Colleges</h1>
<% @colleges.in_groups_of(5) do |group| %>
<div class="row">
<% group.compact.each do |college| %>
<div class="col-md-4">
<%= image_tag college.picture_url, width: '100%' if college.picture.present? %>
<h4><%= link_to college.name, college %></h4>
<%= college.description %>
</div>
<% end %>
</div>
<% end %>
<p id="notice"><%= notice %></p>
Below is my colleges_controller.rb
class CollegesController < ApplicationController
before_action :set_college, only: %i[ show edit update destroy ]
# GET /colleges or /colleges.json
def index
@colleges = College.all
end
# GET /colleges/1 or /colleges/1.json
def show
@comments = @college.comments.all
@comment = @college.comments.build
end
# GET /colleges/new
def new
@college = College.new
end
# GET /colleges/1/edit
def edit
end
# POST /colleges or /colleges.json
def create
@college = College.new(college_params)
respond_to do |format|
if @college.save
format.html { redirect_to college_url(@college), notice: "College was successfully created." }
format.json { render :show, status: :created, location: @college }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @college.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /colleges/1 or /colleges/1.json
def update
respond_to do |format|
if @college.update(college_params)
format.html { redirect_to college_url(@college), notice: "College was successfully updated." }
format.json { render :show, status: :ok, location: @college }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @college.errors, status: :unprocessable_entity }
end
end
end
# DELETE /colleges/1 or /colleges/1.json
def destroy
@college.destroy
respond_to do |format|
format.html { redirect_to colleges_url, notice: "College was successfully destroyed." }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_college
@college = College.find(params[:id])
end
# Only allow a list of trusted parameters through.
def college_params
params.require(:college).permit(:name, :description, :picture, :rating, :apply)
end
end
schema.rb
ActiveRecord::Schema.define(version: 2022_03_02_115834) do
create_table "admin_users", 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.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["email"], name: "index_admin_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_admin_users_on_reset_password_token", unique: true
end
create_table "colleges", force: :cascade do |t|
t.string "region"
t.string "name"
t.text "description"
t.string "picture"
t.string "apply"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "seralno"
end
create_table "comments", force: :cascade do |t|
t.string "user_name"
t.text "body"
t.string "college_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "users", 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.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end
end
stacktrace
sqlite3 (1.4.2) lib/sqlite3/database.rb:147:in `initialize'
sqlite3 (1.4.2) lib/sqlite3/database.rb:147:in `new'
sqlite3 (1.4.2) lib/sqlite3/database.rb:147:in `prepare'
activerecord (5.2.6.2) lib/active_record/connection_adapters/sqlite3_adapter.rb:228:in `block (2 levels) in exec_query'
activesupport (5.2.6.2) lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads'
activesupport (5.2.6.2) lib/active_support/concurrency/share_lock.rb:187:in `yield_shares'
activesupport (5.2.6.2) lib/active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads'
activerecord (5.2.6.2) lib/active_record/connection_adapters/sqlite3_adapter.rb:213:in `block in exec_query'
activerecord (5.2.6.2) lib/active_record/connection_adapters/abstract_adapter.rb:581:in `block (2 levels) in log'
/home/gatwiri/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/monitor.rb:230:in `mon_synchronize'
activerecord (5.2.6.2) lib/active_record/connection_adapters/abstract_adapter.rb:580:in `block in log'
activesupport (5.2.6.2) lib/active_support/notifications/instrumenter.rb:23:in `instrument'
activerecord (5.2.6.2) lib/active_record/connection_adapters/abstract_adapter.rb:571:in `log'
activerecord (5.2.6.2) lib/active_record/connection_adapters/sqlite3_adapter.rb:212:in `exec_query'
activerecord (5.2.6.2) lib/active_record/connection_adapters/abstract/database_statements.rb:482:in `select_prepared'
activerecord (5.2.6.2) lib/active_record/connection_adapters/abstract/database_statements.rb:68:in `select_all'
activerecord (5.2.6.2) lib/active_record/connection_adapters/abstract/query_cache.rb:104:in `block in select_all'
activerecord (5.2.6.2) lib/active_record/connection_adapters/abstract/query_cache.rb:127:in `block in cache_sql'
/home/gatwiri/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/monitor.rb:230:in `mon_synchronize'
activerecord (5.2.6.2) lib/active_record/connection_adapters/abstract/query_cache.rb:113:in `cache_sql'
activerecord (5.2.6.2) lib/active_record/connection_adapters/abstract/query_cache.rb:104:in `select_all'
activerecord (5.2.6.2) lib/active_record/querying.rb:41:in `find_by_sql'
activerecord (5.2.6.2) lib/active_record/relation.rb:560:in `block in exec_queries'
activerecord (5.2.6.2) lib/active_record/relation.rb:584:in `skip_query_cache_if_necessary'
activerecord (5.2.6.2) lib/active_record/relation.rb:547:in `exec_queries'
activerecord (5.2.6.2) lib/active_record/relation.rb:422:in `load'
activerecord (5.2.6.2) lib/active_record/relation.rb:200:in `records'
activerecord (5.2.6.2) lib/active_record/relation/delegation.rb:71:in `each'
formtastic (4.0.0) lib/formtastic/inputs/base/collections.rb:58:in `map'
formtastic (4.0.0) lib/formtastic/inputs/base/collections.rb:58:in `collection'
activeadmin (2.9.0) lib/active_admin/inputs/filters/select_input.rb:43:in `collection'
formtastic (4.0.0) lib/formtastic/inputs/select_input.rb:173:in `select_html'
formtastic (4.0.0) lib/formtastic/inputs/select_input.rb:168:in `block in to_html'
actionview (5.2.6.2) lib/action_view/helpers/capture_helper.rb:41:in `block in capture'
actionview (5.2.6.2) lib/action_view/helpers/capture_helper.rb:205:in `with_output_buffer'
actionview (5.2.6.2) lib/action_view/helpers/capture_helper.rb:41:in `capture'
activeadmin (2.9.0) lib/active_admin/inputs/filters/base.rb:12:in `input_wrapping'
formtastic (4.0.0) lib/formtastic/inputs/select_input.rb:166:in `to_html'
formtastic (4.0.0) lib/formtastic/helpers/input_helper.rb:239:in `input'
activeadmin (2.9.0) lib/active_admin/filters/forms.rb:14:in `filter'
activeadmin (2.9.0) lib/active_admin/filters/forms.rb:64:in `block (2 levels) in active_admin_filters_form_for'
activeadmin (2.9.0) lib/active_admin/filters/forms.rb:57:in `each'
activeadmin (2.9.0) lib/active_admin/filters/forms.rb:57:in `block in active_admin_filters_form_for'
actionview (5.2.6.2) lib/action_view/helpers/capture_helper.rb:41:in `block in capture'
actionview (5.2.6.2) lib/action_view/helpers/capture_helper.rb:205:in `with_output_buffer'
actionview (5.2.6.2) lib/action_view/helpers/capture_helper.rb:41:in `capture'
actionview (5.2.6.2) lib/action_view/helpers/form_helper.rb:452:in `form_for'
activeadmin (2.9.0) lib/active_admin/filters/forms.rb:56:in `active_admin_filters_form_for'
arbre (1.5.0) lib/arbre/element.rb:183:in `method_missing'
activeadmin (2.9.0) lib/active_admin/filters/resource_extension.rb:168:in `block in filters_sidebar_section'
activeadmin (2.9.0) lib/active_admin/views/components/sidebar_section.rb:25:in `instance_exec'
activeadmin (2.9.0) lib/active_admin/views/components/sidebar_section.rb:25:in `build_sidebar_content'
activeadmin (2.9.0) lib/active_admin/views/components/sidebar_section.rb:13:in `build'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:31:in `block in build_tag'
arbre (1.5.0) lib/arbre/context.rb:94:in `with_current_arbre_element'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:50:in `with_current_arbre_element'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:27:in `build_tag'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:40:in `insert_tag'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:15:in `sidebar_section'
activeadmin (2.9.0) lib/active_admin/views/components/sidebar.rb:9:in `map'
activeadmin (2.9.0) lib/active_admin/views/components/sidebar.rb:9:in `build'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:31:in `block in build_tag'
arbre (1.5.0) lib/arbre/context.rb:94:in `with_current_arbre_element'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:50:in `with_current_arbre_element'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:27:in `build_tag'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:40:in `insert_tag'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:15:in `sidebar'
activeadmin (2.9.0) lib/active_admin/views/pages/base.rb:84:in `block in build_page_content'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:32:in `block in build_tag'
arbre (1.5.0) lib/arbre/context.rb:94:in `with_current_arbre_element'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:50:in `with_current_arbre_element'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:27:in `build_tag'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:40:in `insert_tag'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:15:in `div'
activeadmin (2.9.0) lib/active_admin/views/pages/base.rb:82:in `build_page_content'
activeadmin (2.9.0) lib/active_admin/views/pages/base.rb:59:in `block (2 levels) in build_page'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:32:in `block in build_tag'
arbre (1.5.0) lib/arbre/context.rb:94:in `with_current_arbre_element'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:50:in `with_current_arbre_element'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:27:in `build_tag'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:40:in `insert_tag'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:15:in `div'
activeadmin (2.9.0) lib/active_admin/views/pages/base.rb:55:in `block in build_page'
arbre (1.5.0) lib/arbre/context.rb:94:in `with_current_arbre_element'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:50:in `with_current_arbre_element'
activeadmin (2.9.0) lib/active_admin/views/pages/base.rb:54:in `build_page'
activeadmin (2.9.0) lib/active_admin/views/pages/base.rb:9:in `build'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:31:in `block in build_tag'
arbre (1.5.0) lib/arbre/context.rb:94:in `with_current_arbre_element'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:27:in `build_tag'
arbre (1.5.0) lib/arbre/element/builder_methods.rb:40:in `insert_tag'
activeadmin (2.9.0) app/views/active_admin/resource/index.html.arb:2:in `block in __home_gatwiri__rvm_gems_ruby_______gems_activeadmin_______app_views_active_admin_resource_index_html_arb__856722158634028848_70301165774920'
arbre (1.5.0) lib/arbre/context.rb:47:in `instance_eval'
arbre (1.5.0) lib/arbre/context.rb:47:in `initialize'
activeadmin (2.9.0) app/views/active_admin/resource/index.html.arb:1:in `new'
activeadmin (2.9.0) app/views/active_admin/resource/index.html.arb:1:in `__home_gatwiri__rvm_gems_ruby_______gems_activeadmin_______app_views_active_admin_resource_index_html_arb__856722158634028848_70301165774920'
actionview (5.2.6.2) lib/action_view/template.rb:159:in `block in render'
activesupport (5.2.6.2) lib/active_support/notifications.rb:170:in `instrument'
actionview (5.2.6.2) lib/action_view/template.rb:354:in `instrument_render_template'
actionview (5.2.6.2) lib/action_view/template.rb:157:in `render'
actionview (5.2.6.2) lib/action_view/renderer/template_renderer.rb:54:in `block (2 levels) in render_template'
actionview (5.2.6.2) lib/action_view/renderer/abstract_renderer.rb:44:in `block in instrument'
activesupport (5.2.6.2) lib/active_support/notifications.rb:168:in `block in instrument'
activesupport (5.2.6.2) lib/active_support/notifications/instrumenter.rb:23:in `instrument'
activesupport (5.2.6.2) lib/active_support/notifications.rb:168:in `instrument'
actionview (5.2.6.2) lib/action_view/renderer/abstract_renderer.rb:43:in `instrument'
actionview (5.2.6.2) lib/action_view/renderer/template_renderer.rb:53:in `block in render_template'
actionview (5.2.6.2) lib/action_view/renderer/template_renderer.rb:61:in `render_with_layout'
actionview (5.2.6.2) lib/action_view/renderer/template_renderer.rb:52:in `render_template'
actionview (5.2.6.2) lib/action_view/renderer/template_renderer.rb:16:in `render'
actionview (5.2.6.2) lib/action_view/renderer/renderer.rb:44:in `render_template'
actionview (5.2.6.2) lib/action_view/renderer/renderer.rb:25:in `render'
actionview (5.2.6.2) lib/action_view/rendering.rb:103:in `_render_template'
actionpack (5.2.6.2) lib/action_controller/metal/streaming.rb:219:in `_render_template'
actionview (5.2.6.2) lib/action_view/rendering.rb:84:in `render_to_body'
actionpack (5.2.6.2) lib/action_controller/metal/rendering.rb:52:in `render_to_body'
actionpack (5.2.6.2) lib/action_controller/metal/renderers.rb:142:in `render_to_body'
actionpack (5.2.6.2) lib/abstract_controller/rendering.rb:25:in `render'
actionpack (5.2.6.2) lib/action_controller/metal/rendering.rb:36:in `render'
actionpack (5.2.6.2) lib/action_controller/metal/instrumentation.rb:46:in `block (2 levels) in render'
activesupport (5.2.6.2) lib/active_support/core_ext/benchmark.rb:14:in `block in ms'
/home/gatwiri/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/benchmark.rb:308:in `realtime'
activesupport (5.2.6.2) lib/active_support/core_ext/benchmark.rb:14:in `ms'
actionpack (5.2.6.2) lib/action_controller/metal/instrumentation.rb:46:in `block in render'
actionpack (5.2.6.2) lib/action_controller/metal/instrumentation.rb:87:in `cleanup_view_runtime'
activerecord (5.2.6.2) lib/active_record/railties/controller_runtime.rb:31:in `cleanup_view_runtime'
actionpack (5.2.6.2) lib/action_controller/metal/instrumentation.rb:45:in `render'
responders (3.0.1) lib/action_controller/responder.rb:240:in `default_render'
responders (3.0.1) lib/action_controller/responder.rb:172:in `to_html'
responders (3.0.1) lib/responders/flash_responder.rb:109:in `to_html'
responders (3.0.1) lib/action_controller/responder.rb:165:in `respond'
responders (3.0.1) lib/action_controller/responder.rb:158:in `call'
responders (3.0.1) lib/action_controller/respond_with.rb:213:in `respond_with'
inherited_resources (1.13.1) lib/inherited_resources/actions.rb:7:in `index'
activeadmin (2.9.0) lib/active_admin/resource_controller/streaming.rb:12:in `index'
actionpack (5.2.6.2) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
actionpack (5.2.6.2) lib/abstract_controller/base.rb:194:in `process_action'
actionpack (5.2.6.2) lib/action_controller/metal/rendering.rb:30:in `process_action'
actionpack (5.2.6.2) lib/abstract_controller/callbacks.rb:42:in `block in process_action'
activesupport (5.2.6.2) lib/active_support/callbacks.rb:132:in `run_callbacks'
actionpack (5.2.6.2) lib/abstract_controller/callbacks.rb:41:in `process_action'
actionpack (5.2.6.2) lib/action_controller/metal/rescue.rb:22:in `process_action'
actionpack (5.2.6.2) lib/action_controller/metal/instrumentation.rb:34:in `block in process_action'
activesupport (5.2.6.2) lib/active_support/notifications.rb:168:in `block in instrument'
activesupport (5.2.6.2) lib/active_support/notifications/instrumenter.rb:23:in `instrument'
activesupport (5.2.6.2) lib/active_support/notifications.rb:168:in `instrument'
actionpack (5.2.6.2) lib/action_controller/metal/instrumentation.rb:32:in `process_action'
actionpack (5.2.6.2) lib/action_controller/metal/params_wrapper.rb:256:in `process_action'
activerecord (5.2.6.2) lib/active_record/railties/controller_runtime.rb:24:in `process_action'
actionpack (5.2.6.2) lib/abstract_controller/base.rb:134:in `process'
actionview (5.2.6.2) lib/action_view/rendering.rb:32:in `process'
actionpack (5.2.6.2) lib/action_controller/metal.rb:191:in `dispatch'
actionpack (5.2.6.2) lib/action_controller/metal.rb:252:in `dispatch'
actionpack (5.2.6.2) lib/action_dispatch/routing/route_set.rb:52:in `dispatch'
actionpack (5.2.6.2) lib/action_dispatch/routing/route_set.rb:34:in `serve'
actionpack (5.2.6.2) lib/action_dispatch/journey/router.rb:52:in `block in serve'
actionpack (5.2.6.2) lib/action_dispatch/journey/router.rb:35:in `each'
actionpack (5.2.6.2) lib/action_dispatch/journey/router.rb:35:in `serve'
actionpack (5.2.6.2) lib/action_dispatch/routing/route_set.rb:840:in `call'
warden (1.2.9) lib/warden/manager.rb:36:in `block in call'
warden (1.2.9) lib/warden/manager.rb:34:in `catch'
warden (1.2.9) lib/warden/manager.rb:34:in `call'
rack (2.2.3) lib/rack/tempfile_reaper.rb:15:in `call'
rack (2.2.3) lib/rack/etag.rb:27:in `call'
rack (2.2.3) lib/rack/conditional_get.rb:27:in `call'
rack (2.2.3) lib/rack/head.rb:12:in `call'
actionpack (5.2.6.2) lib/action_dispatch/http/content_security_policy.rb:18:in `call'
rack (2.2.3) lib/rack/session/abstract/id.rb:266:in `context'
rack (2.2.3) lib/rack/session/abstract/id.rb:260:in `call'
actionpack (5.2.6.2) lib/action_dispatch/middleware/cookies.rb:670:in `call'
actionpack (5.2.6.2) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (5.2.6.2) lib/active_support/callbacks.rb:98:in `run_callbacks'
actionpack (5.2.6.2) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
actionpack (5.2.6.2) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (5.2.6.2) lib/action_dispatch/middleware/debug_exceptions.rb:61:in `call'
web-console (3.7.0) lib/web_console/middleware.rb:135:in `call_app'
web-console (3.7.0) lib/web_console/middleware.rb:30:in `block in call'
web-console (3.7.0) lib/web_console/middleware.rb:20:in `catch'
web-console (3.7.0) lib/web_console/middleware.rb:20:in `call'
actionpack (5.2.6.2) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (5.2.6.2) lib/rails/rack/logger.rb:38:in `call_app'
railties (5.2.6.2) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (5.2.6.2) lib/active_support/tagged_logging.rb:71:in `block in tagged'
activesupport (5.2.6.2) lib/active_support/tagged_logging.rb:28:in `tagged'
activesupport (5.2.6.2) lib/active_support/tagged_logging.rb:71:in `tagged'
railties (5.2.6.2) lib/rails/rack/logger.rb:26:in `call'
sprockets-rails (3.4.2) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (5.2.6.2) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
request_store (1.5.1) lib/request_store/middleware.rb:19:in `call'
actionpack (5.2.6.2) lib/action_dispatch/middleware/request_id.rb:27:in `call'
rack (2.2.3) lib/rack/method_override.rb:24:in `call'
rack (2.2.3) lib/rack/runtime.rb:22:in `call'
activesupport (5.2.6.2) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (5.2.6.2) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (5.2.6.2) lib/action_dispatch/middleware/static.rb:127:in `call'
rack (2.2.3) lib/rack/sendfile.rb:110:in `call'
railties (5.2.6.2) lib/rails/engine.rb:524:in `call'
puma (3.12.6) lib/puma/configuration.rb:227:in `call'
puma (3.12.6) lib/puma/server.rb:706:in `handle_request'
puma (3.12.6) lib/puma/server.rb:476:in `process_client'
puma (3.12.6) lib/puma/server.rb:334:in `block in run'
puma (3.12.6) lib/puma/thread_pool.rb:135:in `block in spawn_thread'
model.rb
class College < ApplicationRecord
has_many :comments
ratyrate_rateable 'culture', 'original_score', 'resources', 'academic_support'
mount_uploader :picture, PictureUploader
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在 config/environment.rb 文件中禁用了 config.active_record.migration_error = :page_load ,因此无法显示挂起的迁移错误。我运行了 rake db: migrate:status 和我的一些迁移正在等待处理。我发现错误是由ratyrate gem引起的,我使用以下解决方案修复了 Ruby on Rails:ratyrate gem 表已经存在?。
I had disabled
config.active_record.migration_error = :page_load
inconfig/environment.rb
file, hence pending migration error could not be shown.I ranrake db:migrate:status
and some of my migrations were pending. I figured out the error was being caused by the ratyrate gem and I fixed using the following solution Ruby on Rails: ratyrate gem table already exists?.