gpt4 book ai didi

ruby-on-rails - 设计生成 View

转载 作者:行者123 更新时间:2023-11-29 12:45:28 25 4
gpt4 key购买 nike

我正在学习本教程:

http://www.rubyonrailstree.blogspot.com/2014/02/ruby-on-rails-device-gem-install-step.html

我遇到了问题:

rails g devise:views

&

rake db:migrate

都出现了类似的错误:

/home/zach/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/dynamic_matchers.rb:26:in `method_missing': undefined method `attr_accessible' for User (call 'User.connection' to establish a connection):Class (NoMethodError)
from /home/zach/HandCoOp/project/HandCo-op/app/models/user.rb:8:in `<class:User>'
from /home/zach/HandCoOp/project/HandCo-op/app/models/user.rb:1:in `<top (required)>'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:443:in `load'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:443:in `block in load_file'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:633:in `new_constants_in'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:442:in `load_file'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:342:in `require_or_load'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:480:in `load_missing_constant'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:180:in `const_missing'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/inflector/methods.rb:238:in `const_get'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/inflector/methods.rb:238:in `block in constantize'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/inflector/methods.rb:236:in `each'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/inflector/methods.rb:236:in `inject'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/inflector/methods.rb:236:in `constantize'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:552:in `get'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:583:in `constantize'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/devise-1.4.7/lib/devise.rb:259:in `get'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/devise-1.4.7/lib/devise/mapping.rb:103:in `to'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/devise-1.4.7/lib/devise/mapping.rb:98:in `modules'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/devise-1.4.7/lib/devise/mapping.rb:115:in `routes'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/devise-1.4.7/lib/devise/mapping.rb:84:in `initialize'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/devise-1.4.7/lib/devise.rb:289:in `new'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/devise-1.4.7/lib/devise.rb:289:in `add_mapping'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/devise-1.4.7/lib/devise/rails/routes.rb:190:in `block in devise_for'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/devise-1.4.7/lib/devise/rails/routes.rb:189:in `each'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/devise-1.4.7/lib/devise/rails/routes.rb:189:in `devise_for'
from /home/zach/HandCoOp/project/HandCo-op/config/routes.rb:2:in `block in <top (required)>'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_dispatch/routing/route_set.rb:337:in `instance_exec'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_dispatch/routing/route_set.rb:337:in `eval_block'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_dispatch/routing/route_set.rb:315:in `draw'
from /home/zach/HandCoOp/project/HandCo-op/config/routes.rb:1:in `<top (required)>'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:241:in `load'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:241:in `block in load'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:232:in `load_dependency'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:241:in `load'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/application/routes_reloader.rb:40:in `each'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/application/routes_reloader.rb:40:in `load_paths'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/application/routes_reloader.rb:16:in `reload!'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/application/routes_reloader.rb:26:in `block in updater'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/file_update_checker.rb:75:in `call'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/file_update_checker.rb:75:in `execute'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/application/routes_reloader.rb:27:in `updater'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/application/routes_reloader.rb:7:in `execute_if_updated'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/application/finisher.rb:71:in `block in <module:Finisher>'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/initializable.rb:30:in `instance_exec'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/initializable.rb:30:in `run'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/initializable.rb:55:in `block in run_initializers'
from /home/zach/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:226:in `block in tsort_each'
from /home/zach/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
from /home/zach/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:427:in `each_strongly_connected_component_from'
from /home/zach/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:347:in `block in each_strongly_connected_component'
from /home/zach/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:345:in `each'
from /home/zach/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:345:in `call'
from /home/zach/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:345:in `each_strongly_connected_component'
from /home/zach/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:224:in `tsort_each'
from /home/zach/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:205:in `tsort_each'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/initializable.rb:54:in `run_initializers'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/application.rb:300:in `initialize!'
from /home/zach/HandCoOp/project/HandCo-op/config/environment.rb:5:in `<top (required)>'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `require'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `block in require'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:232:in `load_dependency'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `require'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/application.rb:276:in `require_environment!'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:147:in `require_application_and_environment!'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:133:in `generate_or_destroy'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:51:in `generate'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
from /home/zach/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'

我使用的 ruby​​ 版本是否还不支持这个?我会继续调查这个错误,感谢任何知道这个问题的人。

路线.rb:

Rails.application.routes.draw do
devise_for :users


root 'home#index'



user.rb model:

class User < ActiveRecord::Base
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable

# Setup accessible (or protected) attributes for your model
:email
:password
:password_confirmation
:remember_me
end

谢谢,希望对您有所帮助!

最佳答案

  1. root 'home#index' 应该更改为 root to: "home#index"
  2. 从 Rails 4 开始,您不再使用 attr_accessible。您将不得不删除该行。
  3. 当使用 gem 时,更好的解决方案是吸引它的 docs .因此,在您的情况下,生成 View 的命令(在将 gem 'devise' 添加到 Gemfile 并运行 bundle 之后)应该是

a) rails 生成设计:安装,

b) rails 生成 devise:views

关于ruby-on-rails - 设计生成 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25252456/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com