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

  • Home
  • SEARCH
  • 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 9246161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:25:50+00:00 2026-06-18T09:25:50+00:00

So I’ve been holding off putting a question on here because I don’t want

  • 0

So I’ve been holding off putting a question on here because I don’t want to bother the community with stupid questions, but I’m going to ask for help now anyway.

I’m quite new to Ruby on Rails, and as you’ve probably read from the title, I’m having trouble with my subform. More specifically, with assigning the parent object to a client object. I’m building a system for my work in where employees can register repairs (mobile phones) and keep track of them. I’m building the client object with @repair = Repair.new, which works fine, but when I try to set the Client with @repair = Client.new, the :client_id on the repair stays null.

Here’s my repair.rb: (some fields are in Dutch, please ignore that)

class Repair < ActiveRecord::Base
  attr_accessible :imei, :klantnaam, :telefoon, :intake, :branch_id, :id, :client_id
  attr_accessible :merk, :type, :batterij, :lader, :headset, :batterijklep, :carkit, :schade_toestel, :schade_scherm, :bon, :datum_bon, :klacht, :prijsindicatie

  belongs_to :branch
  belongs_to :client

  accepts_nested_attributes_for :client
end

client.rb:

class Client < ActiveRecord::Base
  attr_accessible :email, :firstname, :lastname, :number, :phone, :postalcode
  has_many :repairs
end

repairs_controller.rb: (I’ve left the irrelevant methods out, I was getting tired of the 4 spaces :P)

class RepairsController < ApplicationController
  # GET /repairs/new
  # GET /repairs/new.json
  def new
    @repair = Repair.new
    @repair.client = Client.new

    if request.remote_ip == "xx.xx.xx.xx"
      @repair.branch = Branch.where(:name => "Xxxxxxx").first
    end

    @repair.intake = Time.now

    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @repair }
    end
  end

  # POST /repairs
  # POST /repairs.json
  def create
    @repair = Repair.new(params[:repair])

    respond_to do |format|
      if @repair.save
        format.html { redirect_to @repair, notice: 'Repair was successfully created.' }
        format.json { render json: @repair, status: :created, location: @repair }
      else
        format.html { render action: "new" }
        format.json { render json: @repair.errors, status: :unprocessable_entity }
      end
    end
  end
end

And this is the JSON I get from /repair/new.json:

{"batterij":null,"batterijklep":null,"bon":null,"branch_id":null,"carkit":null,"client_id":null,"created_at":null,"datum_bon":null,"headset":null,"id":null,"imei":null,"intake":"2013-02-01T23:29:10Z","klacht":null,"klantnaam":null,"lader":null,"merk":null,"pickup":null,"prijsindicatie":null,"schade_scherm":null,"schade_toestel":null,"telefoon":null,"updated_at":null}

By the way, the branch assignment works flawlessly… (It’s null now because I’m not on the IP I specified in the new method)

Please help me out… 🙁

Robin

  • 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-18T09:25:51+00:00Added an answer on June 18, 2026 at 9:25 am

    Solved it!!

    The code above all works flawlessly, the problem was a <% instead of <%= in my view, which made my subform not show up. Duhh.

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

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I want to construct a data frame in an Rcpp function, but when I
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want use html5's new tag to play a wav file (currently only supported
I'm interested in microtypography issues on the web. I want a tool to fix:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.