ruby on rails - Cannot create new record in ActiveRecord -
I'm trying to move from Rail 3 to Rail 4. I do not know why, but when I new Trying to create a record I get the error message:
2 errors are restricted from saving this group: name can not be empty The tag can not be empty Here is a controller code:
def @user = UserData.find_by_login (session [: cuser]) @group = @ u Ser.groups.new (params [: group]) "== puts =====================" P @user P parameter P parameter [: group] P @group P "========" P @user .groups response_to do | Format | If the @groups save form.html {redirect_to (@group ,: notice = & gt; 'The group was created successfully.')} Format.xml {render: xml = & gt; @ Group,: status = & gt; : Created: Location = & gt; @ Group} and format.html {Render: Action => "New"} format.xml {Render: xml = & gt; @ group. Errors,: Status = & gt; : Unprocessable_entity} End End End Here is a console log:
================= ====== As I have seen, we have a User Initialized variable:
# & lt; UserData id: 1, Login: "demas", Hashed_password: "e55105f41cd0391b440176a1cd5b14c2732410ca", salt: "xnqKXtOgwO", created_t: "2014-02-17 06:18:08", updated_t: "2014-02-17 06:18: 08 ", last_alline:" 2014-02-16 16:00:00 ", login_count: 1, administrator: 0> I have a set of standards:
{"UTF8" => "One ????" "Authenticity_token" = & gt; "2qxvqJh0nrJiZt + 7xvI0lZjA83Z + hw / GKzwrNlqEh44 =", "group" = & gt; {"Name" = & gt; "112", "tags" = & gt; "2", "stop_tags" => gt; "", "download_on_refresh" = & gt; "0", "site_id" => "1"}, "committed" => "Action" "Create Group", = & gt; "Controller" "create", = & gt; "Group"} {"name" = & gt; "112", "tags" = & gt; "2", "stop_tags" =>, "", "download_on_refresh" => "0", "site_id But when I call the user.groups.new () I get an empty group: # & LT; Group ID: Zero, Name: Zero, Tag: Zero, created_at: Zero, Updated: Zero, User_Data_ID: 1, Site_ID: Zero, Stop_ Tag: Zero, Status: Zero, Last_sync: Zero, Download_App: Approx; I have checked user.groups and as I have seen, the links work fine:
"======= = "Group Load (0.3ms) Select" Groups ". * WHERE "group" from "group" "User_data_id" =? [["User_data_id", 1]] # & lt; ActiveRecord :: Association :: Collection Proxy [# & lt; Group ID: Zero, Name: Zero, Tag: Zero, Created: Zero, Updated_at: Zero, User_Data_ID: 1, Site_ID: Zero, Stop_ Tag: Zero, Status: Zero, Last_sync: Zero, Download_onfresh: Nil>]] gt; (0.1ms) Start Transactions Why do @ user.groups.new () do not make new records?
In advance thanks
Railway has implemented 'powerful parameter' [: Group] will not work to create a model using the straight parameter. You need to allow the controller to accept these parameters to create a model.
Your code: def Possible solutions: def
Comments
Post a Comment