Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7951711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:38:37+00:00 2026-06-04T02:38:37+00:00

I have an application that allows users to create loads and bid on them.

  • 0

I have an application that allows users to create loads and bid on them.

I want a way to go through the application and reserve a bid which will then process a credit card, but I am having issues setting up the reservation model. Here is the setup:

Models with their associations:

class Reservation < ActiveRecord::Base
  belongs_to :load
  belongs_to :bid

  validates :load_id, presence: true
  validates :bid_id, presence: true
end

class Load < ActiveRecord::Base
  has_many :bids, :dependent => :delete_all
  has_one :reservation
end

class Bid < ActiveRecord::Base
  belongs_to :load
  has_one :reservation
end

The reservation migration only includes the references to the two tables.
In my reservations controller I have the following code:

class ReservationsController < ApplicationController

  before_filter :find_load
  before_filter :find_bid 

  def new
    @reservation = @load.build_reservation(params[:reservation])
  end

  def create
    @reservation = @load.build_reservation(params[:reservation].merge!(:bid_id => params[:bid_id])) 
    if @reservation.save
      flash[:notice] = "Reservation has been created successfully"
      redirect_to [@load, @bid]
    else
      render :new
    end
  end

  def find_load
    @load = Load.find(params[:load_id])
  end

  def find_bid
    @bid = Bid.find(params[:bid_id])
  end
end

In my config routes file I have the following:

resources :loads do 
  resources :bids do 
    resources :reservations
  end
end

The migration for the reservations model looks like this:

def change
  create_table :reservations do |t|
    t.references :load
    t.references :bid
    t.timestamps
  end
end

The View Code:

<h4>Reserve this bid: </h4>
  <dl>
    <dt>Carrier</dt>
    <dd><%= @bid.user.email %></dd>
    <dt>Bid Amount:</dt>
    <dd><%= @bid.bid_price %></dd>
 </dl>

<%= form_for [@load, @bid, @reservation], :html => {:class => 'payment_form'} do |f| %>
  <%= f.error_messages %>
<fieldset>
  <div class="field">
    <%= label_tag :card_number, "Credit Card Number" %>
    <%= text_field_tag :card_number, nil, name: nil %>
  </div>
  <div class="field">
    <%= label_tag :card_code, "Security Code on Back of Card (CVV)" %>
    <%= text_field_tag :card_code, nil, name: nil %>
  </div>
  <div class="field">
    <%= label_tag :card_month, "Card Expiration" %>
    <%= select_month nil, { add_month_numbers: true }, { name: nil, id: "card_month" } %>
    <%= select_year nil, { start_year: Date.today.year, end_year: Date.today.year+15 },
  { name: nil, id: "card_year" } %>
 </div>
</fieldset>

When I go to submit the form, I get the following validation error: “Bid can’t be blank”. It looks like the form is submitting the bid as nil, and I am unsure of why it is doing this. I don’t believe the first line of code is correct in my create action of the controller, and I have tried all of the permutations that I could think of and I can’t get it to work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T02:38:39+00:00Added an answer on June 4, 2026 at 2:38 am

    Since your form doesn’t contain any data you’ll be saving you can simply do this:

    @reservation = @load.build_reservation(:bid_id => @bid.id)
    

    If you add reservation fields that you want to save in the future, params[:reservation] will not be nil and you will be able to do:

    @reservation = @load.build_reservation(params[:reservation].merge(:bid_id => @bid.id))
    

    Another way would be to add a hidden field to your form that contains the bid_id, but since you already have it in the URL, this may not be the best approach.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web application that allows users to create an account, and in
I want to create a java application that allows users to import a web
I have an application that allows users to create forms and assign validation to
I'm using: Hibernate MySQL jBoss I have to create an application that allows user
We have created a web application, using ASP.NET, that allows users to upload documents
We have an application that allows users to add/edit/replace/delete content (text, images, swfs, mp3s,
I have a web application that allows users to build a 'client list.' We
Let say, I have a web application that allows users to upload images and
I have a really simple Rails application that allows users to register their attendance
I have written an application that allows a user to create and run a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.