我正在尝试向我的应用添加一个新的Action Mailer,当我导航到connections / new时,我收到了此错误消息:
自动加载常量时检测到循环依赖性 ConnectionsController
完整追踪
activesupport (4.1.0) lib/active_support/dependencies.rb:478:in `load_missing_constant'
activesupport (4.1.0) lib/active_support/dependencies.rb:180:in `const_missing'
activesupport (4.1.0) lib/active_support/inflector/methods.rb:238:in `const_get'
activesupport (4.1.0) lib/active_support/inflector/methods.rb:238:in `block in constantize'
activesupport (4.1.0) lib/active_support/inflector/methods.rb:236:in `each'
activesupport (4.1.0) lib/active_support/inflector/methods.rb:236:in `inject'
activesupport (4.1.0) lib/active_support/inflector/methods.rb:236:in `constantize'
activesupport (4.1.0) lib/active_support/dependencies.rb:552:in `get'
activesupport (4.1.0) lib/active_support/dependencies.rb:583:in `constantize'
actionpack (4.1.0) lib/action_dispatch/routing/route_set.rb:76:in `controller_reference'
actionpack (4.1.0) lib/action_dispatch/routing/route_set.rb:66:in `controller'
actionpack (4.1.0) lib/action_dispatch/routing/route_set.rb:44:in `call'
actionpack (4.1.0) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.1.0) lib/action_dispatch/journey/router.rb:59:in `each'
actionpack (4.1.0) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.1.0) lib/action_dispatch/routing/route_set.rb:676:in `call'
warden (1.2.4) lib/warden/manager.rb:35:in `block in call'
warden (1.2.4) lib/warden/manager.rb:34:in `catch'
warden (1.2.4) lib/warden/manager.rb:34:in `call'
rack (1.5.5) lib/rack/etag.rb:23:in `call'
rack (1.5.5) lib/rack/conditionalget.rb:25:in `call'
rack (1.5.5) lib/rack/head.rb:11:in `call'
actionpack (4.1.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.1.0) lib/action_dispatch/middleware/flash.rb:254:in `call'
rack (1.5.5) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.5.5) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.1.0) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.1.0) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.1.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:621:in `call'
activerecord (4.1.0) lib/active_record/migration.rb:380:in `call'
actionpack (4.1.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.1.0) lib/active_support/callbacks.rb:82:in `run_callbacks'
actionpack (4.1.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.1.0) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.1.0) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
rollbar (2.4.0) lib/rollbar/middleware/rails/rollbar.rb:24:in `block in call'
rollbar (2.4.0) lib/rollbar.rb:842:in `scoped'
rollbar (2.4.0) lib/rollbar/middleware/rails/rollbar.rb:22:in `call'
actionpack (4.1.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
rollbar (2.4.0) lib/rollbar/middleware/rails/show_exceptions.rb:22:in `call_with_rollbar'
actionpack (4.1.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.1.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.1.0) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.1.0) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.1.0) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.1.0) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.1.0) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.1.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.5) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.5) lib/rack/runtime.rb:17:in `call'
activesupport (4.1.0) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
rack (1.5.5) lib/rack/lock.rb:17:in `call'
actionpack (4.1.0) lib/action_dispatch/middleware/static.rb:64:in `call'
rack (1.5.5) lib/rack/sendfile.rb:112:in `call'
railties (4.1.0) lib/rails/engine.rb:514:in `call'
railties (4.1.0) lib/rails/application.rb:144:in `call'
rack (1.5.5) lib/rack/lock.rb:17:in `call'
rack (1.5.5) lib/rack/content_length.rb:14:in `call'
rack (1.5.5) lib/rack/handler/webrick.rb:60:in `service'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread'
控制器/ connections_controller.rb
class ConnectionionsController < ApplicationController
def new
@connection = connection.new
end
def create
@connection = Connection.new(connection_params)
if @connection.save
name = params[:connection][:your_name]
email = params[:connection][:email]
body = params[:connection][:mentors_name, :mentees_name]
connectionMailer.connection_email(name, email, body).deliver
flash[:success] = "Message sent. Someone at Jr. Dev Mentoring will respond to your message soon. Thank you."
redirect_to new_connection_path
else
flash[:danger] = "Error occured, message has not been sent. You must complete all form fields"
redirect_to new_connection_path
end
end
private
def connection_params
params.require(:connection).permit(:your_name, :email, :mentors_name, :mentees_name)
end
end
寄件人/ connection_mailer.rb
class ConnectionsMailer < ActionMailer::Base
default to: 'info@jrdevmentoring.com'
def connection_email(name, email, body)
@name = name
@email = email
@body = body
mail(from: email, subject: 'Jr. Dev Mentoring Connect Form Message')
end
end
模型/ connection.rb
class Connection < ActiveRecord::Base
validates :your_name, presence: true
validates :email, presence: true
end
视图/连接/ new.html.erb
<div class="row">
<div class="col-md-4 col-md-offset-4">
<h1 class="text-center">Let's Connect</h1>
<p class="text-center">I'd like to connect</p>
<div class="well">
<%= form_for @connection do |f| %>
<div class="form-group">
<%= f.label :your_name %>
<%= f.text_field :your_name, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :email %>
<%= f.email_field :email, class: 'form-control' %>
</div>
<div class="form-group, 'Mentors Name'">
<%= f.label :comments %>
<%= f.text_area :mentors_name, class: 'form-control' %>
</div>
<div class="form-group, 'Mentees Name'">
<%= f.label :comments %>
<%= f.text_area :mentees_name, class: 'form-control' %>
</div>
<%= f.submit 'Submit', class: 'btn btn-default' %>
<% end %>
</div>
</div>
</div>
视图/ connection_mailer / connection_email.html.erb
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p>You have received a message from the Jr. Dev Mentoring site's connect form, from <%= "#{ @name }, #{ @email }." %></p>
<p><%= @body %></p>
</body>
</html>
分贝/迁移
class CreateConnections < ActiveRecord::Migration
def change
create_table :connections do |t|
t.string :your_name
t.string :email
t.text :mentors_name
t.text :mentees_name
t.timestamps
end
模式
create_table "connections", force: true do |t|
t.string "your_name"
t.string "email"
t.text "mentors_name"
t.text "mentees_name"
t.datetime "created_at"
t.datetime "updated_at"
end
路由
Rails.application.routes.draw do
devise_for :users,:controllers => { :registrations => "users/registrations" }
resources :users do
resource :profile
end
resources :connections
resources :contacts
get '/about' => 'pages#about'
namespace :mentee do
root 'pages#home'
get '/mentor_profiles' => 'profiles#mentor_profiles'
end
namespace :mentor do
root 'pages#home'
get '/mentee_profiles' => 'profiles#mentee_profiles'
end
root 'pages#home'
答案 0 :(得分:0)
我在connections_controller.rb
文件
class ConnectionionsController < ApplicationController
替换为class ConnectionsController < ApplicationController
@connection = connection.new
替换为@connection = Connection.new
connectionMailer.connection_email(name, email, body).deliver
替换为ConnectionMailer.connection_email(name, email, body).deliver