Issues with Customizing the app

Alex, sorry about the two previous comments. Thanks for all your help so far. I'm now rebuilding the app to suit my needs and I'm running into a road block. I am creating a new model where there are two types of member profiles: Hosts and Users. I've successfully created both profiles and each can log in independently. My goals is to make it so that Users can buy and Hosts can List and Sell. My current model allows Host to Sign in and create listings and sell. However, sales are not being recorded in the sales page. The seller page works just fine. Another problem with my Host profile is they can Buy and I would like to prevent that. Here is my host.rb file: class Host < ActiveRecord::Base # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable validates :name, presence: true has_many :listings, dependent: :destroy has_many :sales, class_name: "Order", foreign_key: "seller_id" end Here is my order.rb file: class Order < ActiveRecord::Base validates :name, :email, :phone, presence: true belongs_to :listing belongs_to :buyer, class_name: "User" belongs_to :seller, class_name: "Host" end And Here is my orders_controller.rb file: class OrdersController < ApplicationController before_action :set_order, only: [:show, :edit, :update, :destroy] before_action :authenticate_host! def sales @orders = Order.all.where(seller: current_user).order("created_at DESC") end def purchases @orders = Order.all.where(buyer: current_host).order("created_at DESC") end # GET /orders # GET /orders.json def index @orders = Order.all end # GET /orders/1 # GET /orders/1.json def show end # GET /orders/new def new @order = Order.new @listing = Listing.find(params[:listing_id]) end # GET /orders/1/edit def edit end # POST /orders # POST /orders.json def create @order = Order.new(order_params) @listing = Listing.find(params[:listing_id]) @seller = @listing.host @order.listing_id = @listing.id @order.buyer_id = current_user.id @order.seller_id = @seller.id respond_to do |format| if @order.save format.html { redirect_to @order, notice: 'Order was successfully created.' } format.json { render :show, status: :created, location: @order } else format.html { render :new } format.json { render json: @order.errors, status: :unprocessable_entity } end end end # PATCH/PUT /orders/1 # PATCH/PUT /orders/1.json def update respond_to do |format| if @order.update(order_params) format.html { redirect_to @order, notice: 'Order was successfully updated.' } format.json { render :show, status: :ok, location: @order } else format.html { render :edit } format.json { render json: @order.errors, status: :unprocessable_entity } end end end # DELETE /orders/1 # DELETE /orders/1.json def destroy @order.destroy respond_to do |format| format.html { redirect_to orders_url, notice: 'Order was successfully destroyed.' } format.json { head :no_content } end end private # Use callbacks to share common setup or constraints between actions. def set_order @order = Order.find(params[:id]) end # Never trust parameters from the scary internet, only allow the white list through. def order_params params.require(:order).permit(:name, :email, :phone) end end I appreciate your help. Couldn't have gotten this far without your help and great class!

Posted over 3 years ago by Javier
Posted over 3 years ago by Javier

I just realized pasting in the code looks awful, Is there a better way to send over my code?

1
Posted over 3 years ago by Alex Yang

Why don't you send an up-to-date link to your GitHub repository? Also, can you be more specific about the exact problem? For example, is the issue that sales are not recorded in your database or that sales don't show up on some kind of Host page?

I can only offer limited troubleshooting help for custom projects with customized code, but will be happy to take a quick look for you.

1