format.HTML { redirect_to controller: "my_objects",action: "index",notice: 'Saved successfully.' }
但是,当我重定向时,实际上是URL
http://mydomein.devBox.com:3000/my_objects
我想要它
http://mydomein.devBox.com:3000/my_objects/index
如何强制URL为“/ index”而不是现在出现的?
编辑:以下是访问/ my_objects / index时的日志:
Started GET "/my_objects/index" for 127.0.0.1 at 2016-07-12 12:17:25 -0500Processing by MyObjectsController#index as HTMLDEPRECATION WARNING: Passing a nested array to Active Record finder methods is deprecated and will be removed. Flatten your array before using it for 'IN' conditions. (called from country_code_select at /Users/davea/documents/workspace/runtrax/app/helpers/user_form_helper.rb:83) Rendered my_objects/_add.HTML.erb (31.0ms) Rendered my_objects/index.HTML.erb within layouts/race (46.0ms) Rendered layouts/_navigation.HTML.erb (0.2ms) Rendered layouts/_messages.HTML.erb (0.1ms) Rendered my_objects/_tabs.HTML.erb (0.3ms)Completed 200 OK in 308ms (VIEws: 301.9ms | ActiveRecord: 4.8ms)
编辑:这是config / routes.rb文件中的相关部分……
get 'my_objects/index' get 'my_objects/create' resources :my_objects do collection do post 'create' get 'import' get 'index' => 'my_objects/index' get 'search' get 'stats' end end解决方法 rails惯例重定向的URL正在重定向到索引 *** 作.检查您的日志以查看发生的情况.如果您执行/ my_objects / index,那么您需要使用ID = index的my_object. 总结
以上是内存溢出为你收集整理的ruby-on-rails-4 – 如何在Rails重定向后强制使用某个URL?全部内容,希望文章能够帮你解决ruby-on-rails-4 – 如何在Rails重定向后强制使用某个URL?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)