我从昨天下午3点开始从事这个rails 4项目并且我没有睡觉。我完全不知道为什么这是轰炸。我得到的错误信息是:ActionController :: ParameterMissing at / accounts / deposit param丢失或值为空:affiliates_account
我的accounts_controller看起来像这样:
class AccountsController < ApplicationController
#before_action :set_account, only: [:show, :edit, :deposit, :credit,
:update, :destroy]
before_filter :set_account, only: [:show, :edit, :credit, :update, :destroy]
before_filter :authenticate_user!
respond_to :html
def index
# @accounts = Account.all
#@accounts = Account.where(id:current_user.id)
if current_user.admin?
@accounts = Account.all
else
@accounts = Account.where(email:current_user.email)
end
respond_with(@accounts)
end
def show
if current_user.admin?
@accounts = Account.all
else
@accounts = Account.where(email:current_user.email)
end
respond_with(@account)
end
def new
@account = Account.new
respond_with(@account)
end
def edit
@accounts = Account.all
end
def create
# @account = Account.new(account_params)
#@account.save
# respond_with(@account)
end
def update
@account.update(account_params)
respond_with(@account)
end
def destroy
@account.destroy
respond_with(@account)
end
def withdrawl
@account = Account.new(account_params)
@account.email = current_user.email
@account.user_id = current_user.id
end
def deposit
@account = Account.new(account_params)
@account.email = current_user.email
@account.user_id = current_user.id
respond_to do |format|
@account.save
end
redirect_to :root
end
private
def set_account
#@accounts = Account.where(id:current_user.id)
@account = Account.find(params[:id])
end
def account_params
# params[:account]
params.require(:account).permit(:created_at, :email, :credit, :debit,
:acctbal, :depotype)
end
end
和我的accounts.rb模型
class Account < ActiveRecord::Base
belongs_to :user
validates :depotype, presence: true
DEPOSIT_TYPES = [ "Check", "Credit card", "Purchase order" ]
validates :depotype, inclusion: DEPOSIT_TYPES
def final_acct_bal
accounts.to_a.sum {|account| account.final_acct_price}
end
end
我创建了一个新的deposit.html.erb,因为new.html.erb一直给我一个奇怪的错误,有人提到create方法与之相关,我应该创建一个单独的表单页面。所以我做了,现在我很难将我的存款行动方法与该页面联系起来,以便我的&#34;添加资金&#34;我的index.html.erb上的按钮会转到它。并相应地执行请求的操作。
<h1>Editing account</h1>
<%= render 'form' %>
<%= link_to 'Show', @account %> |
<%= link_to 'Back', accounts_path %>
带有link_to按钮的index.html.erb
<div class="container">
<h1>Listing Accounts Inquiries</h1>
<h2>Your Account information</h2>
<table border="3">
<table class="table table-striped">
<thead>
<tr>
<th>Date</th>
<th>Credit</th>
<th>Debit</th>
<th>Account Balance</th>
</tr>
</thead>
<tbody>
<% @accounts.each do |account| %>
<tr>
<td><%= account.created_at %></td>
<td><b><font color="green"><%=
number_to_currency(account.credit)%></b></td>
<td><b><font color="red"><%=
number_to_currency(account.debit)%></font></b></td>
<td><b><%= number_to_currency(account.acctbal)%></b>
</td>
</tr>
<% end %>
<tbody>
</table>
</table>
<%= link_to "Add Funds", deposit_accounts_path, method: :post, :class =>
"btn btn-primary btn-sm" %>
<table>
<thead>
<tr>
<th colspan="3"></th>
</tr>
</thead>
<% if can? :manage, Users%>
<tbody>
<% @accounts.each do |account| %>
<tr>
<td><%= link_to 'Show', account %></td>
<td><%= link_to 'Edit', edit_account_path(account) %></td>
<td><%= link_to 'Destroy', account, method: :delete, data: { confirm:
'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
</div>
<% end %>
我认为params的这一部分正在填补它,params.require(:account)但我不知道该怎么做才能改变它以便它可以工作而没有别的东西打破
这是参数日志
开始POST&#34; / __ better_errors / 08542fc78df5081e / variables&#34;对于127.0.0.1在2015-04-25 13:31:29 -0400
开始发布&#34; / accounts / deposit&#34;对于127.0.0.1在2015-04-25 13:33:56 - 0400 通过AccountsController处理#store为HTML 参数:{&#34; authenticity_token&#34; =&gt;&#34; 96gx + hIldjDtDpPKJAa3fwx / v9ooL1Y1xt5pNzFrC8U =&#34;} [1m [36mUser Load(1.0ms)[0m [1mSELECT&#34;用户&#34;。* FROM&#34;用户&#34;用户&#34;。&#34; id&#34; = 1 ORDER BY&#34;用户&#34;。&#34; id&#34; ASC LIMIT 1 [0m 在58毫秒内完成了400次错误请求
ActionController :: ParameterMissing - 缺少param或值为空:account:
actionpack(4.1.8)lib / action_controller / metal / strong_parameters.rb:187:require'
app/controllers/accounts_controller.rb:80:in
account_params&#39;
app / controllers / accounts_controller.rb:62:在deposit'
actionpack (4.1.8) lib/action_controller/metal/implicit_render.rb:4:in
send_action&#39;
actionpack(4.1.8)lib / abstract_controller / base.rb:189:在process_action'
actionpack (4.1.8) lib/action_controller/metal/rendering.rb:10:in
process_action&#39;
actionpack(4.1.8)lib / abstract_controller / callbacks.rb:20:in block in process_action'
activesupport (4.1.8) lib/active_support/callbacks.rb:113:in
call&#39;
activesupport(4.1.8)lib / active_support / callbacks.rb:113:在call'
activesupport (4.1.8) lib/active_support/callbacks.rb:166:in
块中暂停&#39;
activesupport(4.1.8)lib / active_support / callbacks.rb:149:在call'
activesupport (4.1.8) lib/active_support/callbacks.rb:149:in
块中的halting_and_conditional&#39;
activesupport(4.1.8)lib / active_support / callbacks.rb:229:在call'
activesupport (4.1.8) lib/active_support/callbacks.rb:229:in
块中暂停&#39;
activesupport(4.1.8)lib / active_support / callbacks.rb:149:在call'
activesupport (4.1.8) lib/active_support/callbacks.rb:149:in
块中的halting_and_conditional&#39;
activesupport(4.1.8)lib / active_support / callbacks.rb:229:在call'
activesupport (4.1.8) lib/active_support/callbacks.rb:229:in
块中暂停&#39;
activesupport(4.1.8)lib / active_support / callbacks.rb:166:在call'
activesupport (4.1.8) lib/active_support/callbacks.rb:166:in
块中暂停&#39;
activesupport(4.1.8)lib / active_support / callbacks.rb:166:在call'
activesupport (4.1.8) lib/active_support/callbacks.rb:166:in
块中暂停&#39;
activesupport(4.1.8)lib / active_support / callbacks.rb:166:在call'
activesupport (4.1.8) lib/active_support/callbacks.rb:166:in
块中暂停&#39;
activesupport(4.1.8)lib / active_support / callbacks.rb:86:in call'
activesupport (4.1.8) lib/active_support/callbacks.rb:86:in
run_callbacks&#39;
actionpack(4.1.8)lib / abstract_controller / callbacks.rb:19:在process_action'
actionpack (4.1.8) lib/action_controller/metal/rescue.rb:29:in
process_action&#39;
actionpack(4.1.8)lib / action_controller / metal / instrumentation.rb:31:在block in process_action'
activesupport (4.1.8) lib/active_support/notifications.rb:159:in
块中的仪器&#39;
activesupport(4.1.8)lib / active_support / notifications / instrumenter.rb:20:in instrument'
activesupport (4.1.8) lib/active_support/notifications.rb:159:in
instrument&#39;
actionpack(4.1.8)lib / action_controller / metal / instrumentation.rb:30:在process_action'
actionpack (4.1.8) lib/action_controller/metal/params_wrapper.rb:250:in
process_action&#39;
activerecord(4.1.8)lib / active_record / railties / controller_runtime.rb:18:in process_action'
actionpack (4.1.8) lib/abstract_controller/base.rb:136:in
进程&#39;
actionview(4.1.8)lib / action_view / rendering.rb:30:在process'
actionpack (4.1.8) lib/action_controller/metal.rb:196:in
发送&#39;
actionpack(4.1.8)lib / action_controller / metal / rack_delegation.rb:13:dispatch'
actionpack (4.1.8) lib/action_controller/metal.rb:232:in
阻止行动&#39;
actionpack(4.1.8)lib / action_dispatch / routing / route_set.rb:82:in call'
actionpack (4.1.8) lib/action_dispatch/routing/route_set.rb:82:in
dispatch&#39;
actionpack(4.1.8)lib / action_dispatch / routing / route_set.rb:50:in call'
actionpack (4.1.8) lib/action_dispatch/journey/router.rb:73:in
阻止通话&#39;
actionpack(4.1.8)lib / action_dispatch / journey / router.rb:59:each'
actionpack (4.1.8) lib/action_dispatch/journey/router.rb:59:in
来电&#39;
actionpack(4.1.8)lib / action_dispatch / routing / route_set.rb:678:call'
warden (1.2.3) lib/warden/manager.rb:35:in
块中的呼叫&#39;
warden(1.2.3)lib / warden / manager.rb:34:in catch'
warden (1.2.3) lib/warden/manager.rb:34:in
来电&#39;
rack(1.5.2)lib / rack / etag.rb:23:in call'
rack (1.5.2) lib/rack/conditionalget.rb:35:in
call&#39;
rack(1.5.2)lib / rack / head.rb:11:in call'
actionpack (4.1.8) lib/action_dispatch/middleware/params_parser.rb:27:in
call&#39;
actionpack(4.1.8)lib / action_dispatch / middleware / flash.rb:254:在call'
rack (1.5.2) lib/rack/session/abstract/id.rb:225:in
上下文&#39;
rack(1.5.2)lib / rack / session / abstract / id.rb:220:in call'
actionpack (4.1.8) lib/action_dispatch/middleware/cookies.rb:560:in
call&#39;
activerecord(4.1.8)lib / active_record / query_cache.rb:36:in call'
activerecord (4.1.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:621:in
call&#39;
activerecord(4.1.8)lib / active_record / migration.rb:380:在call'
actionpack (4.1.8) lib/action_dispatch/middleware/callbacks.rb:29:in
阻止呼叫&#39;
activesupport(4.1.8)lib / active_support / callbacks.rb:82:in run_callbacks'
actionpack (4.1.8) lib/action_dispatch/middleware/callbacks.rb:27:in
call&#39;
actionpack(4.1.8)lib / action_dispatch / middleware / reloader.rb:73:in call'
actionpack (4.1.8) lib/action_dispatch/middleware/remote_ip.rb:76:in
call&#39;
better_errors(2.1.1)lib / better_errors / middleware.rb:84:in protected_app_call'
better_errors (2.1.1) lib/better_errors/middleware.rb:79:in
better_errors_call&#39;
better_errors(2.1.1)lib / better_errors / middleware.rb:57:in call'
actionpack (4.1.8) lib/action_dispatch/middleware/debug_exceptions.rb:17:in
call&#39;
actionpack(4.1.8)lib / action_dispatch / middleware / show_exceptions.rb:30:in call'
railties (4.1.8) lib/rails/rack/logger.rb:38:in
call_app&#39;
railties(4.1.8)lib / rails / rack / logger.rb:20:block in call'
activesupport (4.1.8) lib/active_support/tagged_logging.rb:68:in
块中标记的&#39;
activesupport(4.1.8)lib / active_support / tagged_logging.rb:26:in tagged'
activesupport (4.1.8) lib/active_support/tagged_logging.rb:68:in
已标记&#39;
railties(4.1.8)lib / rails / rack / logger.rb:20:in call'
quiet_assets (1.1.0) lib/quiet_assets.rb:27:in
call_with_quiet_assets&#39;
actionpack(4.1.8)lib / action_dispatch / middleware / request_id.rb:21:in call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in
call&#39;
rack(1.5.2)lib / rack / runtime.rb:17:in call'
activesupport (4.1.8) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in
call&#39;
rack(1.5.2)lib / rack / lock.rb:17:in call'
actionpack (4.1.8) lib/action_dispatch/middleware/static.rb:84:in
call&#39;
rack(1.5.2)lib / rack / sendfile.rb:112:call'
railties (4.1.8) lib/rails/engine.rb:514:in
来电&#39;
railties(4.1.8)lib / rails / application.rb:144:in call'
rack (1.5.2) lib/rack/lock.rb:17:in
来电&#39;
rack(1.5.2)lib / rack / content_length.rb:14:in call'
rack (1.5.2) lib/rack/handler/webrick.rb:60:in
service&#39;
c:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/webrick/httpserver.rb:138:在service'
c:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/webrick/httpserver.rb:94:in
运行&#39;
c:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/webrick/server.rb:295:在start_thread中的`block&#39;
开始POST&#34; / __ better_errors / 19a4122f55bc057b / variables&#34;对于127.0.0.1在2015-04-25 13:33:57 -0400
我的路线
Rails.application.routes.draw do
devise_for :users
get 'admin' => 'admin#index'
get 'users/index'
get 'accounts/index'
get 'accounts/show'
resources :students
root 'store#index', as: 'store'
resources :orders
resources :line_items
resources :carts
get 'store/index'
resources :menus
resources :users
resources :accounts do
collection do
post 'deposit', :action => :deposit
post 'withdrawl', :action => :withdrawl
end
end
答案 0 :(得分:0)
这是否正确发布了问题?
#before_action :set_account, only: [:show, :edit, :deposit, :credit,
:update, :destroy]
before_filter :set_account, only: [:show, :edit, :credit, :update, :destroy]
before_filter :authenticate_user!
第一个before_action
被评论并且:deposit
你应该用before_action替换before_filter作为它的Rails 4,尽管before_action有效,比如
before_action :set_account, only: [:show, :edit, :deposit, :credit, :update, :destroy]
您的存款方式需要@account,因此:需要在before_action中添加set_account