I have a simple self-contained model for an account. In an account, a single parent and / or multiple children Accounts.
Here's the square:
class account
and migration:
Class CreateAccounts & lt; ActiveRecord :: Migration deff changes make_table: accounts do | T | T.references: Parent, Index: True t.string: Name t.string: Category t.timestamps Faucet: False End End End
When the build method is applied to the controller, I Receive the following error:
account (# 70188397277860) Expected, string (# 70188381177720) found
and reference the first line to create this method Controller:
def create account @ account.new (account_params) response_to do | Format | If @ account.save format.html {redirect_to @account, notice: 'The account was created successfully.' } Format.json {Render: Show, Status :: created, Location: @account} and Format Html {render: new} format.json {render json: @account. Errors, Status :: unprocessable_entity} End And End
Since the account model is self-referencing, it seems that the Railways expects an account as an argument for the creation of an account is.
Rail activation is a limited example of record. I believe that I have followed closely, but I do not know where I am wrong.
I have tried many types of foreign key types and not with any luck. Any signal is appreciated.
Edit:
Here is a form that is generated by Scaffold Commands, which collects information about creating a new account. As suggested by @SteveTourskin in the comments, collecting a string for the original field rather than the form ID.
& lt;% = form_for (@account) do | F | & Gt%; & Lt;% if @ account.errors.any? & Gt%; & Lt; Div id = "error_explanation" & gt; & Lt; H2 & gt; & Lt;% = plural (@account.arrose quote, "error")%> Forgotten this account from being saved: \ & lt; / H2 & gt; & Lt; Ul & gt; & Lt;% @ account.errors.full_messages.each do | Message | & Gt%; & Lt; Li & gt; & Lt;% = Message% & gt; & Lt; / Li & gt; & Lt;% end% & gt; & Lt; / Ul & gt; & Lt; / Div & gt; & Lt;% end% & gt; & Lt; Div class = "field" & gt; & Lt;% = f.label: Parent% & gt; & Lt; Br> & Lt;% = f.text_field: Parent% & gt; & Lt; / Div & gt; & Lt; Div class = "field" & gt; & Lt;% = f.label: name% & gt; & Lt; Br> & Lt;% = f.text_field: name% & gt; & Lt; / Div & gt; & Lt; Div class = "field" & gt; & Lt;% = f.label: Category% & gt; & Lt; Br> & Lt;% = f.text_field: Category% & gt; & Lt; / Div & gt; & Lt; Div class = "verb" & gt; & Lt;% = f.submit% & gt; & Lt; / Div & gt; & Lt;% end% & gt; EDIT2:
Change the parent
field from text_field
to number_field
There is no effect on the result.
The parameters passed in the method of creating are the same:
{"utf8" => "✓", "Authenticity_token" = & gt; "Pq0sp162cA7Bmn7uw67F7gOvUVLj / S + xcasVibqysiF68vheVkATsf4pwKgPqH5nawjc0BnIj3qoot8JyIeVmg ==", "account" = & gt; {"Parent" = & gt; "0", "name" = & gt; "Foo", "category" = & gt; "Bar"}, " " post-text "itemprop =" text " > You are submitting the ID of the form guardian
, but your association should actually be compared to guardian
No comments:
Post a Comment