最近自己学了学 ruby on rails,已经根据 rails 指南的教材编写了一个简单的小程序,现在想把这个东西做成 redmine 的插件。 但是提交表单的时间出了问题,苦恼了很久,网上也找不到相关的资料,求助! 以下是路由的代码:
get 'notes', :to => 'notes#index'
get 'notes/new(.:format)', :to => 'notes#new'
post '/notes(.:format)', :to => 'notes#create'
这里是页面代码:
<%= form_for :note, url: notes_path do |f| %>
<p>
<%= f.label :姓名 %><br>
<%= f.text_field :name %>
</p>
<p>
<%= f.label :部门 %><br>
<%= f.text_field :department %>
</p>
<p>
<%= f.label :岗位 %><br>
<%= f.text_field :position %>
</p>
<p>
<%= f.label :请假时间 %><br>
<%= f.text_field :time %>
</p>
<p>
<%= f.label :请假事由 %><br>
<%= f.text_area :text %>
</p>
<p>
<%= f.label :主管意见 %><br>
<%= f.text_field :opinion %>
</p>
<p>
<%= f.submit:提交 %>
</p>
<% end %>`
在最后提交表单的时候出了问题
这里是 controller 代码:
class NotesController < ApplicationController
def index
@notes = Note.all
end
def new
end
def create
@note = Note.new(note_params)
@note.save
redirect_to :action => 'index'
end
def show
@note= Note.find(params[:id])
end
private
def note_params
params.require(:note).permit(:name,:department,:position,:time,:text,:opinion)
end
end
最后是报错信息:
Started POST "/notes" for 127.0.0.1 at 2014-11-24 22:23:56 +0800
Processing by NotesController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"u8Q0hqZOgEce4iOX8/vWrR8tWM9qwes7ffisYnXE1vI=", "note"=>{"name"=>"", "department"=>"", "position"=>"", "time"=>"", "text"=>"", "opinion"=>""}, "commit"=>"提交"}
Current user: anonymous
Completed 500 Internal Server Error in 71.9ms
TypeError (no implicit conversion of Symbol into String):
activesupport (3.2.19) lib/active_support/dependencies.rb:251:in `require'
activesupport (3.2.19) lib/active_support/dependencies.rb:251:in `block in require'
activesupport (3.2.19) lib/active_support/dependencies.rb:236:in `load_dependency'
activesupport (3.2.19) lib/active_support/dependencies.rb:251:in `require'
plugins/notes/app/controllers/notes_controller.rb:18:in `note_params'
plugins/notes/app/controllers/notes_controller.rb:8:in `create'
actionpack (3.2.19) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.2.19) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.19) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.19) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.2.19) lib/active_support/callbacks.rb:480:in `_run__542389636927640692__process_action__3294544606366668215__callbacks'
activesupport (3.2.19) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.19) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
activesupport (3.2.19) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.19) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.2.19) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (3.2.19) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.2.19) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.19) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.19) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.19) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.2.19) lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
activerecord (3.2.19) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.2.19) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.2.19) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.19) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.19) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.19) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.19) lib/action_dispatch/routing/route_set.rb:73:in `call'
actionpack (3.2.19) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (3.2.19) lib/action_dispatch/routing/route_set.rb:36:in `call'
journey (1.0.4) lib/journey/router.rb:68:in `block in call'
journey (1.0.4) lib/journey/router.rb:56:in `each'
journey (1.0.4) lib/journey/router.rb:56:in `call'
actionpack (3.2.19) lib/action_dispatch/routing/route_set.rb:608:in `call'
rack-openid (1.4.2) lib/rack/openid.rb:98:in `call'
request_store (1.0.5) lib/request_store/middleware.rb:9:in `call'
actionpack (3.2.19) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.5) lib/rack/etag.rb:23:in `call'
rack (1.4.5) lib/rack/conditionalget.rb:35:in `call'
actionpack (3.2.19) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.19) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.19) lib/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.4.5) lib/rack/session/abstract/id.rb:210:in `context'
rack (1.4.5) lib/rack/session/abstract/id.rb:205:in `call'
actionpack (3.2.19) lib/action_dispatch/middleware/cookies.rb:341:in `call'
activerecord (3.2.19) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.19) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
actionpack (3.2.19) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.19) lib/active_support/callbacks.rb:405:in `_run__2302799743034094018__call__3164167435205094136__callbacks'
activesupport (3.2.19) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.19) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.19) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.19) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.19) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.19) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.19) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.19) lib/rails/rack/logger.rb:32:in `call_app'
railties (3.2.19) lib/rails/rack/logger.rb:16:in `block in call'
activesupport (3.2.19) lib/active_support/tagged_logging.rb:22:in `tagged'
railties (3.2.19) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.19) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.5) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.5) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.19) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.5) lib/rack/lock.rb:15:in `call'
actionpack (3.2.19) lib/action_dispatch/middleware/static.rb:63:in `call'
rack-cache (1.2) lib/rack/cache/context.rb:136:in `forward'
rack-cache (1.2) lib/rack/cache/context.rb:143:in `pass'
rack-cache (1.2) lib/rack/cache/context.rb:155:in `invalidate'
rack-cache (1.2) lib/rack/cache/context.rb:71:in `call!'
rack-cache (1.2) lib/rack/cache/context.rb:51:in `call'
railties (3.2.19) lib/rails/engine.rb:484:in `call'
railties (3.2.19) lib/rails/application.rb:231:in `call'
rack (1.4.5) lib/rack/content_length.rb:14:in `call'
railties (3.2.19) lib/rails/rack/log_tailer.rb:17:in `call'
rack (1.4.5) lib/rack/handler/webrick.rb:59:in `service'
/usr/local/Cellar/ruby/2.1.4/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
/usr/local/Cellar/ruby/2.1.4/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
/usr/local/Cellar/ruby/2.1.4/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
求助!为什么提交表单的时候出出这样的错误呢?