【发布时间】:2015-03-29 04:13:01
【问题描述】:
我正在尝试创建一个从动作“other_hello”到动作“index”的简单重定向。现在,当我使用 url “localhost:3000/demo/other_hello”从浏览器发出 GET 请求时,它正在重定向到主页。我希望它被重定向到索引操作,然后呈现“演示/你好”视图。我当前的控制器如下所示:
class DemoController < ApplicationController
layout false
def index
render('demo/hello')
end
def hello
render('demo/index')
end
def other_hello
redirect_to(:controller => 'demo', :action => 'index')
end
end
我当前的文件夹结构如下:
[root@vc2cmmkb036933n simple_cms]# tree
.
├── app
│ ├── assets
│ │ ├── images
│ │ │ └── rails.png
│ │ ├── javascripts
│ │ │ ├── application.js
│ │ │ └── demo.js
│ │ └── stylesheets
│ │ ├── application.css
│ │ └── demo.css
│ ├── controllers
│ │ ├── application_controller.rb
│ │ └── demo_controller.rb
│ ├── helpers
│ │ ├── application_helper.rb
│ │ └── demo_helper.rb
│ ├── mailers
│ ├── models
│ └── views
│ ├── demo
│ │ ├── hello.html.erb
│ │ └── index.html.erb
│ └── layouts
│ └── application.html.erb
├── config
│ ├── application.rb
│ ├── boot.rb
│ ├── database.yml
│ ├── environment.rb
│ ├── environments
│ │ ├── development.rb
│ │ ├── production.rb
│ │ └── test.rb
│ ├── initializers
│ │ ├── backtrace_silencers.rb
│ │ ├── inflections.rb
│ │ ├── mime_types.rb
│ │ ├── secret_token.rb
│ │ ├── session_store.rb
│ │ └── wrap_parameters.rb
│ ├── locales
│ │ └── en.yml
│ └── routes.rb
├── config.ru
├── db
│ └── seeds.rb
├── doc
│ └── README_FOR_APP
├── Gemfile
├── Gemfile.lock
├── lib
│ ├── assets
│ └── tasks
├── log
│ └── development.log
├── public
│ ├── 404.html
│ ├── 422.html
│ ├── 500.html
│ ├── demo
│ │ └── test.html
│ ├── favicon.ico
│ ├── index.html
│ └── robots.txt
├── Rakefile
├── README.rdoc
├── script
│ └── rails
├── test
│ ├── fixtures
│ ├── functional
│ │ └── demo_controller_test.rb
│ ├── integration
│ ├── performance
│ │ └── browsing_test.rb
│ ├── test_helper.rb
│ └── unit
│ └── helpers
│ └── demo_helper_test.rb
├── tmp
│ ├── cache
│ │ └── assets
│ │ ├── CF0
│ │ │ └── DA0
│ │ │ └── sprockets%2Fd7d5b37686831d37c4dd75e645f5e016
│ │ └── E25
│ │ └── 4C0
│ │ └── sprockets%2Fde2fd9fd11c04a582cdbbe3d84a35ae6
│ ├── pids
│ │ └── server.pid
│ ├── sessions
│ └── sockets
└── vendor
├── assets
│ ├── javascripts
│ └── stylesheets
└── plugins
47 directories, 50 files
为了格外小心,我的 routes.rb 文件如下所示:
SimpleCms::Application.routes.draw do
# get "demo/index"
root :to => "demo#index"
match ':controller(/:action(/:id))', :via => :get
end
我目前使用的是 Ruby 1.9.3 和 Rails 3.2.3。
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-3 http-redirect