如何更改':action =>" index"' to':action =>" list"'?
我使用的是ruby 2.0.0和Rails 3.1.3。
背景: 我正在摆弄比特币中心。当我转到htt *:// localhost:3000 / admin / pending_transfers时,会发生丢失的模板错误。这是因为活跃的脚手架虫。要正确渲染,必须使用" list"行动。我可以通过将list.html.erb复制到index.html.erb来修复它,但它的解决方案似乎很脏。
这是我的佣金路线
Machida-no-MacBook-Air:bitcoin-central machidahiroaki$ rake routes | grep index
[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
invoices GET /invoices(.:format) {:action=>"index", :controller=>"invoices"}
user_yubikeys GET /user/yubikeys(.:format) {:action=>"index", :controller=>"yubikeys"}
user_bank_accounts GET /user/bank_accounts(.:format) {:action=>"index", :controller=>"bank_accounts"}
user_tickets GET /user/tickets(.:format) {:action=>"index", :controller=>"tickets"}
account_transfers GET /account/transfers(.:format) {:action=>"index", :controller=>"transfers"}
account_trades GET /account/trades(.:format) {:action=>"index", :controller=>"trades"}
account_invoices GET /account/invoices(.:format) {:action=>"index", :controller=>"invoices"}
account_trade_orders GET /account/trade_orders(.:format) {:action=>"index", :controller=>"trade_orders"}
admin_announcements GET /admin/announcements(.:format) {:action=>"index", :controller=>"admin/announcements"}
admin_yubikeys GET /admin/yubikeys(.:format) {:action=>"index", :controller=>"admin/yubikeys"}
admin_static_pages GET /admin/static_pages(.:format) {:action=>"index", :controller=>"admin/static_pages"}
admin_currencies GET /admin/currencies(.:format) {:action=>"index", :controller=>"admin/currencies"}
admin_tickets GET /admin/tickets(.:format) {:action=>"index", :controller=>"admin/tickets"}
admin_comments GET /admin/comments(.:format) {:action=>"index", :controller=>"admin/comments"}
admin_pending_transfers GET /admin/pending_transfers(.:format) {:action=>"index", :controller=>"admin/pending_transfers"}
admin_user_account_operations GET /admin/users/:user_id/account_operations(.:format) {:action=>"index", :controller=>"admin/account_operations"}
admin_users GET /admin/users(.:format) {:action=>"index", :controller=>"admin/users"}
这是我的routes.rb
BitcoinBank::Application.routes.draw do
resources :invoices, :only => [:index, :new, :create, :show, :destroy]
resource :user, :only => [:edit, :update] do
get :ga_otp_configuration
post :reset_ga_otp_secret
put :update_password
get :edit_password
resources :yubikeys, :only => [:index, :create, :destroy]
resources :bank_accounts, :only => [:index, :create, :destroy]
resources :tickets do
resources :comments, :only => :create
member do
post :close
post :reopen
post :solve
end
end
end
devise_for :users, :controllers => { :registrations => "registrations" }
# These routes need some loving :/
resource :chart, :path => "charts", :only => [] do
get :price
end
resource :account, :only => [:show] do
match '/balance/:currency',
:action => 'balance',
:as => 'balance',
:only => :get
get :deposit
get :pecunix_deposit_form
resources :transfers, :only => [:index, :new, :create, :show]
resources :trades,
:only => [:index]
resources :invoices
resources :trade_orders, :only => [:index, :new, :create, :destroy] do
post :activate
end
end
match "/s/:name" => "static_pages#show", :as => :static
match '/third_party_callbacks/:action',
:controller => :third_party_callbacks
namespace :admin do
%w{ announcements yubikeys static_pages currencies tickets comments }.each { |r| resources(r.to_sym) {as_routes} }
resources :pending_transfers do
as_routes
member do
post :process_tx
end
end
resources :users do
as_routes
member do
get :balances
end
resources :account_operations do
as_routes
end
end
match '/balances', :to => 'informations#balances', :as => :balances
end
match '/qrcode/:data.png' => 'qrcodes#show', :as => :qrcode
match '/order_book' => 'trade_orders#book'
match '/trades' => 'trades#all_trades'
match '/ticker' => 'trades#ticker'
match '/economy' => 'informations#economy', :as => :economy
match '/support' => 'informations#support', :as => :support
root :to => 'informations#welcome'
end
我已删除了应用程序视图目录中的list.html.erb,并将此代码放在application_controller.rb上
def index
render :action => 'list'
end
没有被召唤。并发生模板缺失错误。
当我将上面的代码放在users_controller上时,我收到了这个错误。
NoMethodError in Admin/users#index
Showing /Users/machidahiroaki/.rvm/gems/ruby-2.0.0-p451/gems/active_scaffold-3.2.20/frontends/default/views/_list_messages.html.erb where line #21 raised:
undefined method `items' for nil:NilClass
Extracted source (around line #21):
18: </div>
19: <% end -%>
20: </div>
21: <p id="<%= empty_message_id %>" class="empty-message" <%= ' style="display:none;" '.html_safe unless @page.items.empty? %>>
22: <%= as_(active_scaffold_config.list.no_entries_message) %>
23: </p>
24: </td>
Trace of template inclusion: /Users/machidahiroaki/.rvm/gems/ruby-2.0.0-p451/gems/active_scaffold-3.2.20/frontends/default/views/_list.html.erb, /Users/machidahiroaki/.rvm/gems/ruby-2.0.0-p451/gems/active_scaffold-3.2.20/frontends/default/views/_list_with_header.html.erb, /Users/machidahiroaki/.rvm/gems/ruby-2.0.0-p451/gems/active_scaffold-3.2.20/frontends/default/views/list.html.erb
Rails.root: /Volumes/G-DRIVE_slim/Development/bitcoin-central
Application Trace | Framework Trace | Full Trace
app/controllers/admin/users_controller.rb:94:in `index'
config/initializers/monkey_patches.rb:8:in `call'