I've been trying to learn ruby(2.6.3) on rails(6.0.1) by following a project to make an Instagram clone.
When I try to create a new post I get "no implicit conversion of String into Integer app/controllers/posts_controller.rb:8:in `create' ". I'm confused because I do not see a string to int so i'm wondering if it is something i'm missing with ruby. I've tried updating my gem versions and also tried adding the "strong_parameters" gem but that did not seem to fix my problem. Thank you for any insight as to what i'm doing wrong
Post_controller.rb
class PostsController < ApplicationController
def new
#post = Post.new
end
def create
#post = Post.new(post_params)
if #post.save
redirect_to dashboard_path, flash: {success: "Post was created successfully!"}
else
redirect_to new_post_path, flash: {danger: "Post failed to save!"}
end
end
def show
end
private
def post_params
params.require(:post).permit(:image, :image_cache)
end
end
Posts table migrate
class CreatePosts < ActiveRecord::Migration[6.0]
def change
create_table :posts do |t|
t.string :image
t.boolean :active
t.references :account
t.timestamps
end
end
end
Post Model
class Post < ApplicationRecord
mount_uploader :image, ImageUploader
end
Post table schema
create_table "posts", force: :cascade do |t|
t.string "image"
t.boolean "active"
t.bigint "account_id"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["account_id"], name: "index_posts_on_account_id"
end
Full stack trace
carrierwave (2.0.2) lib/carrierwave/sanitized_file.rb:312:in `chmod'
carrierwave (2.0.2) lib/carrierwave/sanitized_file.rb:312:in `chmod!'
carrierwave (2.0.2) lib/carrierwave/sanitized_file.rb:220:in `copy_to'
carrierwave (2.0.2) lib/carrierwave/uploader/cache.rb:141:in `cache!'
carrierwave (2.0.2) lib/carrierwave/mounter.rb:63:in `block (2 levels) in cache'
carrierwave (2.0.2) lib/carrierwave/mounter.rb:176:in `handle_error'
carrierwave (2.0.2) lib/carrierwave/mounter.rb:47:in `block in cache'
carrierwave (2.0.2) lib/carrierwave/mounter.rb:46:in `map'
carrierwave (2.0.2) lib/carrierwave/mounter.rb:46:in `cache'
carrierwave (2.0.2) lib/carrierwave/mount.rb:146:in `image='
carrierwave (2.0.2) lib/carrierwave/mount.rb:373:in `image='
carrierwave (2.0.2) lib/carrierwave/orm/activerecord.rb:75:in `image='
activemodel (6.0.1) lib/active_model/attribute_assignment.rb:51:in `public_send'
activemodel (6.0.1) lib/active_model/attribute_assignment.rb:51:in `_assign_attribute'
activemodel (6.0.1) lib/active_model/attribute_assignment.rb:44:in `block in _assign_attributes'
activemodel (6.0.1) lib/active_model/attribute_assignment.rb:43:in `each'
activemodel (6.0.1) lib/active_model/attribute_assignment.rb:43:in `_assign_attributes'
activerecord (6.0.1) lib/active_record/attribute_assignment.rb:22:in `_assign_attributes'
activemodel (6.0.1) lib/active_model/attribute_assignment.rb:35:in `assign_attributes'
activerecord (6.0.1) lib/active_record/core.rb:326:in `initialize'
activerecord (6.0.1) lib/active_record/inheritance.rb:70:in `new'
activerecord (6.0.1) lib/active_record/inheritance.rb:70:in `new'
app/controllers/posts_controller.rb:8:in `create'
actionpack (6.0.1) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
actionpack (6.0.1) lib/abstract_controller/base.rb:196:in `process_action'
actionpack (6.0.1) lib/action_controller/metal/rendering.rb:30:in `process_action'
actionpack (6.0.1) lib/abstract_controller/callbacks.rb:42:in `block in process_action'
activesupport (6.0.1) lib/active_support/callbacks.rb:135:in `run_callbacks'
actionpack (6.0.1) lib/abstract_controller/callbacks.rb:41:in `process_action'
actionpack (6.0.1) lib/action_controller/metal/rescue.rb:22:in `process_action'
actionpack (6.0.1) lib/action_controller/metal/instrumentation.rb:33:in `block in process_action'
activesupport (6.0.1) lib/active_support/notifications.rb:180:in `block in instrument'
activesupport (6.0.1) lib/active_support/notifications/instrumenter.rb:24:in `instrument'
activesupport (6.0.1) lib/active_support/notifications.rb:180:in `instrument'
actionpack (6.0.1) lib/action_controller/metal/instrumentation.rb:32:in `process_action'
actionpack (6.0.1) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
activerecord (6.0.1) lib/active_record/railties/controller_runtime.rb:27:in `process_action'
actionpack (6.0.1) lib/abstract_controller/base.rb:136:in `process'
actionview (6.0.1) lib/action_view/rendering.rb:39:in `process'
actionpack (6.0.1) lib/action_controller/metal.rb:191:in `dispatch'
actionpack (6.0.1) lib/action_controller/metal.rb:252:in `dispatch'
actionpack (6.0.1) lib/action_dispatch/routing/route_set.rb:51:in `dispatch'
actionpack (6.0.1) lib/action_dispatch/routing/route_set.rb:33:in `serve'
actionpack (6.0.1) lib/action_dispatch/journey/router.rb:49:in `block in serve'
actionpack (6.0.1) lib/action_dispatch/journey/router.rb:32:in `each'
actionpack (6.0.1) lib/action_dispatch/journey/router.rb:32:in `serve'
actionpack (6.0.1) lib/action_dispatch/routing/route_set.rb:837:in `call'
warden (1.2.8) lib/warden/manager.rb:36:in `block in call'
warden (1.2.8) lib/warden/manager.rb:34:in `catch'
warden (1.2.8) lib/warden/manager.rb:34:in `call'
rack (2.0.7) lib/rack/tempfile_reaper.rb:15:in `call'
rack (2.0.7) lib/rack/etag.rb:25:in `call'
rack (2.0.7) lib/rack/conditional_get.rb:38:in `call'
rack (2.0.7) lib/rack/head.rb:12:in `call'
actionpack (6.0.1) lib/action_dispatch/http/content_security_policy.rb:18:in `call'
rack (2.0.7) lib/rack/session/abstract/id.rb:232:in `context'
rack (2.0.7) lib/rack/session/abstract/id.rb:226:in `call'
actionpack (6.0.1) lib/action_dispatch/middleware/cookies.rb:648:in `call'
activerecord (6.0.1) lib/active_record/migration.rb:567:in `call'
actionpack (6.0.1) lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'
activesupport (6.0.1) lib/active_support/callbacks.rb:101:in `run_callbacks'
actionpack (6.0.1) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
actionpack (6.0.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (6.0.1) lib/action_dispatch/middleware/actionable_exceptions.rb:17:in `call'
actionpack (6.0.1) lib/action_dispatch/middleware/debug_exceptions.rb:32:in `call'
web-console (4.0.1) lib/web_console/middleware.rb:132:in `call_app'
web-console (4.0.1) lib/web_console/middleware.rb:28:in `block in call'
web-console (4.0.1) lib/web_console/middleware.rb:17:in `catch'
web-console (4.0.1) lib/web_console/middleware.rb:17:in `call'
actionpack (6.0.1) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (6.0.1) lib/rails/rack/logger.rb:38:in `call_app'
railties (6.0.1) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (6.0.1) lib/active_support/tagged_logging.rb:80:in `block in tagged'
activesupport (6.0.1) lib/active_support/tagged_logging.rb:28:in `tagged'
activesupport (6.0.1) lib/active_support/tagged_logging.rb:80:in `tagged'
railties (6.0.1) lib/rails/rack/logger.rb:26:in `call'
sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (6.0.1) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
actionpack (6.0.1) lib/action_dispatch/middleware/request_id.rb:27:in `call'
rack (2.0.7) lib/rack/method_override.rb:22:in `call'
rack (2.0.7) lib/rack/runtime.rb:22:in `call'
activesupport (6.0.1) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (6.0.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (6.0.1) lib/action_dispatch/middleware/static.rb:126:in `call'
rack (2.0.7) lib/rack/sendfile.rb:111:in `call'
actionpack (6.0.1) lib/action_dispatch/middleware/host_authorization.rb:83:in `call'
webpacker (4.2.0) lib/webpacker/dev_server_proxy.rb:23:in `perform_request'
rack-proxy (0.6.5) lib/rack/proxy.rb:57:in `call'
railties (6.0.1) lib/rails/engine.rb:526:in `call'
puma (4.3.1) lib/puma/configuration.rb:228:in `call'
puma (4.3.1) lib/puma/server.rb:681:in `handle_request'
puma (4.3.1) lib/puma/server.rb:472:in `process_client'
puma (4.3.1) lib/puma/server.rb:328:in `block in run'
puma (4.3.1) lib/puma/thread_pool.rb:134:in `block in spawn_thread'
Carrierwave config
CarrierWave.configure do |config| config.fog_credentials = { provider: 'AWS', aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'], aws_secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'], } config.storage = :fog config.permissions = "0666" config.cache_dir = "#{Rails.root}/tmp/" config.fog_directory = ENV['FOG_DIRECTORY'] config.fog_attributes = { 'Cache-Control' => "max-age=#{365.day.to_i}" }end
almost always when I see this, it is passing a string into the index of an array. Sorry to be vague, but I don't see where that would happen in your code.
Related
I'm having some trouble with nested attributes when the defined classes are inside a module:
# file bar.rb
module Abc
class Bar << ActiveRecord::Base
has_many :foos
accepts_nested_attributes_for :foos
end
end
# file foo.rb
module Abc
class Foo << ActiveRecord::Base
belongs_to :bar
# let's consider an attribute: qux
end
end
# inside the controller
def new
#bar = Abc::Bar.new
end
# inside a view
<%= form_for #bar .... do |f| %>
....
<%= f.fields_for :abc_foos, #bar.foos do |ff| %>
<%= ff.hidden_field :qux, value: true %>
<% end %>
<% end %>
Now we got the prefix "abc" in the names attributes>
# the rendered html
<input type="hidden" name="abc_bar[abc_foos][qux]" ... />
The params now comes with the abc_foos included:
# the params hash
"abc_bar" => {
....
"abc_foos" => {"qux" => "some value"}
}
The problem: the accepts_nested_attributes_for method creates something like "abc_foos_attributes=" in order to receive the attributes, but the default param key name is different. So, this will not work:
# in the controller, again
def create
#bar = Abc::Bar.new(params.require(:abc_bar).permit(:a, :b, abc_foos: [:qux]))
end
I get the error:
unknown attribute 'abc_foos' for Abc::Bar.
I would expect something like "foos_attributes" as the appropriate key. What am I missing?
Thanks!
The full bactrace:
activemodel (5.2.1) lib/active_model/attribute_assignment.rb:53:in `_assign_attribute'
activerecord (5.2.1) lib/active_record/attribute_assignment.rb:31:in `block in assign_nested_parameter_attributes'
activerecord (5.2.1) lib/active_record/attribute_assignment.rb:31:in `each'
activerecord (5.2.1) lib/active_record/attribute_assignment.rb:31:in `assign_nested_parameter_attributes'
activerecord (5.2.1) lib/active_record/attribute_assignment.rb:25:in `_assign_attributes'
activemodel (5.2.1) lib/active_model/attribute_assignment.rb:35:in `assign_attributes'
activerecord (5.2.1) lib/active_record/core.rb:314:in `initialize'
activerecord (5.2.1) lib/active_record/inheritance.rb:66:in `new'
activerecord (5.2.1) lib/active_record/inheritance.rb:66:in `new'
app/controllers/bar_controller.rb:33:in `create'
actionpack (5.2.1) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
actionpack (5.2.1) lib/abstract_controller/base.rb:194:in `process_action'
actionpack (5.2.1) lib/action_controller/metal/rendering.rb:30:in `process_action'
actionpack (5.2.1) lib/abstract_controller/callbacks.rb:42:in `block in process_action'
activesupport (5.2.1) lib/active_support/callbacks.rb:132:in `run_callbacks'
actionpack (5.2.1) lib/abstract_controller/callbacks.rb:41:in `process_action'
actionpack (5.2.1) lib/action_controller/metal/rescue.rb:22:in `process_action'
actionpack (5.2.1) lib/action_controller/metal/instrumentation.rb:34:in `block in process_action'
activesupport (5.2.1) lib/active_support/notifications.rb:168:in `block in instrument'
activesupport (5.2.1) lib/active_support/notifications/instrumenter.rb:23:in `instrument'
activesupport (5.2.1) lib/active_support/notifications.rb:168:in `instrument'
actionpack (5.2.1) lib/action_controller/metal/instrumentation.rb:32:in `process_action'
actionpack (5.2.1) lib/action_controller/metal/params_wrapper.rb:256:in `process_action'
activerecord (5.2.1) lib/active_record/railties/controller_runtime.rb:24:in `process_action'
actionpack (5.2.1) lib/abstract_controller/base.rb:134:in `process'
actionview (5.2.1) lib/action_view/rendering.rb:32:in `process'
actionpack (5.2.1) lib/action_controller/metal.rb:191:in `dispatch'
actionpack (5.2.1) lib/action_controller/metal.rb:252:in `dispatch'
actionpack (5.2.1) lib/action_dispatch/routing/route_set.rb:52:in `dispatch'
actionpack (5.2.1) lib/action_dispatch/routing/route_set.rb:34:in `serve'
actionpack (5.2.1) lib/action_dispatch/journey/router.rb:52:in `block in serve'
actionpack (5.2.1) lib/action_dispatch/journey/router.rb:35:in `each'
actionpack (5.2.1) lib/action_dispatch/journey/router.rb:35:in `serve'
actionpack (5.2.1) lib/action_dispatch/routing/route_set.rb:840:in `call'
rack (2.0.6) lib/rack/tempfile_reaper.rb:15:in `call'
rack (2.0.6) lib/rack/etag.rb:25:in `call'
rack (2.0.6) lib/rack/conditional_get.rb:38:in `call'
rack (2.0.6) lib/rack/head.rb:12:in `call'
actionpack (5.2.1) lib/action_dispatch/http/content_security_policy.rb:18:in `call'
rack (2.0.6) lib/rack/session/abstract/id.rb:232:in `context'
rack (2.0.6) lib/rack/session/abstract/id.rb:226:in `call'
actionpack (5.2.1) lib/action_dispatch/middleware/cookies.rb:670:in `call'
activerecord (5.2.1) lib/active_record/migration.rb:559:in `call'
actionpack (5.2.1) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (5.2.1) lib/active_support/callbacks.rb:98:in `run_callbacks'
actionpack (5.2.1) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
actionpack (5.2.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (5.2.1) 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:22: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.1) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (5.2.1) lib/rails/rack/logger.rb:38:in `call_app'
railties (5.2.1) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (5.2.1) lib/active_support/tagged_logging.rb:71:in `block in tagged'
activesupport (5.2.1) lib/active_support/tagged_logging.rb:28:in `tagged'
activesupport (5.2.1) lib/active_support/tagged_logging.rb:71:in `tagged'
railties (5.2.1) lib/rails/rack/logger.rb:26:in `call'
sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (5.2.1) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
actionpack (5.2.1) lib/action_dispatch/middleware/request_id.rb:27:in `call'
rack (2.0.6) lib/rack/method_override.rb:22:in `call'
rack (2.0.6) lib/rack/runtime.rb:22:in `call'
activesupport (5.2.1) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (5.2.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (5.2.1) lib/action_dispatch/middleware/static.rb:127:in `call'
rack (2.0.6) lib/rack/sendfile.rb:111:in `call'
railties (5.2.1) lib/rails/engine.rb:524:in `call'
puma (3.12.0) lib/puma/configuration.rb:225:in `call'
puma (3.12.0) lib/puma/server.rb:658:in `handle_request'
puma (3.12.0) lib/puma/server.rb:472:in `process_client'
puma (3.12.0) lib/puma/server.rb:332:in `block in run'
puma (3.12.0) lib/puma/thread_pool.rb:133:in `block in spawn_thread'
Can you post full backtrace errors? But in the meantime if you try
<%= f.fields_for :foos, #bar.foos do |foo| %>
<%= foo.hidden_field :qux, value: true %>
<% end %>
you probably also need to do
#bar = Abc::Bar.new(params.require(:abc_bar).permit(:a, :b, foos: [:qux]))
I'm constructing an admin panel with active admin
I've installed the three gems
gem 'activeadmin', github: 'activeadmin'
gem 'devise'
gem 'cancancan'
I set it up as follows:
rails g active_admin:install # Created a nice admin panel, with AdminUser Model
rails generate active_admin:resource MyModel # Added all my models
config/active_admin.rb
config.authorization_adapter = ActiveAdmin::CanCanAdapter
config.cancan_ability_class = Ability
config.authentication_method = :authenticate_admin_user!
ability.rb
class Ability
include CanCan::Ability
def initialize(user)
if user.admin?
can :read, ActiveAdmin::Page, :name => "Dashboard"
else
can :read, ActiveAdmin::Page, :name => "Dashboard"
end
end
end
and I also defined nice custom methods using formtastic, like index, show, edit, etc. methods for all my resource models I generated for active admin.
For example, my admin/dashboard.rb
ActiveAdmin.register_page "Dashboard" do
menu priority: 1, label: proc{ I18n.t("active_admin.dashboard") }
# some tables to display
content title: proc{ I18n.t("active_admin.dashboard") } do
div class: "blank_slate_container", id: "dashboard_default_message" do
columns do
column do
panel "Latest Visitors" do
# table_for Visitor('id desc').limit(10) do
table_for Patient.order("id desc").limit(10) do
column(:name)
column(:mobile)
end
end
end
end # columns
end
end # content
controller do
# before_action :authenticate_admin_user!
load_and_authorize_resource :through => :current_admin_user
end
end
The app runs fine if I comment out load_and_authorize_resource, a nice login system, which shows dashboard on successful log in details.
But when I use "load_and_authorize_resource", it throws an error when I load https://mywebsite/admin saying
NoMethodError in Admin::DashboardController#index
undefined method `dashboards' for #<AdminUser:0x007f0afd642878>
The method initialize seems to be working fine. But it somehow doesn't redirect back properly to the dashboard.
I didn't specifically use devise, but when I ran rails g active_admin:install initially, when setting up activeadmin, it automatically used devise, done as per the activeadmin documentation.
Update Stack trace:
Processing by Admin::DashboardController#index as HTML
AdminUser Load (50.8ms) SELECT "admin_users".* FROM "admin_users" WHERE "admin_users"."id" = $1 ORDER BY "admin_users"."id" ASC LIMIT $2 [["id", 2], ["LIMIT", 1]]
Completed 500 Internal Server Error in 106ms (ActiveRecord: 50.8ms)
NoMethodError (undefined method `dashboards' for #<AdminUser:0x000000063c4fa0>):
activemodel (5.0.6) lib/active_model/attribute_methods.rb:433:in `method_missing'
cancancan (2.0.0) lib/cancan/controller_resource.rb:201:in `resource_base_through'
cancancan (2.0.0) lib/cancan/controller_resource.rb:190:in `resource_base'
cancancan (2.0.0) lib/cancan/controller_resource.rb:72:in `load_collection?'
cancancan (2.0.0) lib/cancan/controller_resource.rb:36:in `load_resource'
cancancan (2.0.0) lib/cancan/controller_resource.rb:28:in `load_and_authorize_resource'
cancancan (2.0.0) lib/cancan/controller_resource.rb:12:in `block in add_before_action'
activesupport (5.0.6) lib/active_support/callbacks.rb:398:in `instance_exec'
activesupport (5.0.6) lib/active_support/callbacks.rb:398:in `block in make_lambda'
activesupport (5.0.6) lib/active_support/callbacks.rb:169:in `block (2 levels) in halting'
actionpack (5.0.6) lib/abstract_controller/callbacks.rb:12:in `block (2 levels) in <module:Callbacks>'
activesupport (5.0.6) lib/active_support/callbacks.rb:170:in `block in halting'
activesupport (5.0.6) lib/active_support/callbacks.rb:454:in `block in call'
activesupport (5.0.6) lib/active_support/callbacks.rb:454:in `each'
activesupport (5.0.6) lib/active_support/callbacks.rb:454:in `call'
activesupport (5.0.6) lib/active_support/callbacks.rb:101:in `__run_callbacks__'
activesupport (5.0.6) lib/active_support/callbacks.rb:750:in `_run_process_action_callbacks'
activesupport (5.0.6) lib/active_support/callbacks.rb:90:in `run_callbacks'
actionpack (5.0.6) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (5.0.6) lib/action_controller/metal/rescue.rb:20:in `process_action'
actionpack (5.0.6) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
activesupport (5.0.6) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (5.0.6) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (5.0.6) lib/active_support/notifications.rb:164:in `instrument'
actionpack (5.0.6) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (5.0.6) lib/action_controller/metal/params_wrapper.rb:248:in `process_action'
activerecord (5.0.6) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (5.0.6) lib/abstract_controller/base.rb:126:in `process'
actionview (5.0.6) lib/action_view/rendering.rb:30:in `process'
actionpack (5.0.6) lib/action_controller/metal.rb:190:in `dispatch'
actionpack (5.0.6) lib/action_controller/metal.rb:262:in `dispatch'
actionpack (5.0.6) lib/action_dispatch/routing/route_set.rb:50:in `dispatch'
actionpack (5.0.6) lib/action_dispatch/routing/route_set.rb:32:in `serve'
actionpack (5.0.6) lib/action_dispatch/journey/router.rb:39:in `block in serve'
actionpack (5.0.6) lib/action_dispatch/journey/router.rb:26:in `each'
actionpack (5.0.6) lib/action_dispatch/journey/router.rb:26:in `serve'
actionpack (5.0.6) lib/action_dispatch/routing/route_set.rb:727:in `call'
newrelic_rpm (4.5.0.337) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
newrelic_rpm (4.5.0.337) lib/new_relic/rack/agent_hooks.rb:30:in `traced_call'
newrelic_rpm (4.5.0.337) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
newrelic_rpm (4.5.0.337) lib/new_relic/rack/browser_monitoring.rb:32:in `traced_call'
newrelic_rpm (4.5.0.337) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
warden (1.2.7) lib/warden/manager.rb:36:in `block in call'
warden (1.2.7) lib/warden/manager.rb:35:in `catch'
warden (1.2.7) lib/warden/manager.rb:35:in `call'
newrelic_rpm (4.5.0.337) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
rack (2.0.3) lib/rack/etag.rb:25:in `call'
newrelic_rpm (4.5.0.337) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
rack (2.0.3) lib/rack/conditional_get.rb:25:in `call'
newrelic_rpm (4.5.0.337) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
rack (2.0.3) lib/rack/head.rb:12:in `call'
newrelic_rpm (4.5.0.337) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
rack (2.0.3) lib/rack/session/abstract/id.rb:232:in `context'
rack (2.0.3) lib/rack/session/abstract/id.rb:226:in `call'
newrelic_rpm (4.5.0.337) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
actionpack (5.0.6) lib/action_dispatch/middleware/cookies.rb:613:in `call'
newrelic_rpm (4.5.0.337) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
activerecord (5.0.6) lib/active_record/migration.rb:553:in `call'
newrelic_rpm (4.5.0.337) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
actionpack (5.0.6) lib/action_dispatch/middleware/callbacks.rb:38:in `block in call'
activesupport (5.0.6) lib/active_support/callbacks.rb:97:in `__run_callbacks__'
activesupport (5.0.6) lib/active_support/callbacks.rb:750:in `_run_call_callbacks'
activesupport (5.0.6) lib/active_support/callbacks.rb:90:in `run_callbacks'
actionpack (5.0.6) lib/action_dispatch/middleware/callbacks.rb:36:in `call'
newrelic_rpm (4.5.0.337) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
actionpack (5.0.6) lib/action_dispatch/middleware/executor.rb:12:in `call'
newrelic_rpm (4.5.0.337) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
actionpack (5.0.6) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
newrelic_rpm (4.5.0.337) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
better_errors (2.4.0) lib/better_errors/middleware.rb:59:in `call'
newrelic_rpm (4.5.0.337) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
actionpack (5.0.6) lib/action_dispatch/middleware/debug_exceptions.rb:49:in `call'
newrelic_rpm (4.5.0.337) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
web-console (3.5.1) lib/web_console/middleware.rb:135:in `call_app'
web-console (3.5.1) lib/web_console/middleware.rb:20:in `block in call'
web-console (3.5.1) lib/web_console/middleware.rb:18:in `catch'
web-console (3.5.1) lib/web_console/middleware.rb:18:in `call'
newrelic_rpm (4.5.0.337) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
actionpack (5.0.6) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
newrelic_rpm (4.5.0.337) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
railties (5.0.6) lib/rails/rack/logger.rb:36:in `call_app'
railties (5.0.6) lib/rails/rack/logger.rb:24:in `block in call'
activesupport (5.0.6) lib/active_support/tagged_logging.rb:69:in `block in tagged'
activesupport (5.0.6) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (5.0.6) lib/active_support/tagged_logging.rb:69:in `tagged'
railties (5.0.6) lib/rails/rack/logger.rb:24:in `call'
newrelic_rpm (4.5.0.337) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call'
newrelic_rpm (4.5.0.337) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
actionpack (5.0.6) lib/action_dispatch/middleware/request_id.rb:24:in `call'
newrelic_rpm (4.5.0.337) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
rack (2.0.3) lib/rack/method_override.rb:22:in `call'
newrelic_rpm (4.5.0.337) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
rack (2.0.3) lib/rack/runtime.rb:22:in `call'
newrelic_rpm (4.5.0.337) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
activesupport (5.0.6) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
newrelic_rpm (4.5.0.337) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
actionpack (5.0.6) lib/action_dispatch/middleware/executor.rb:12:in `call'
newrelic_rpm (4.5.0.337) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
actionpack (5.0.6) lib/action_dispatch/middleware/static.rb:136:in `call'
newrelic_rpm (4.5.0.337) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
rack (2.0.3) lib/rack/sendfile.rb:111:in `call'
newrelic_rpm (4.5.0.337) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
railties (5.0.6) lib/rails/engine.rb:522:in `call'
newrelic_rpm (4.5.0.337) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
puma (3.10.0) lib/puma/configuration.rb:225:in `call'
puma (3.10.0) lib/puma/server.rb:605:in `handle_request'
puma (3.10.0) lib/puma/server.rb:437:in `process_client'
puma (3.10.0) lib/puma/server.rb:301:in `block in run'
puma (3.10.0) lib/puma/thread_pool.rb:120:in `block in spawn_thread'
Rendering /usr/local/rvm/gems/ruby-2.3.4/gems/actionpack-5.0.6/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout
Rendering /usr/local/rvm/gems/ruby-2.3.4/gems/actionpack-5.0.6/lib/action_dispatch/middleware/templates/rescues/_source.html.erb
Rendered /usr/local/rvm/gems/ruby-2.3.4/gems/actionpack-5.0.6/lib/action_dispatch/middleware/templates/rescues/_source.html.erb (4.6ms)
Rendering /usr/local/rvm/gems/ruby-2.3.4/gems/actionpack-5.0.6/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb
Rendered /usr/local/rvm/gems/ruby-2.3.4/gems/actionpack-5.0.6/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (2.2ms)
Rendering /usr/local/rvm/gems/ruby-2.3.4/gems/actionpack-5.0.6/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb
Rendered /usr/local/rvm/gems/ruby-2.3.4/gems/actionpack-5.0.6/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.0ms)
Rendered /usr/local/rvm/gems/ruby-2.3.4/gems/actionpack-5.0.6/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (35.2ms)
If you follow the steps for integrating Cancancan with ActiveAdmin, then you just have to extend Ability#initialize with your user roles as you need like so:
# app/models/ability.rb
def initialize(user)
if user.admin?
can :manage, :all
elsif user.product_manager?
can :manage, Product
can :read, ActiveAdmin::Page, name: 'Dashboard'
end
end
No need to invoke load_and_authorize_resource in each controller!
I get NameError: uninitialized constant Category::Translation when executing:
Category.first.translations
Rails version: 5.1.3
Ruby version: 2.3.3
Models:
# app/models/translation.rb
class Translation < ApplicationRecord
belongs_to :translatable, polymorphic: true
end
# app/models/category.rb
class Category < ApplicationRecord
has_many :translations, :as => :translatable
end
Migration:
class CreateTranslations < ActiveRecord::Migration[5.1]
def change
create_table :translations do |t|
t.string :locale
t.string :key
t.text :value
t.text :interpolations
t.boolean :is_proc, default: false
t.references :translatable, polymorphic: true, index: true
t.timestamps
end
end
end
schema.rb:
create_table "translations", force: :cascade do |t|
t.string "locale"
t.string "key"
t.text "value"
t.text "interpolations"
t.boolean "is_proc", default: false
t.string "translatable_type"
t.integer "translatable_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["translatable_type", "translatable_id"], name: "index_translations_on_translatable_type_and_translatable_id"
end
Full trace:
activerecord (5.1.3) lib/active_record/inheritance.rb:166:in `compute_type'
activerecord (5.1.3) lib/active_record/reflection.rb:401:in `compute_class'
activerecord (5.1.3) lib/active_record/reflection.rb:397:in `klass'
activerecord (5.1.3) lib/active_record/associations/association.rb:127:in `klass'
activerecord (5.1.3) lib/active_record/associations/collection_association.rb:33:in `reader'
activerecord (5.1.3) lib/active_record/associations/builder/association.rb:111:in `translations'
app/controllers/categories_controller.rb:27:in `new'
actionpack (5.1.3) lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action'
actionpack (5.1.3) lib/abstract_controller/base.rb:186:in `process_action'
actionpack (5.1.3) lib/action_controller/metal/rendering.rb:30:in `process_action'
actionpack (5.1.3) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (5.1.3) lib/active_support/callbacks.rb:131:in `run_callbacks'
actionpack (5.1.3) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (5.1.3) lib/action_controller/metal/rescue.rb:20:in `process_action'
actionpack (5.1.3) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
activesupport (5.1.3) lib/active_support/notifications.rb:166:in `block in instrument'
activesupport (5.1.3) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (5.1.3) lib/active_support/notifications.rb:166:in `instrument'
actionpack (5.1.3) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (5.1.3) lib/action_controller/metal/params_wrapper.rb:252:in `process_action'
activerecord (5.1.3) lib/active_record/railties/controller_runtime.rb:22:in `process_action'
actionpack (5.1.3) lib/abstract_controller/base.rb:124:in `process'
actionview (5.1.3) lib/action_view/rendering.rb:30:in `process'
actionpack (5.1.3) lib/action_controller/metal.rb:189:in `dispatch'
actionpack (5.1.3) lib/action_controller/metal.rb:253:in `dispatch'
actionpack (5.1.3) lib/action_dispatch/routing/route_set.rb:49:in `dispatch'
actionpack (5.1.3) lib/action_dispatch/routing/route_set.rb:31:in `serve'
actionpack (5.1.3) lib/action_dispatch/journey/router.rb:46:in `block in serve'
actionpack (5.1.3) lib/action_dispatch/journey/router.rb:33:in `each'
actionpack (5.1.3) lib/action_dispatch/journey/router.rb:33:in `serve'
actionpack (5.1.3) lib/action_dispatch/routing/route_set.rb:834:in `call'
omniauth (1.6.1) lib/omniauth/strategy.rb:189:in `call!'
omniauth (1.6.1) lib/omniauth/strategy.rb:167:in `call'
omniauth (1.6.1) lib/omniauth/strategy.rb:189:in `call!'
omniauth (1.6.1) lib/omniauth/strategy.rb:167:in `call'
omniauth (1.6.1) lib/omniauth/builder.rb:63:in `call'
rack (2.0.3) lib/rack/etag.rb:25:in `call'
rack (2.0.3) lib/rack/conditional_get.rb:25:in `call'
rack (2.0.3) lib/rack/head.rb:12:in `call'
rack (2.0.3) lib/rack/session/abstract/id.rb:232:in `context'
rack (2.0.3) lib/rack/session/abstract/id.rb:226:in `call'
actionpack (5.1.3) lib/action_dispatch/middleware/cookies.rb:613:in `call'
activerecord (5.1.3) lib/active_record/migration.rb:556:in `call'
actionpack (5.1.3) lib/action_dispatch/middleware/callbacks.rb:26:in `block in call'
activesupport (5.1.3) lib/active_support/callbacks.rb:97:in `run_callbacks'
actionpack (5.1.3) lib/action_dispatch/middleware/callbacks.rb:24:in `call'
actionpack (5.1.3) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.1.3) lib/action_dispatch/middleware/debug_exceptions.rb:59:in `call'
web-console (3.5.1) lib/web_console/middleware.rb:135:in `call_app'
web-console (3.5.1) lib/web_console/middleware.rb:28:in `block in call'
web-console (3.5.1) lib/web_console/middleware.rb:18:in `catch'
web-console (3.5.1) lib/web_console/middleware.rb:18:in `call'
actionpack (5.1.3) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
railties (5.1.3) lib/rails/rack/logger.rb:36:in `call_app'
railties (5.1.3) lib/rails/rack/logger.rb:24:in `block in call'
activesupport (5.1.3) lib/active_support/tagged_logging.rb:69:in `block in tagged'
activesupport (5.1.3) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (5.1.3) lib/active_support/tagged_logging.rb:69:in `tagged'
railties (5.1.3) lib/rails/rack/logger.rb:24:in `call'
sprockets-rails (3.2.0) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (5.1.3) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
actionpack (5.1.3) lib/action_dispatch/middleware/request_id.rb:25:in `call'
rack (2.0.3) lib/rack/method_override.rb:22:in `call'
rack (2.0.3) lib/rack/runtime.rb:22:in `call'
activesupport (5.1.3) lib/active_support/cache/strategy/local_cache_middleware.rb:27:in `call'
actionpack (5.1.3) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.1.3) lib/action_dispatch/middleware/static.rb:125:in `call'
rack (2.0.3) lib/rack/sendfile.rb:111:in `call'
railties (5.1.3) lib/rails/engine.rb:522:in `call'
puma (3.9.1) lib/puma/configuration.rb:224:in `call'
puma (3.9.1) lib/puma/server.rb:602:in `handle_request'
puma (3.9.1) lib/puma/server.rb:435:in `process_client'
puma (3.9.1) lib/puma/server.rb:299:in `block in run'
puma (3.9.1) lib/puma/thread_pool.rb:120:in `block in spawn_thread'
I read on many sites that this error is caused by misconfiguration in assocations (mostly typos). I also tried to set :classname => 'Translation' in Category class, but that didnt helped too. I was not able to identify the problem for the whole day so I am here to beg for help.
Thanks!
I solved it! This was not related to the models directly. #MrYoshiji pointed me to the right direction.
I use I18n gem and i18n-active_record so I can store translations in database.
In initialization Rails loaded this code:
Translation = I18n::Backend::ActiveRecord::Translation
The Translation model was in real I18n::Backend::ActiveRecord::Translation model. And therefore changes in my Translation model took no effect, because the name was linked to another model..
I changed app/models/translation.rb to this:
class Translation < I18n::Backend::ActiveRecord::Translation
belongs_to :translatable, polymorphic: true
end
and deleted line mentioned above from configuration.
Anyway, thank you so much for your comments!
I'm currently working on a assignment for ruby on rails course I'm doing. I have to refactor a blog app written in Rails and add the functionality to merge articles.
What I did was to add a new text field in the form that is displayed when you edit the article
<%= text_field 'article', 'merge' %>
After I do that, it complains that there is no merge method in article model so I went ahead and implemented that.
I run the following migration:
class AddMergeWithToContents < ActiveRecord::Migration
def self.up
add_column :contents, :merge_with, :integer
end
def self.down
remove_column :contents, :merge_with
end
end
Then, when when accessing again the app it gives me the following error:
RangeError in Admin::SettingsController#update_database
bignum too big to convert into `long'
Rails.root: /home/saasbook/typo
Application Trace | Framework Trace | Full Trace
app/controllers/admin/settings_controller.rb:38:in `[]'
app/controllers/admin/settings_controller.rb:38:in `update_database'
Full Trace
app/controllers/admin/settings_controller.rb:38:in `[]'
app/controllers/admin/settings_controller.rb:38:in `update_database'
actionpack (3.0.17) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.0.17) lib/abstract_controller/base.rb:150:in `process_action'
actionpack (3.0.17) lib/action_controller/metal/rendering.rb:11:in `process_action'
actionpack (3.0.17) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.0.17) lib/active_support/callbacks.rb:457:in `block in _run__331447277__process_action__533401003__callbacks'
activesupport (3.0.17) lib/active_support/callbacks.rb:221:in `block in _conditional_callback_around_20300'
activesupport (3.0.17) lib/active_support/callbacks.rb:331:in `around'
activesupport (3.0.17) lib/active_support/callbacks.rb:315:in `_callback_around_20297'
activesupport (3.0.17) lib/active_support/callbacks.rb:220:in `_conditional_callback_around_20300'
activesupport (3.0.17) lib/active_support/callbacks.rb:456:in `_run__331447277__process_action__533401003__callbacks'
activesupport (3.0.17) lib/active_support/callbacks.rb:410:in `_run_process_action_callbacks'
activesupport (3.0.17) lib/active_support/callbacks.rb:94:in `run_callbacks'
actionpack (3.0.17) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.0.17) lib/action_controller/metal/rescue.rb:17:in `process_action'
actionpack (3.0.17) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.0.17) lib/active_support/notifications.rb:52:in `block in instrument'
activesupport (3.0.17) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.17) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.17) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.0.17) lib/abstract_controller/base.rb:119:in `process'
actionpack (3.0.17) lib/abstract_controller/rendering.rb:41:in `process'
actionpack (3.0.17) lib/action_controller/metal.rb:138:in `dispatch'
actionpack (3.0.17) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.0.17) lib/action_controller/metal.rb:178:in `block in action'
actionpack (3.0.17) lib/action_dispatch/routing/route_set.rb:68:in `call'
actionpack (3.0.17) lib/action_dispatch/routing/route_set.rb:68:in `dispatch'
actionpack (3.0.17) lib/action_dispatch/routing/route_set.rb:33:in `call'
rack-mount (0.6.14) lib/rack/mount/route_set.rb:148:in `block in call'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:93:in `block in recognize'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:75:in `optimized_each'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:92:in `recognize'
rack-mount (0.6.14) lib/rack/mount/route_set.rb:139:in `call'
actionpack (3.0.17) lib/action_dispatch/routing/route_set.rb:499:in `call'
actionpack (3.0.17) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
actionpack (3.0.17) lib/action_dispatch/middleware/head.rb:14:in `call'
rack (1.2.5) lib/rack/methodoverride.rb:24:in `call'
actionpack (3.0.17) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.0.17) lib/action_dispatch/middleware/flash.rb:182:in `call'
actionpack (3.0.17) lib/action_dispatch/middleware/session/abstract_store.rb:149:in `call'
actionpack (3.0.17) lib/action_dispatch/middleware/cookies.rb:302:in `call'
activerecord (3.0.17) lib/active_record/query_cache.rb:32:in `block in call'
activerecord (3.0.17) lib/active_record/connection_adapters/abstract/query_cache.rb:28:in `cache'
activerecord (3.0.17) lib/active_record/query_cache.rb:12:in `cache'
activerecord (3.0.17) lib/active_record/query_cache.rb:31:in `call'
activerecord (3.0.17) lib/active_record/connection_adapters/abstract/connection_pool.rb:354:in `call'
actionpack (3.0.17) lib/action_dispatch/middleware/callbacks.rb:46:in `block in call'
activesupport (3.0.17) lib/active_support/callbacks.rb:416:in `_run_call_callbacks'
actionpack (3.0.17) lib/action_dispatch/middleware/callbacks.rb:44:in `call'
rack (1.2.5) lib/rack/sendfile.rb:106:in `call'
actionpack (3.0.17) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.0.17) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
railties (3.0.17) lib/rails/rack/logger.rb:13:in `call'
rack (1.2.5) lib/rack/runtime.rb:17:in `call'
activesupport (3.0.17) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.2.5) lib/rack/lock.rb:13:in `block in call'
<internal:prelude>:10:in `synchronize'
rack (1.2.5) lib/rack/lock.rb:13:in `call'
actionpack (3.0.17) lib/action_dispatch/middleware/static.rb:30:in `call'
railties (3.0.17) lib/rails/application.rb:168:in `call'
railties (3.0.17) lib/rails/application.rb:77:in `method_missing'
railties (3.0.17) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.2.5) lib/rack/content_length.rb:13:in `call'
rack (1.2.5) lib/rack/handler/webrick.rb:52:in `service'
/home/saasbook/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
/home/saasbook/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
/home/saasbook/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
This is the settings controller
class Admin::SettingsController < Admin::BaseController
cache_sweeper :blog_sweeper
def index
if this_blog.base_url.blank?
this_blog.base_url = blog_base_url
end
load_settings
end
def write; load_settings end
def feedback; load_settings end
def errors; load_settings; end
def redirect
flash[:notice] = _("Please review and save the settings before continuing")
redirect_to :action => "index"
end
def update
if request.post?
Blog.transaction do
params[:setting].each { |k,v| this_blog.send("#{k.to_s}=", v) }
this_blog.save
flash[:notice] = _('config updated.')
end
redirect_to :action => params[:from]
end
rescue ActiveRecord::RecordInvalid
render params[:from]
end
def update_database
#current_version = Migrator.current_schema_version
#needed_version = Migrator.max_schema_version
#support = Migrator.db_supports_migrations?
#needed_migrations = Migrator.available_migrations[#current_version..#needed_version].collect do |mig|
mig.scan(/\d+\_([\w_]+)\.rb$/).flatten.first.humanize
end
end
def migrate
if request.post?
Migrator.migrate
redirect_to :action => 'update_database'
end
end
private
def load_settings
#setting = this_blog
end
end
Any help would be really appreciated. Thanks.
So to just answer the question, you can change the text_field to text_field_tag and remove the first argument. Or you can add a "setter" method to your article model named merge=(val) in which you can code whatever you need to. Hope this helps!
Im making an application in rails and my upload is throwing an error. Here are the details. My photos_controller.rb
def create
#photo = Photo.new(params[:photo])
respond_to do |format|
if #photo.save
format.html { redirect_to #photo, notice: 'Photo was successfully created.' }
format.json { render json: #photo, status: :created, location: #photo }
else
format.html { render action: "new" }
format.json { render json: #photo.errors, status: :unprocessable_entity }
end
end
end
my form
<%= f.file_field :binary_data %>
<%= f.submit %>
database model
t.string :photon
t.column :lat, :string
t.column :lon, :string
t.column :pname, :string
t.column :uname, :string
t.column :content_type, :string
t.column :filename, :string
t.column :binary_data, :binary
t.timestamps
I tried some ways which was mentioned in some blogs. None of them worked.
Here is the full trace
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:25:in `block in initialize'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `yield'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `default'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `block in initialize'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `yield'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `default'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `block in initialize'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `yield'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `default'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `block in initialize'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `yield'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `default'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `block in initialize'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:102:in `yield'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:102:in `default'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:102:in `accept'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:447:in `block in dump_ivars'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:445:in `each'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:445:in `dump_ivars'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:124:in `visit_Object'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:102:in `accept'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:66:in `push'
/usr/lib/ruby/1.9.1/psych.rb:242:in `dump'
activerecord (3.2.2) lib/active_record/connection_adapters/abstract/quoting.rb:38:in `quote'
activerecord (3.2.2) lib/active_record/connection_adapters/abstract_mysql_adapter.rb:203:in `quote'
activerecord (3.2.2) lib/active_record/connection_adapters/abstract/database_statements.rb:8:in `block in to_sql'
arel (3.0.3) lib/arel/visitors/bind_visitor.rb:17:in `call'
arel (3.0.3) lib/arel/visitors/bind_visitor.rb:17:in `visit_Arel_Nodes_BindParam'
arel (3.0.3) lib/arel/visitors/visitor.rb:19:in `visit'
arel (3.0.3) lib/arel/visitors/to_sql.rb:111:in `block in visit_Arel_Nodes_Values'
arel (3.0.3) lib/arel/visitors/to_sql.rb:109:in `map'
arel (3.0.3) lib/arel/visitors/to_sql.rb:109:in `visit_Arel_Nodes_Values'
arel (3.0.3) lib/arel/visitors/visitor.rb:19:in `visit'
arel (3.0.3) lib/arel/visitors/to_sql.rb:74:in `visit_Arel_Nodes_InsertStatement'
arel (3.0.3) lib/arel/visitors/visitor.rb:19:in `visit'
arel (3.0.3) lib/arel/visitors/visitor.rb:5:in `accept'
arel (3.0.3) lib/arel/visitors/to_sql.rb:19:in `accept'
arel (3.0.3) lib/arel/visitors/bind_visitor.rb:11:in `accept'
activerecord (3.2.2) lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `to_sql'
activerecord (3.2.2) lib/active_record/connection_adapters/abstract/database_statements.rb:89:in `insert'
activerecord (3.2.2) lib/active_record/connection_adapters/abstract/query_cache.rb:14:in `insert'
activerecord (3.2.2) lib/active_record/relation.rb:66:in `insert'
activerecord (3.2.2) lib/active_record/persistence.rb:363:in `create'
activerecord (3.2.2) lib/active_record/timestamp.rb:57:in `create'
activerecord (3.2.2) lib/active_record/callbacks.rb:268:in `block in create'
activesupport (3.2.2) lib/active_support/callbacks.rb:403:in `_run__4454296851553403224__create__1976589364162331536__callbacks'
activesupport (3.2.2) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.2) lib/active_support/callbacks.rb:385:in `_run_create_callbacks'
activesupport (3.2.2) lib/active_support/callbacks.rb:81:in `run_callbacks'
activerecord (3.2.2) lib/active_record/callbacks.rb:268:in `create'
activerecord (3.2.2) lib/active_record/persistence.rb:344:in `create_or_update'
activerecord (3.2.2) lib/active_record/callbacks.rb:264:in `block in create_or_update'
activesupport (3.2.2) lib/active_support/callbacks.rb:403:in `_run__4454296851553403224__save__1976589364162331536__callbacks'
activesupport (3.2.2) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.2) lib/active_support/callbacks.rb:385:in `_run_save_callbacks'
activesupport (3.2.2) lib/active_support/callbacks.rb:81:in `run_callbacks'
activerecord (3.2.2) lib/active_record/callbacks.rb:264:in `create_or_update'
activerecord (3.2.2) lib/active_record/persistence.rb:84:in `save'
activerecord (3.2.2) lib/active_record/validations.rb:50:in `save'
activerecord (3.2.2) lib/active_record/attribute_methods/dirty.rb:22:in `save'
activerecord (3.2.2) lib/active_record/transactions.rb:241:in `block (2 levels) in save'
activerecord (3.2.2) lib/active_record/transactions.rb:295:in `block in with_transaction_returning_status'
activerecord (3.2.2) lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
activerecord (3.2.2) lib/active_record/transactions.rb:208:in `transaction'
activerecord (3.2.2) lib/active_record/transactions.rb:293:in `with_transaction_returning_status'
activerecord (3.2.2) lib/active_record/transactions.rb:241:in `block in save'
activerecord (3.2.2) lib/active_record/transactions.rb:252:in `rollback_active_record_state!'
activerecord (3.2.2) lib/active_record/transactions.rb:240:in `save'
app/controllers/photos_controller.rb:47:in `block in create'
actionpack (3.2.2) lib/action_controller/metal/mime_responds.rb:278:in `call'
actionpack (3.2.2) lib/action_controller/metal/mime_responds.rb:278:in `retrieve_collector_from_mimes'
actionpack (3.2.2) lib/action_controller/metal/mime_responds.rb:194:in `respond_to'
app/controllers/photos_controller.rb:46:in `create'
actionpack (3.2.2) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.2.2) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.2) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.2) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.2.2) lib/active_support/callbacks.rb:414:in `_run__1057882058708114548__process_action__3391181575290593173__callbacks'
activesupport (3.2.2) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.2) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
activesupport (3.2.2) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.2) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.2.2) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (3.2.2) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.2.2) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.2) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.2) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.2) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.2.2) lib/action_controller/metal/params_wrapper.rb:205:in `process_action'
activerecord (3.2.2) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.2.2) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.2.2) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.2) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.2) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.2) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.2) lib/action_dispatch/routing/route_set.rb:67:in `call'
actionpack (3.2.2) lib/action_dispatch/routing/route_set.rb:67:in `dispatch'
actionpack (3.2.2) lib/action_dispatch/routing/route_set.rb:30:in `call'
/usr/lib/ruby/vendor_ruby/journey/router.rb:68:in `block in call'
/usr/lib/ruby/vendor_ruby/journey/router.rb:56:in `each'
/usr/lib/ruby/vendor_ruby/journey/router.rb:56:in `call'
actionpack (3.2.2) lib/action_dispatch/routing/route_set.rb:594:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.5) lib/rack/etag.rb:23:in `call'
rack (1.4.5) lib/rack/conditionalget.rb:35:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.4.5) lib/rack/session/abstract/id.rb:210:in `context'
rack (1.4.5) lib/rack/session/abstract/id.rb:205:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/cookies.rb:338:in `call'
activerecord (3.2.2) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:443:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.2) lib/active_support/callbacks.rb:405:in `_run__255478243604444547__call__1976589364162331536__callbacks'
activesupport (3.2.2) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.2) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.2) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.2) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.2) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.2) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.5) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.5) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.2) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.5) lib/rack/lock.rb:15:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/static.rb:61:in `call'
railties (3.2.2) lib/rails/engine.rb:479:in `call'
railties (3.2.2) lib/rails/application.rb:220:in `call'
rack (1.4.5) lib/rack/content_length.rb:14:in `call'
railties (3.2.2) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.4.5) lib/rack/handler/webrick.rb:59:in `service'
/usr/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
/usr/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
/usr/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
parameters
{"utf8"=>"✓",
"authenticity_token"=>"1zvkibcE9YuaT2sR2ofHx06MlpH7JtK7QiK/sExTNVY=",
"photo"=>{"binary_data"=>#<ActionDispatch::Http::UploadedFile:0x007fdc144411a8 #original_filename="1.jpg",
#content_type="image/jpeg",
#headers="Content-Disposition: form-data; name=\"photo[binary_data]\"; filename=\"1.jpg\"\r\nContent-Type: image/jpeg\r\n",
#tempfile=#<File:/tmp/RackMultipart20140417-28258-142dwwo>>},
"commit"=>"Create Photo"}
server log
Started POST "/photos" for 127.0.0.1 at 2014-04-17 03:21:40 +0530
Processing by PhotosController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"1zvkibcE9YuaT2sR2ofHx06MlpH7JtK7QiK/sExTNVY=", "photo"=>{"binary_data"=>#<ActionDispatch::Http::UploadedFile:0x007fdc144411a8 #original_filename="1.jpg", #content_type="image/jpeg", #headers="Content-Disposition: form-data; name=\"photo[binary_data]\"; filename=\"1.jpg\"\r\nContent-Type: image/jpeg\r\n", #tempfile=#<File:/tmp/RackMultipart20140417-28258-142dwwo>>}, "commit"=>"Create Photo"}
(0.1ms) BEGIN
(0.2ms) ROLLBACK
Completed 500 Internal Server Error in 23ms
NoMethodError (undefined method `name' for nil:NilClass):
app/controllers/photos_controller.rb:47:in `block in create'
app/controllers/photos_controller.rb:46:in `create'