我有一个users_controller里面有这个功能:
def process_csv
puts 'processing csv file'
end
然后我有一个带有"link_to"标签的show.html.erb文件。
<%= link_to 'Click HERE to open file', @user.image.url %><br/><br/><br/>
<%= label_tag(:q, "Parse CSV File:") %><br/>
<%= link_to 'Parse CSV', {:controller => "users", :action => "process" } %>
<% end %>
这是我的耙子路线的输出:
process_users GET /users/process(.:format) users#process
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
listings GET /listings(.:format) listings#index
POST /listings(.:format) listings#create
new_listing GET /listings/new(.:format) listings#new
edit_listing GET /listings/:id/edit(.:format) listings#edit
listing GET /listings/:id(.:format) listings#show
PUT /listings/:id(.:format) listings#update
DELETE /listings/:id(.:format) listings#destroy
这是我的路线.rb文件
resources :users do
collection do
get:process
end
end
资源 :列表
当我点击 show.html.erb 文件中的链接时。我希望被引导到这个过程.html.erb视图。相反,我收到一个错误:
Routing Error
No route matches [GET] "/assets"
我尝试了很多切换组合,但还没有奏效。所以我想知道是否有人可以帮我一把。
谢谢
是由"assets"引起的,而不是"routes",因此请确保您正确使用了"asset-pipeline"。
如果您处于"开发"模式,请将所有图像/JS/CSS放在"应用程序/资产"文件夹下。
如果您处于"生产"模式,请确保您已完成此操作:bundle exec rake assets:precompile
有关资产管道的更多信息,请参阅:http://guides.rubyonrails.org/asset_pipeline.html#in-production
顺便说一句,由于您使用的是 RESTful 路由,请将您的"link_to"从 :
<%= link_to 'Parse CSV', {:controller => "users", :action => "process" } %>
自:
<%= link_to 'Parse CSV', process_csv_users_path %>
同时,为相应的操作指定一个更具可读性的名称:
resources :users do
collection do
get :process_csv
end
end
在控制器中:
class UsersController ...
def process_csv
puts "bla bla bla"
end
end