samedi 25 avril 2015

ActionController::ParameterMissing at /accounts/deposit tieing params to deposit form

I have been working on this rails 4 project since yesterday at 3pm and i have not slept. i am all out of ideas as to why this is bombing out. the error message i get is : ActionController::ParameterMissing at /accounts/deposit param is missing or the value is empty: affiliates_account

my accounts_controller looks like 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 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

and my Model for 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 i created a new deposit.html.erb because the new.html.erb kept giving me a weird error and someone mention that the create method is tied to that and that i should create a seperate form page. so i did and now im having a tough time linking my deposit action method to that page so that my "add funds" button on my index.html.erb will go to it. and perform the requested actions accordingly.

<h1>Editing account</h1>

<%= render 'form' %>

<%= link_to 'Show', @account %> |
<%= link_to 'Back', accounts_path %>

my index.html.erb with that 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 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 %>

i think this part of the params is hosing it up, params.require(:account) but i dont know what to do to change this so that it works and nothing else breaks

Aucun commentaire:

Enregistrer un commentaire