2017-01-02 27 views
0

当我访问本地主机:3000, 我的浏览器在ConnectionController#index中告诉错误NoMethodError。 此外,我被告知ConnectionController(表不存在)的未定义方法`行动':类。ConnectionController中的NoMethodError#index

错误浏览器告诉26行的connection_controller.rb是错误的,但我没有像26行一样编写代码。

send(name, *arguments, &block) 
 
     else 
 
     super 
 
     end 
 
    end

我写的,在connection_controller.rb

class ConnectionController < ActiveRecord::Base 
 
    def index 
 
     personal = {'name'=>'Yamada','old'=>28} 
 
     render :json => personal 
 

 
    end 
 
end

在routes.rb中

Rails.application.routes.draw do 
 

 

 
    namespace :connection do 
 
     get '/',action:'index' 
 
    end 
 
end

在schema.rb

ActiveRecord::Schema.define(version: 20170101073143) do 
 

 
    create_table "userdata", force: :cascade do |t| 
 
    t.datetime "created_at", null: false 
 
    t.datetime "updated_at", null: false 
 
    end 
 

 
end

在迁移文件

class CreateUserdata < ActiveRecord::Migration 
 
    def change 
 
    create_table :userdata do |t| 
 
    t.string :name 
 
     t.text :image 
 
     t.timestamps null: false 
 
    end 
 
    end 
 
end

模型,

class Userdatum < ActiveRecord::Base 
 
\t user = User.new 
 
\t user.name = "XXX" 
 
\t user.email = "mail" 
 
\t user.save 
 
end

回答

0

请注意,在Rails的控制器应扩展ActionController类和模式应该扩展ActiveRecord::Base类。

您似乎已经做到了这一点

class ConnectionController < ActiveRecord::Base 
end 

控制器内。

应该

class ConnectionController < ApplicationController 
end 
相关问题