Benny Maas

Joined

220 Experience
0 Lessons Completed
0 Questions Solved

Activity

Posted in How to deposit, withdraw, transfer coins...

Hi Chris,

I want to create an app where I can keep track of my cryptocurrencies.

This is what I have right now:

  • Coins (can have many wallets)
    • name
    • symbol

  • Wallets (belongs_to coin)(has_many transactions)
    • coin_id
    • name
    • wtype (Type of wallet, Hardware, Exchange, Local, …)
    • address
    • balance
    • description

  • Transactions(belong_to wallet)
    • date
    • txid (Transaction ID) this should be generated when the transaction is saved to the DB. (SecureRandom.hex 32)
    • wallet_id
    • txtype (Transaction Type: Deposit, Withdraw, Transfer)
    • amount
    • amount_currency
    • description
    • old_balance (should take the actual balance from the wallet)
    • new_balance (should calculate the new balance  old_balance + amount)

The creation of coins and wallets is no problem.

Im stuck at the transaction part, the deposit and withdraw part.

Where would you put the deposit, withdraw and the transfer methods?

If you need more infos, let me know.

Benny

Posted in Devise User with separate Profile

Hi,
i am using Devise and i want to a separate profile for each user with additional informations like address, phone, mobile, ...

After Signup, the user should be forced to fill out his profile.

right now i have the standard devise user model and the profile model.

# == Schema Information
#
# Table name: users
#
#  id                     :integer          not null, primary key
#  email                  :string           default(""), not null
#  encrypted_password     :string           default(""), not null
#  reset_password_token   :string
#  reset_password_sent_at :datetime
#  remember_created_at    :datetime
#  sign_in_count          :integer          default(0), not null
#  current_sign_in_at     :datetime
#  last_sign_in_at        :datetime
#  current_sign_in_ip     :inet
#  last_sign_in_ip        :inet
#  confirmation_token     :string
#  confirmed_at           :datetime
#  confirmation_sent_at   :datetime
#  unconfirmed_email      :string
#  failed_attempts        :integer          default(0), not null
#  unlock_token           :string
#  locked_at              :datetime
#  created_at             :datetime         not null
#  updated_at             :datetime         not null
#

class User < ActiveRecord::Base

  has_one :profile, dependent: :destroy
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable
end
# == Schema Information
#
# Table name: profiles
#
#  id         :integer          not null, primary key
#  user_id    :integer
#  title      :string
#  first_name :string
#  last_name  :string
#  street     :string
#  zip        :string
#  city       :string
#  country    :string
#  phone      :string
#  mobile     :string
#  created_at :datetime         not null
#  updated_at :datetime         not null
#

class Profile < ActiveRecord::Base
  belongs_to :user

  validates :title, :first_name, :last_name, :country, :mobile, presence: true
end

Any hint how i can start?

Posted in Switch state of boolean field

Hi Chris,

i got it working.
Is this OK or is there a better way to implement this?

my routes

resources :products do
    member do
        patch :toggle_enable_status
    end
end

products_controller.rb

def toggle_enable_status
    @product.toggle!(:enabled)
end

the link in index.html.erb

<td class="product-<%= product.id %>">
    <%= link_to "#{ product.enabled ? 'Enabled' : 'Disabled' }", toggle_enable_status_product_path(product), method: :patch, remote: :true, class: "btn btn-xs btn-#{ product.enabled ? 'success' : 'warning' }"  %>
</td>

and the toggle_enabled_status.js.erb

console.log(<%= @product.enabled %>);
<% if @product.enabled == true %>
    $(".product-<%= @product.id %> > a").html('Enabled').removeClass('btn-warning').addClass('btn-success')
<% else %>
    $(".product-<%= @product.id %> > a").html('Disabled').removeClass('btn-success').addClass('btn-warning')
<% end %>
$("#product-status-<%= @product.id %>").html("<%= @product.enabled %>")

Posted in Switch state of boolean field

Hi,

on my index page i want to place a button for each record where i can switch the state from active to inactive or from inactive to active.
the button should change without refreshing the page.

How can i achieve that?

Thanks

Benny

Posted in Autocomplete a form field

Hi Chris,

thanks for your reply.
I will try your suggestion.

Posted in Autocomplete a form field

Hi,

i have the following models:
users, markets, assignments, products, sales,

a user gets an assignment, and then he should enter his sales for the assignment.

i have a sales form with the following fields:

quantity, product, price

now i want to autocomplete the product_field with the products from the product model.
only products that are in the database, no new products should get over the sales form.

Any hint how to start this?

thanks