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 6010665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:08:57+00:00 2026-05-23T02:08:57+00:00

I have 3 objects: users, travels, points. A user has many travels, a travel

  • 0

I have 3 objects: users, travels, points.

A user has many travels, a travel has many points, a point belongs to one travel e one user.

A travel has also a boolean attribute (:open) which tells if is it in curse or not.

The problem is that I can’t save “travel_id” of the current travel in my points table.

Here is the code:

class Point < ActiveRecord::Base
    belongs_to :travel, :foreign_key=> "travel_id"
    belongs_to :user, :foreign_key=> "user_id"
end


class Travel < ActiveRecord::Base
    has_one :user, :foreign_key => "user_id"
    has_many :ways
    has_many :points
    attr_accessible :description, :start_date, :last_date
    validates_date :last_date, :on_or_after => :start_date
end

Points controller:

...
 def create
   @point = Point.new(params[:point])
   @point.user_id = current_user.id
   @travel = current_user.travels.find(:all, :conditions => {:open => true})
   @point.travel_id = @travel.id
   respond_to do |format|
     if @point.save
       format.html { redirect_to(@point, :notice => 'Point was successfully created.') }
       format.xml  { render :xml => @point, :status => :created, :location => @point }
     else
       format.html { render :action => "new" }
       format.xml  { render :xml => @point.errors, :status => :unprocessable_entity }
     end
   end
 end
...

Every time I try to save a new point, @point.travel_id = -614747648

  • 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-05-23T02:08:58+00:00Added an answer on May 23, 2026 at 2:08 am

    A few things could do with being fixed up here.

    Firstly, you don’t need to specify :foreign_key when the key is just the same as the relation name + _id.

    Second, you don’t need to (and generally shouldn’t) set the foo_id fields directly; it’s more usual to do @point.user = current_user.

    Thirdly, and the direct cause of your problem, is that @travel has been set to the result of a find(:all, ...) call – so it’s an Array of Travel objects. What you’re saving into @point.travel_id will be Ruby’s internal id for the @travel Array, rather than a database ID for a single row.

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

Sidebar

Related Questions

I have many User objects with created_at attribute e.g. I get objects with @users
I have an array of objects (Users) each user has an nsset named devices
I have an object called users that I use to store user objects that
I have async methods that returns an objects public static IEnumerable<Users.User> GetUsers(IEnumerable<string> uids, Field
I have a class that contains multiple user objects and as such has an
I have a collection of objects @users , each having its id attribute. @users
I have 2 arrays of objects : users and channels. Each user can be
Background I have an array of objects (Users) defined and set as follows: //
I have users that have several objects and can upload images for those objects.
I have a form where users can modify a collection of objects using 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.