0

この関数を含む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

これは私のroutes.rbファイルです

 resources :users do
  collection do
     get:process
 end
 end

リソース:リスト

show.html.erbファイルのリンクをクリックすると。process.html.erbビューに移動することを望んでいました。代わりに、エラーが発生します。

Routing Error
No route matches [GET] "/assets"

私は物事を切り替える多くの組み合わせを試しましたが、まだ何も機能していません。だから私は誰かが私に手を差し伸べることができるかどうか疑問に思っています。

ありがとう、

4

1 に答える 1

1

エラーの原因は「assets」ですが「routes」ではないため、「asset-pipeline」を正しく使用していることを確認してください。

「開発」モードの場合は、すべてのimage / js/cssを「app/assets」フォルダーに配置してください。

「本番」モードの場合は、次のことを確認してください。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 
于 2012-05-02T04:49:31.043 に答える