post - Rails 4: TypeError no implicit conversion of Symbol into String -


i relatively new rails , encountered seems common problem after reading through responses, cannot seem make work situation.

i have app keeps track of loans , users, , trying add payment feature. when try reach payment page encounter typeerror: no implicit conversion of symbol string. have tried bunch of things nothing seems work. i'm not sure if how trying access loan_id or else.

the error encountered in paymentscontroller#create

here view:

show.html.erb

<p id="notice"><%= notice %></p>  <div class="row">   <div class="col-md-2">     <ul>       <li><strong>lender</strong>: <%= @loan.lender.username %></li>       <li><strong>borrower</strong>: <%= @loan.borrower.username %></li>       <li><strong>amount remaining</strong>: <%= @loan.amount %></li>       <li><%= link_to "new payment", loan_payments_path(@loan.id), :method => :post %></li>     </ul>     <section>     </section>   </div> </div>  <%= link_to 'edit', edit_loan_path(@loan) %> | <%= link_to 'back', loans_path %> 

app/controllers/payments_controller

class paymentscontroller < applicationcontroller    # post /loans/:loan_id/payments   def create     @loan = loan.find(params[:loan_id])     @loan.make_payment(payment)     if @load.save       redirect_to @loan, notice: "payment successful"     else       redirect_to @loan, alert: "payment count not processed"     end    end    private     def payment     require(:loan).require(:payment)[:payment]   end  end 

routes

rails.application.routes.draw   devise_for :users   resources :users, only: [:index, :show]   resources :loans, shallow: :true     resources :payments, only: :create   end   root 'static_pages#home' end    prefix verb   uri pattern                        controller#action         new_user_session    /users/sign_in(.:format)           devise/sessions#new             user_session post   /users/sign_in(.:format)           devise/sessions#create     destroy_user_session delete /users/sign_out(.:format)          devise/sessions#destroy            user_password post   /users/password(.:format)          devise/passwords#create        new_user_password    /users/password/new(.:format)      devise/passwords#new       edit_user_password    /users/password/edit(.:format)     devise/passwords#edit                          patch  /users/password(.:format)          devise/passwords#update                          put    /users/password(.:format)          devise/passwords#update cancel_user_registration    /users/cancel(.:format)            devise/registrations#cancel        user_registration post   /users(.:format)                   devise/registrations#create    new_user_registration    /users/sign_up(.:format)           devise/registrations#new   edit_user_registration    /users/edit(.:format)              devise/registrations#edit                          patch  /users(.:format)                   devise/registrations#update                          put    /users(.:format)                   devise/registrations#update                          delete /users(.:format)                   devise/registrations#destroy                    users    /users(.:format)                   users#index                     user    /users/:id(.:format)               users#show            loan_payments post   /loans/:loan_id/payments(.:format) payments#create                    loans    /loans(.:format)                   loans#index                          post   /loans(.:format)                   loans#create                 new_loan    /loans/new(.:format)               loans#new                edit_loan    /loans/:id/edit(.:format)          loans#edit                     loan    /loans/:id(.:format)               loans#show                          patch  /loans/:id(.:format)               loans#update                          put    /loans/:id(.:format)               loans#update                          delete /loans/:id(.:format)               loans#destroy                     root    /                                  static_pages#home 

parameters

{"_method"=>"post",  "authenticity_token"=>"vi7rp4n2ehw+tpky2nod/so9vngky/ue06052vj1f4qidnzgdjzt3av5v8+xzms2zqiuwe0xzamsqpwltft6lg==",  "loan_id"=>"5"} 

your problem in method:

def payment   require(:loan).permit(:payment)[:payment] end 

fix to:

def payment   params.permit(:loan_id) end 

read how permit params in rails.

update:

now error actioncontroller::parametermissing in paymentscontroller#create param missing or value empty: loan

this normal behavior, because parameters empty, sent nothing action, except load_id, send params @load attributes, pass loan_payments_path() helper, like:

  <li><%= link_to "new payment", loan_payments_path(@loan.id, params: { loan_amount: @loan.amount }), :method => :post %></li> 

and permit in controller code:

def payment   params.permit(:loan_id, :loan_amount) end 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -