相关疑难解决方法(0)

无法在Rails中找到关联问题

我是Ruby on Rails的新手,我显然有一个活跃的记录关联问题,但我不能自己解决它.

鉴于三个模型类及其关联:

# application_form.rb
class ApplicationForm < ActiveRecord::Base
  has_many :questions, :through => :form_questions
end

# question.rb
class Question < ActiveRecord::Base
  belongs_to :section
  has_many :application_forms, :through => :form_questions
end

# form_question.rb
class FormQuestion < ActiveRecord::Base
  belongs_to :question
  belongs_to :application_form
  belongs_to :question_type
  has_many :answers, :through => :form_question_answers
end
Run Code Online (Sandbox Code Playgroud)

但是当我执行控制器向应用程序表单添加问题时,我收到错误:

ActiveRecord::HasManyThroughAssociationNotFoundError in Application_forms#show

Showing app/views/application_forms/show.html.erb where line #9 raised:

Could not find the association :form_questions in model ApplicationForm
Run Code Online (Sandbox Code Playgroud)

谁能指出我做错了什么?

activerecord ruby-on-rails associations models

35
推荐指数
2
解决办法
2万
查看次数

"CSRF检测到"与Omniauth和Google合作

我得到了这个

OmniAuth :: Strategies :: OAuth2 ::/auth/google/callback中的CallbackError csrf_detected | CSRF检测到

我的代码:

require 'sinatra'
require "sinatra/json"
require "sinatra/config_file"
require 'omniauth-oauth2'
require 'omniauth-google-oauth2'

use Rack::Logger

config_file "config/app_config.yml"
use Rack::Session::Cookie, secret: '5fb7w345y3489f523y4h'

configure do
  enable :sessions
end

use OmniAuth::Builder do
  provider :google_oauth2, settings.google[:client_id], settings.google[:secret],
    {
      :scope => "userinfo.profile",
      :access_type => "offline",
      :prompt => "select_account consent",
      :name => "google"
    }
end

get '/list' do
  json get_list
end

get '/' do
  %Q|<a href='/auth/google'>Sign in with Google</a>|
end

get '/auth/:name/callback' do
  @auth = request.env['omniauth.auth']
  @auth.inspect
end …
Run Code Online (Sandbox Code Playgroud)

ruby sinatra oauth-2.0 omniauth

14
推荐指数
3
解决办法
2万
查看次数