Hi YogiZoli,
Thanks for your post.
I think you meant has_one instead of 'has_many' (in your first bullet
point for student.rb).
I tried what you suggested, and my routes.rb file has
resource :accounts
I also went back to my original "form_for" text as per my attachment and
I no longer see that NoMethodError (YAY!) that I first posted up.
I figured out why (at least i think i did) my 'insert into accounts'
would delete when I rendered the show.html.erb file after creating an
account.... I had the text ":dependent => :destroy" in the model.rb file
I've updated my models to have that 1-1 relationship.
While I was testing it out, I noticed the following in my server logs...
*****************************
Started POST "/students/4/accounts" for 127.0.0.1 at 2012-04-01 21:16:19
+1000
Processing by AccountsController#create as HTML
Parameters: {"utf8"=>"✓",
"authenticity_token"=>"FEdjo1+qRJ1cIQpwIbpRnvJ51esPgd/K8s9Hb4MOylQ=",
"account"=>{"name"=>"acname1", "number"=>"1111"}, "commit"=>"Create
Account", "student_id"=>"4"}
Student Load (0.4ms) SELECT `students`.* FROM `students` WHERE
`students`.`id` = 4 LIMIT 1
(0.4ms) BEGIN
SQL (0.5ms) INSERT INTO `accounts` (`created_at`, `name`, `number`,
`student_id`, `updated_at`) VALUES ('2012-04-01 11:16:20', 'acname1',
'1111', 4, '2012-04-01 11:16:20')
(0.7ms) COMMIT
Account Load (0.3ms) SELECT `accounts`.* FROM `accounts` WHERE
`accounts`.`student_id` = 4 LIMIT 1
(0.1ms) BEGIN
(0.1ms) COMMIT
Redirected to http://localhost:3000/students/4
Completed 302 Found in 11ms (ActiveRecord: 2.4ms)
Started GET "/students/4" for 127.0.0.1 at 2012-04-01 21:16:20 +1000
Processing by StudentsController#show as HTML
Parameters: {"id"=>"4"}
Student Load (0.3ms) SELECT `students`.* FROM `students` WHERE
`students`.`id` = 4 LIMIT 1
Account Load (0.4ms) SELECT `accounts`.* FROM `accounts` WHERE
`accounts`.`student_id` = 4 LIMIT 1
(0.1ms) BEGIN
(0.3ms) UPDATE `accounts` SET `student_id` = NULL, `updated_at` =
'2012-04-01 11:16:20' WHERE `accounts`.`id` = 4
(28.6ms) COMMIT
Rendered students/show.html.erb within layouts/application (36.4ms)
Completed 200 OK in 46ms (Views: 14.5ms | ActiveRecord: 29.8ms)
*****************
After entering the account details I make it redirect to the
app/views/student/show.html.erb view because I basically want to just
update the "show" page. BUT I can see that the student_id is being
updated to NULL - why is that?
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
No comments:
Post a Comment