ruby on rails - ActionController::ParameterMissing at /accounts/deposit tieing params to deposit form -
i have been working on rails 4 project since yesterday @ 3pm , have not slept. out of ideas why bombing out. error message : actioncontroller::parametermissing @ /accounts/deposit param missing or value empty: affiliates_account
my accounts_controller looks this:
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 |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
and model 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
and created new deposit.html.erb because new.html.erb kept giving me weird error , mention create method tied , should create seperate form page. did , im having tough time linking deposit action method page "add funds" button on index.html.erb go it. , perform requested actions accordingly.
<h1>editing account</h1> <%= render 'form' %> <%= link_to 'show', @account %> | <%= link_to 'back', accounts_path %>
my index.html.erb link_to button
<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 |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 |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 sure?' } %></td> </tr> <% end %> </tbody> </table> <br> </div> <% end %>
i think part of params hosing up, params.require(:account) dont know change works , nothing else breaks
here parameter log
started post "/__better_errors/08542fc78df5081e/variables" 127.0.0.1 @ 2015-04-25 13:31:29 -0400
started post "/accounts/deposit" 127.0.0.1 @ 2015-04-25 13:33:56 -0400 processing accountscontroller#deposit html parameters: {"authenticity_token"=>"96gx+hildjdtdppkjaa3fwx/v9ool1y1xt5pnzfrc8u="} [1m[36muser load (1.0ms)[0m [1mselect "users".* "users" "users"."id" = 1 order "users"."id" asc limit 1[0m completed 400 bad request in 58ms
actioncontroller::parametermissing - param missing or value empty: account: actionpack (4.1.8) lib/action_controller/metal/strong_parameters.rb:187:in require' app/controllers/accounts_controller.rb:80:in
account_params' app/controllers/accounts_controller.rb:62:in deposit' actionpack (4.1.8) lib/action_controller/metal/implicit_render.rb:4:in
send_action' actionpack (4.1.8) lib/abstract_controller/base.rb:189:in process_action' actionpack (4.1.8) lib/action_controller/metal/rendering.rb:10:in
process_action' 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' activesupport (4.1.8) lib/active_support/callbacks.rb:113:in call' activesupport (4.1.8) lib/active_support/callbacks.rb:166:in
block in halting' activesupport (4.1.8) lib/active_support/callbacks.rb:149:in call' activesupport (4.1.8) lib/active_support/callbacks.rb:149:in
block in halting_and_conditional' activesupport (4.1.8) lib/active_support/callbacks.rb:229:in call' activesupport (4.1.8) lib/active_support/callbacks.rb:229:in
block in halting' activesupport (4.1.8) lib/active_support/callbacks.rb:149:in call' activesupport (4.1.8) lib/active_support/callbacks.rb:149:in
block in halting_and_conditional' activesupport (4.1.8) lib/active_support/callbacks.rb:229:in call' activesupport (4.1.8) lib/active_support/callbacks.rb:229:in
block in halting' activesupport (4.1.8) lib/active_support/callbacks.rb:166:in call' activesupport (4.1.8) lib/active_support/callbacks.rb:166:in
block in halting' activesupport (4.1.8) lib/active_support/callbacks.rb:166:in call' activesupport (4.1.8) lib/active_support/callbacks.rb:166:in
block in halting' activesupport (4.1.8) lib/active_support/callbacks.rb:166:in call' activesupport (4.1.8) lib/active_support/callbacks.rb:166:in
block in halting' 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' actionpack (4.1.8) lib/abstract_controller/callbacks.rb:19:in process_action' actionpack (4.1.8) lib/action_controller/metal/rescue.rb:29:in
process_action' actionpack (4.1.8) lib/action_controller/metal/instrumentation.rb:31:in block in process_action' activesupport (4.1.8) lib/active_support/notifications.rb:159:in
block in instrument' 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' actionpack (4.1.8) lib/action_controller/metal/instrumentation.rb:30:in process_action' actionpack (4.1.8) lib/action_controller/metal/params_wrapper.rb:250:in
process_action' 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
process' actionview (4.1.8) lib/action_view/rendering.rb:30:in process' actionpack (4.1.8) lib/action_controller/metal.rb:196:in
dispatch' actionpack (4.1.8) lib/action_controller/metal/rack_delegation.rb:13:in dispatch' actionpack (4.1.8) lib/action_controller/metal.rb:232:in
block in action' 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' 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
block in call' actionpack (4.1.8) lib/action_dispatch/journey/router.rb:59:in each' actionpack (4.1.8) lib/action_dispatch/journey/router.rb:59:in
call' actionpack (4.1.8) lib/action_dispatch/routing/route_set.rb:678:in call' warden (1.2.3) lib/warden/manager.rb:35:in
block in call' warden (1.2.3) lib/warden/manager.rb:34:in catch' warden (1.2.3) lib/warden/manager.rb:34:in
call' rack (1.5.2) lib/rack/etag.rb:23:in call' rack (1.5.2) lib/rack/conditionalget.rb:35:in
call' 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' actionpack (4.1.8) lib/action_dispatch/middleware/flash.rb:254:in call' rack (1.5.2) lib/rack/session/abstract/id.rb:225:in
context' 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' 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' activerecord (4.1.8) lib/active_record/migration.rb:380:in call' actionpack (4.1.8) lib/action_dispatch/middleware/callbacks.rb:29:in
block in call' 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' 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' 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' 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' 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' railties (4.1.8) lib/rails/rack/logger.rb:20:in block in call' activesupport (4.1.8) lib/active_support/tagged_logging.rb:68:in
block in tagged' 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
tagged' 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' 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' 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' rack (1.5.2) lib/rack/lock.rb:17:in call' actionpack (4.1.8) lib/action_dispatch/middleware/static.rb:84:in
call' rack (1.5.2) lib/rack/sendfile.rb:112:in call' railties (4.1.8) lib/rails/engine.rb:514:in
call' railties (4.1.8) lib/rails/application.rb:144:in call' rack (1.5.2) lib/rack/lock.rb:17:in
call' rack (1.5.2) lib/rack/content_length.rb:14:in call' rack (1.5.2) lib/rack/handler/webrick.rb:60:in
service' c:/railsinstaller/ruby2.0.0/lib/ruby/2.0.0/webrick/httpserver.rb:138:in service' c:/railsinstaller/ruby2.0.0/lib/ruby/2.0.0/webrick/httpserver.rb:94:in
run' c:/railsinstaller/ruby2.0.0/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
started post "/__better_errors/19a4122f55bc057b/variables" 127.0.0.1 @ 2015-04-25 13:33:57 -0400
my routes
rails.application.routes.draw devise_for :users 'admin' => 'admin#index' 'users/index' 'accounts/index' 'accounts/show' resources :students root 'store#index', as: 'store' resources :orders resources :line_items resources :carts 'store/index' resources :menus resources :users resources :accounts collection post 'deposit', :action => :deposit post 'withdrawl', :action => :withdrawl end end
is correctly posted in question?
#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!
first before_action
commented , having :deposit
you should replace before_filter before_action rails 4, though before_action works,
before_action :set_account, only: [:show, :edit, :deposit, :credit, :update, :destroy]
your deposit method needs @account, :set_account needs added in before_action
Comments
Post a Comment