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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:56:01+00:00 2026-06-17T23:56:01+00:00

Ok, I’ve searched high and low, read tutorials, watched videos and I am still

  • 0

Ok, I’ve searched high and low, read tutorials, watched videos and I am still not getting any where with this. I’ve read similar questions here, but questions were more complex or lacked answers – so here goes…

I have models Account and Invoice. When showing an Account, I’d like a link to ‘Create new invoice’ which relates to that account. (Later I’d actually like a select field to choose an Account when creating an Invoice, but I’ll leave that to another excruciation).

Here are my models…
Account:

class Account < ActiveRecord::Base
  attr_accessible :name, :invoice 
  attr_accessible :name, :invoice
  has_many :invoices
end

and Invoice:

class Invoice < ActiveRecord::Base
  belongs_to :account
  attr_accessible :amount_pretax, :amount_total, :date_sent, :project, :status, :tax, :account, :account_id
end

Now, in my /views/accounts/show.html.erb

<p id="notice"><%= notice %></p>
<p>
  <b>Name:</b>
  <%= @account.name %>
</p>
<%= link_to 'New Invoice', new_invoice_path(:account_id=>@account.id) %>
<%= link_to 'Edit', edit_account_path(@account) %> |
<%= link_to 'Back', accounts_path %>

So, what’s happening is, when I click on the New Invoice link it shows the new form, with the account field populated with this weird text: #<Account:0x10fe16bc0> and then when I submit the form I get this error:
ActiveRecord::AssociationTypeMismatch in InvoicesController#create
with this statement: Account(#2281084000) expected, got String(#2267210740)
along with this:

app/controllers/invoices_controller.rb:45:in `new'
app/controllers/invoices_controller.rb:45:in `create'

This is what is in the Invoices Controller:

def new
  @invoice = Invoice.new(:account_id => params[:account_id])
  respond_to do |format|
  format.html # new.html.erb
  format.json { render :json => @invoice }
  end
end

def create
  @invoice = Invoice.new(params[:invoice])
   ....
end

The above is where I think I’m going wrong, but what to put this those lines is beyond me at the moment. I’m totally a beginner, any help to solve this functionality will surely teach me loads.

Thanks for your time.

  • 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-17T23:56:03+00:00Added an answer on June 17, 2026 at 11:56 pm

    When you click the New invoice link on the /views/accounts/show page, I suppose that you want that your new invoice belongs to this account.

    So in your form, you don’t have to let the user choose an account. You can for example replace the corresponding field by a hidden_field:

    <%= f.hidden_field :account_id, :value => params[:account_id] %>
    

    Also in the new action of your controller, replace @invoice = Invoice.new(:account_id => params[:account_id]) by @invoice = Invoice.new

    Hope this helps.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms

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.