我使用以下脚手架
创建了此表单rails generate scaffold Adminlocations city:string state:string zip:integer long:integer lat:integer
当我在表单中输入新位置时,我收到以下错误:(我没有看到"加入"编码中的任何地方)
2014-04-30 08:15:21 INFO -- Processing by AdminlocationsController#create as HTML
2014-04-30 08:15:21 INFO -- Parameters: {"utf8"=>"✓", "authenticity_token"=>"U27TufEFF9UYznNMB/OzkEIEPSSBScKqPH/MOdzC9kQ=", "adminlocation"=>{"city"=>"Springfield", "state"=>"Mo", "zip"=>"65803", "long"=>"123", "lat"=>"123"}, "commit"=>"Create Adminlocation"}
2014-04-30 08:15:21 INFO -- Redirected to
2014-04-30 08:15:21 INFO -- Completed 500 Internal Server Error in 539ms
2014-04-30 08:15:21 FATAL --
NoMethodError (undefined method `join' for nil:NilClass):
app/controllers/adminlocations_controller.rb:40:in `block (2 levels) in create'
app/controllers/adminlocations_controller.rb:38:in `create'
2014-04-30 08:15:21 INFO -- Processing by InfoController#error as HTML
2014-04-30 08:15:21 INFO -- Parameters: {"utf8"=>"✓", "authenticity_token"=>"U27TufEFF9UYznNMB/OzkEIEPSSBScKqPH/MOdzC9kQ=", "adminlocation"=>{"city"=>"Springfield", "state"=>"Mo", "zip"=>"65803", "long"=>"123", "lat"=>"123"}, "commit"=>"Create Adminlocation"}
2014-04-30 08:15:21 INFO -- Rendered info/error.html.haml within layouts/application (0.3ms)
2014-04-30 08:15:22 INFO -- Rendered shared/_navbar.html.haml (300.7ms)
2014-04-30 08:15:22 INFO -- Rendered shared/_footer.html.haml (0.3ms)
2014-04-30 08:15:22 INFO -- Completed 200 OK in 617ms (Views: 30.5ms | ActiveRecord: 575.7ms)
2014-04-30 08:15:22 INFO --
这是控制器中的相应区块
def create
@adminlocation = Adminlocation.new(params[:adminlocation])
respond_to do |format|
if @adminlocation.save
format.html { redirect_to @adminlocation, notice: 'Adminlocation was successfully created.' }
format.json { render json: @adminlocation, status: :created, location: @adminlocation }
else
format.html { render action: "new" }
format.json { render json: @adminlocation.errors, status: :unprocessable_entity }
end
end
end
这是生成表单的输出:
[root@digihaul3-pc current]# rails generate scaffold Adminlocations city:string state:string zip:integer long:integer lat:integer
SECURITY WARNING: No secret option provided to Rack::Session::Cookie.
This poses a security threat. It is strongly recommended that you
provide a secret to prevent exploits that may be possible from crafted
cookies. This will not be supported in future versions of Rack, and
future versions will even invalidate your existing user cookies.
Called from: /home/deployer/loadmax/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/session/abstract_store.rb:28:in `initialize'.
Plural version of the model detected, using singularized version. Override with --force-plural.
invoke active_record
create db/migrate/20140429172723_create_adminlocations.rb
create app/models/adminlocation.rb
invoke test_unit
create test/unit/adminlocation_test.rb
create test/fixtures/adminlocations.yml
route resources :adminlocations
invoke scaffold_controller
create app/controllers/adminlocations_controller.rb
invoke erb
create app/views/adminlocations
create app/views/adminlocations/index.html.erb
create app/views/adminlocations/edit.html.erb
create app/views/adminlocations/show.html.erb
create app/views/adminlocations/new.html.erb
create app/views/adminlocations/_form.html.erb
invoke test_unit
create test/functional/adminlocations_controller_test.rb
invoke helper
create app/helpers/adminlocations_helper.rb
invoke test_unit
create test/unit/helpers/adminlocations_helper_test.rb
invoke assets
invoke coffee
create app/assets/javascripts/adminlocations.js.coffee
invoke scss
create app/assets/stylesheets/adminlocations.css.scss
invoke scss
create app/assets/stylesheets/scaffolds.css.scss
我必须手动创建数据库并为其提供正确的权限
请求信息
class Adminlocation < ActiveRecord::Base
attr_accessible :city, :lat, :long, :state, :zip
end
答案 0 :(得分:0)
尝试:
rails generate scaffold Adminlocation city:string state:string zip:integer long:integer lat:integer
在rails generate scaffold
中您提供了型号名称。型号名称应该始终是单数! (看看你的错误消息)