I’m trying to achieve a simple 1 to 1 relation in Rails 3 where a user can connect a bank account.
class User < ActiveRecord::Base
has_one :bank
accepts_nested_attributes_for :bank
attr_accessible :bank_attributes
end
class Bank < ActiveRecord::Base
belongs_to :user
end
Route
resources :users do
resources :bank
Now when i build a new bank object for a user in users/1/bank/new like this:
def new
@user = User.find(current_user.id)
@bank = @user.build_bank
end
I get an error on my for which looks like this:
<%= simple_form_for(@bank) do |f| %>
The error is:
undefined method `banks_path' for #<#<Class:0x007fa7bd090f08>:0x007fa7c0545b40>
My goal is to have a separate form for a user to add there bank account information.. Hope someone can help me in the right direction to do this. I also use ActiveAdmin and the relation with forms etc works fine there.
Any help is appreciated!
You need to declare resource in plural form regardless of the association type.
So, your resource declaration