Я видел ответ на этот вопрос здесь для Rails 2, но не для Rails 3.
У меня есть приложение, которое я запускаю на локальном хосте, называемое Skynet, которое обеспечивает доступ одним щелчком к сценариям, которые яиспользуйте регулярно:
У меня есть:
config / rout.rb:
Skynet::Application.routes.draw do
resources :robots do
member do
get "cleaner"
end
end
end
app / controllers / robots_controller.rb:
class RobotsController < ApplicationController
def index
respond_to do |format|
format.html
end
end
def cleaner
@output = ''
f = File.open("/Users/steven/Code/skynet/public/input/input.txt", "r")
f.each_line do |line|
@output += line
end
output = Sanitize.clean(@output, :elements => ['title', 'h1', 'h2', 'h3', 'h4', 'p', 'td', 'li'], :attributes => {:all => ['class']}, :remove_contents => ['script'])
newfile = File.new("/Users/steven/Code/skynet/public/output/result.txt", "w")
newfile.write(output)
newfile.close
redirect_to :action => "index"
end
end
(Рефакторинг позже.)
В app / views / robots / index.html.haml у меня есть:
= link_to "test", cleaner_robot_path
Когда я набираю рейк-маршруты, я получаю:
cleaner_robot GET /robots/:id/cleaner(.:format) {:controller=>"robots", :action=>"cleaner"}
Так почему же тогда, когда я указываю своему браузеру на http://localhost:3000/,, я получаю следующее?
ActionController::RoutingError in Robots#index
Showing /Users/steven/Code/skynet/app/views/robots/index.html.haml where line #1 raised:
No route matches {:action=>"cleaner", :controller=>"robots"}
Extracted source (around line #1):
1: = link_to "test", cleaner_robot_path
Rails.root: /Users/steven/Code/skynet
Application Trace | Framework Trace | Full Trace
app/views/robots/index.html.haml:1:in `_app_views_robots_index_html_haml___2129226934_2195069160_0'
app/controllers/robots_controller.rb:4:in `index'
Request
Parameters:
None
Show session dump
Show env dump
Response
Headers:
None