I got this problem of ActiveAdmin not updating my record and i noticed on log that the update statement is passing a PK key of "0" instead of the params[:id] of "5"... Any idea how can i override this? or any workaround? I was thinking maybe this was due to i was not using the normal PK of "id".. any thoughts? Thanks in advance...
Started PATCH "/admin/doctors/5" for 127.0.0.1 at 2014-09-15 20:51:35 +0800
Processing by Admin::DoctorsController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"rkmUILbx/t6Rk5jtanupJkt5yZBmj6PbGQhnhxcOP0U=", "doctor"=>{ "gender"=>"0", "details"=>"asdfasdf", "active_flag"=>"Y"}, "commit"=>"Update Doctor", "id"=>"5"}
AdminUser Load (0.4ms) SELECT `admin_users`.* FROM `admin_users` WHERE `admin_users`.`id` = 2 ORDER BY `admin_users`.`id` ASC LIMIT 1
Doctor Load (0.2ms) SELECT `doctors`.* FROM `doctors` WHERE `doctors`.`doctor_id` = ? LIMIT 1 [["doctor_id", 5]]
SQL (0.7ms) BEGIN
SQL (0.3ms) UPDATE `doctors` SET `gender` = ?, `updated_at` = ? WHERE `doctors`.`doctor_id` = 0 [["gender", 0], ["updated_at", "2014-09-15 12:51:35"]]
(0.6ms) COMMIT
Redirected to http://localhost:3000/admin/doctors/5
Completed 302 Found in 40ms (ActiveRecord: 2.2ms)
Started GET "/admin/doctors/5" for 127.0.0.1 at 2014-09-15 20:51:35 +0800
Processing by Admin::DoctorsController#show as HTML
Parameters: {"id"=>"5"}
AdminUser Load (0.3ms) SELECT `admin_users`.* FROM `admin_users` WHERE `admin_users`.`id` = 2 ORDER BY `admin_users`.`id` ASC LIMIT 1
Doctor Load (0.3ms) SELECT `doctors`.* FROM `doctors` WHERE `doctors`.`doctor_id` = ? LIMIT 1 [["doctor_id", 5]]
Completed 200 OK in 25ms (Views: 20.9ms | ActiveRecord: 0.6ms)
Here the controller code..
ActiveAdmin.register Doctor do
controller do
def permitted_params
params.permit :utf8, :_method, :authenticity_token, :commit, :id, :doctor_id,
doctor: [:first_name, :middle_initial, :last_name, :name_suffix,
:title, :primary_spec_id, :dob, :gender, :email, :phone,
:details, :ratings, :active_flag ]
end
def update
params.merge!({doctor_id: params[:id]})
Rails.logger.debug params.inspect
super
end
end
menu parent: 'Maintenance Tables'
scope :is_inactive
scope :is_active
filter :first_name
filter :last_name
filter :email
filter :primary_spec_id, :label => 'Specialization' , :as => :select , :collection => Specialization.all.order(name: :asc)
filter :gender, :as => :select , :collection => { 'Male' => 1, 'Female' => 0 }
filter :active_flag, :label => 'Status' , :as => :select , :collection => ['Y','N']
index do
column :ID, :sortable => :doctor_id, :max_width => "500px" do |doctor|
link_to(doctor.doctor_id, admin_doctor_path(doctor))
end
column :first_name
column :M_I, :sortable => :middle_initial do |doctor|
doctor.middle_initial
end
column :last_name
column :suffix, :sortable => :name_suffix do |doctor|
doctor.name_suffix
end
column :title
column :specialization, :sortable => :primary_spec_id do |doctor|
specialization = Specialization.find(doctor.primary_spec_id)
link_to(specialization.name,admin_specialization_path(specialization))
end
column :dob
column :gender, :sortable => :gender do |doctor|
gender = ['F','M']
gender[doctor.gender]
end
column :email, :sortable => :email do |doctor|
mail_to(doctor.email)
end
column :phone
column :active_flag, :sortable => :active_flag do |doctor|
div :class => "doctor_status" do
status_tag(doctor.active_flag, ((doctor.active_flag == 'Y') ? :ok : :error))
end
end
end
form do |f|
f.inputs "Doctor Details" do
#f.input :doctor_id
f.input :first_name
f.input :middle_initial, :label => 'M.I.'
f.input :last_name
f.input :name_suffix, :label => 'Suffix', :as => :select, :collection => ['JR.', 'SR.', 'III', 'IV', 'V']
f.input :title, :label => 'Specialization Title Prefix', :hint => "(e.g. M.D., etc.)"
f.input :primary_spec_id, :as => :select, :collection => Specialization.all.order(name: :asc)
f.input :dob, :label => 'Birth Date', :hint => "(format: MM/DD/YYYY)"
f.input :gender, :as => :radio, :collection => { 'M' => 1, 'F' => 0 }
f.input :email, :as => :email
f.input :phone, :as => :phone
f.input :details, :label => 'Doctor\'s Brief Description', :as => :text
f.input :picture, :label => 'Upload Picture', :as => :file
f.input :active_flag, :as => :select, :collection => ['Y','N'], :hint => "(Default: Y)"
end
f.actions
end
end
Do you get the same error, if you permit the id of the doctor like this?
doctor: [:id, :first_name, :middle_initial, :last_name, :name_suffix,
:title, :primary_spec_id, :dob, :gender, :email, :phone,
:details, :ratings, :active_flag ]
Finally figured it out. Maybe it was something to do with the ActiveRecord the Rails version 4.1.6..
So I tried reverting my gem to 4.0.4
gem 'rails', '4.0.4'
Then it finally working as it should be.. Thanks anyway..
Started PATCH "/admin/doctors/5" for 127.0.0.1 at 2014-09-16 17:24:19 +0800
Processing by Admin::DoctorsController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"I9K+GM6iB1a9OvKvmFrqz3qsf4XwedImLHYihtxYBKY=", "doctor"=>{ "gender"=>"0", "details"=>"asdfasdf", "active_flag"=>"Y"}, "commit"=>"Update Doctor", "id"=>"5"}
AdminUser Load (3.9ms) SELECT `admin_users`.* FROM `admin_users` WHERE `admin_users`.`id` = 2 ORDER BY `admin_users`.`id` ASC LIMIT 1
Doctor Load (1.2ms) SELECT `doctors`.* FROM `doctors` WHERE `doctors`.`doctor_id` = ? LIMIT 1 [["doctor_id", "5"]]
SQL (0.1ms) BEGIN
SQL (0.4ms) UPDATE `doctors` SET `gender` = ?, `updated_at` = ? WHERE `doctors`.`doctor_id` = 5 [["gender", 0], ["updated_at", Tue, 16 Sep 2014 09:24:19 UTC +00:00]]
(0.6ms) COMMIT
Redirected to http://localhost:3000/admin/doctors/5
Completed 302 Found in 33ms (ActiveRecord: 6.3ms)
Related
I am working on my first Rails project and have installed the Paperclip Gem to handle image uploads. As is, it works fine, but all the upload fields are displayed to be fill out separately as seen in the screen shot below.
Below is my code as is with all the image input fields broken out individually.
models/project.rb
class Project < ApplicationRecord
has_many :tasks
validates :name, presence: true, length: { maximum: 50 }
validates :content, presence: true, length: { maximum: 500 }
validates :price, presence: true, numericality: { only_integer: true }
has_attached_file :avatar, styles: { medium: '680x300>', thumb: '170x75>' }, default_url: '/images/:style/missing.png"'
validates_attachment_content_type :avatar, content_type: '/\Aimage\/.*\z/'
end
admin/project.rb
ActiveAdmin.register Project do
permit_params :name, :content, :price, :image
show do |t|
attributes_table do
row :name
row :content
row :price
row :image do
project.image? ? image_tag(project.image.url, height: '100') : content_tag(:span, 'No Photo Yet')
end
end
end
# form html: { enctype: 'multipart/form-data' } do |f|
# f.input do
# f.input :name
# f.input :content
# f.input :price
# f.input :image, hint: f.project.image? ? image_tag(project.image.url, height: '100') : content_tag(:span, 'Upload JPG/PNG/GIF Image')
# end
# f.actions
# end
end
I know that there is a way to take all these inputs and have them automatic as part of an upload button, but am having a hard time with the code; I keep getting the error below when I uncomment the other part of my admin/project.rb code.
I am using ActiveAdmin, Paperclip 5.1 and Rails 5.1.1
Started GET "/admin/projects/2/edit" for 127.0.0.1 at 2017-06-26 13:14:33 -0700
Processing by Admin::ProjectsController#edit as HTML
Parameters: {"id"=>"2"}
AdminUser Load (0.1ms) SELECT "admin_users".* FROM "admin_users" WHERE "admin_users"."id" = ? ORDER BY "admin_users"."id" ASC LIMIT ? [["id", 2], ["LIMIT", 1]]
Project Load (0.1ms) SELECT "projects".* FROM "projects" WHERE "projects"."id" = ? LIMIT ? [["id", 2], ["LIMIT", 1]]
Rendering /Users/rooster/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activeadmin-1.0.0/app/views/active_admin/resource/edit.html.arb
CACHE Project Load (0.0ms) SELECT "projects".* FROM "projects" WHERE "projects"."id" = ? LIMIT ? [["id", 2], ["LIMIT", 1]]
Rendered /Users/rooster/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activeadmin-1.0.0/app/views/active_admin/resource/edit.html.arb (129.0ms)
Completed 500 Internal Server Error in 163ms (ActiveRecord: 1.4ms)
ActionView::Template::Error (wrong number of arguments (given 0, expected 1..2)):
1: insert_tag renderer_for(:edit)
I see a couple changes that would have to be made with your form.
It currently looks like:
form html: { enctype: 'multipart/form-data' } do |f|
f.input do
f.input :name
f.input :content
f.input :price
f.input :image, hint: f.project.image? ? image_tag(project.image.url, height: '100') : content_tag(:span, 'Upload JPG/PNG/GIF Image')
end
f.actions
end
And it should look something like:
form html: { enctype: 'multipart/form-data' } do |f|
f.inputs do
f.input :name
f.input :content
f.input :price
f.input :image, hint: resource.project.image? ? image_tag(project.image.url, height: '100') : content_tag(:span, 'Upload JPG/PNG/GIF Image')
end
f.actions
end
Two minor changes that were made. Changed input to inputs, got this from after looking at ActiveAdmin's documentation about forms. Next I changed f.project.image? to resource.project.image?. resource corresponds with your Project object.
My form is updating the tester record (which is an end user). I am also trying to update many applied_program records which belong to the tester.
I am sending the parameters to the controller but cannot get it to update the the applied_program records. It is trying to use all the parameters instead of just the applied program params to update it.
Form:
<%= form_for #tester, url: { controller: :admins, action: :update_tester } do |f| %>
<%= render 'shared/error_messages' %>
<%= f.label :name %>
<%= f.text_field :name, class: "input-lg" %>
...
<%= f.fields_for :applied_programs do |fml| %>
<%= fml.label :approved, "Approved: " %><%= fml.check_box :approved %>
<%= fml.hidden_field :id %>
<% end %>
<%= f.submit "Save Changes", class: "btn btn-lg btn-primary" %>
<% end %>
Tester Model:
has_many :applied_programs, :dependent => :destroy
accepts_nested_attributes_for :applied_programs
AppliedProgram Model:
belongs_to :tester
Controller:
def update_tester
#applied_programs = AppliedProgram.where(tester_id: #tester.id)
#tester.update_attributes(tester_params)
#applied_programs.each do |p|
p.update_attributes(tester_params)
end
end
def tester_params
params.require(:tester).permit(:name, :email, :phone_number, :address1,
:city, :zip_code, :country, :password, :password_confirmation,
:active, :approved, applied_programs_attributes: [ :approved, :id ])
end
The log:
Processing by AdminsController#update_tester as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"x", "tester"=>{"name"=>"Dave", "email"=>"nope#gmail.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "applied_programs_attributes"=>{"0"=>{"approved"=>"0", "id"=>"9"}, "1"=>{"approved"=>"1", "id"=>"745"}}}, "commit"=>"Save Changes", "id"=>"16"}
Tester Load (0.1ms) SELECT `testers`.* FROM `testers` WHERE `testers`.`id` = 16 LIMIT 1
Tester Load (1.1ms) SELECT `testers`.* FROM `testers` WHERE `testers`.`remember_token` = 'x' LIMIT 1
(6.8ms) BEGIN
AppliedProgram Load (2.6ms) SELECT `applied_programs`.* FROM `applied_programs` WHERE `applied_programs`.`tester_id` = 16 AND `applied_programs`.`id` IN (9, 745)
Tester Exists (0.8ms) SELECT 1 AS one FROM `testers` WHERE (`testers`.`email` = 'nope#gmail.com' AND `testers`.`id` != 16) LIMIT 1
(0.1ms) COMMIT
AppliedProgram Load (0.1ms) SELECT `applied_programs`.* FROM `applied_programs` WHERE `applied_programs`.`tester_id` = 16
(0.1ms) BEGIN
(12.4ms) ROLLBACK
Completed 500 Internal Server Error in 95ms
ActiveRecord::UnknownAttributeError (unknown attribute: name)
You problem is the loop over the applied_programs you need to do something like:
def update_tester
#applied_programs = AppliedProgram.where(tester_id: #tester.id)
#tester.update_attributes(tester_params)
end
def tester_params
params.require(:tester).permit(:name, :email, :phone_number, :address1,
:city, :zip_code, :country, :password, :password_confirmation,
:active, :approved, applied_programs_attributes: [ :approved, :id ])
end
So I have a deeply nested association among Polls, Questions, and Answers:
class Poll < ActiveRecord::Base
attr_accessible :description, :end_time, :start_time, :title, :user_id, :questions_attributes, :is_live
belongs_to :user
has_many :questions, :dependent => :destroy
# This is the plularized form of sms, it's not smss
has_many :sms, :through => :questions
has_many :feedbacks
accepts_nested_attributes_for :questions, :reject_if => lambda { |a| a[:content].blank?}, :allow_destroy => true
end
class Question < ActiveRecord::Base
attr_accessible :poll_id, :title, :answer_attributes
belongs_to :poll
has_many :answers, :dependent => :destroy
# THis is the plularized form of sms, it's not smss
has_many :sms
#If someone creates a form with a blank question field at the end, this will prevent it from being rendered on teh show page
accepts_nested_attributes_for :answers, :reject_if => lambda { |a| a[:content].blank?}, :allow_destroy => true
end
class Answer < ActiveRecord::Base
attr_accessible :is_correct, :question_id, :title
belongs_to :question
end
And am trying to save all objects in a single fields_for form like so.
= form_for #poll, :class=>'create-poll-form' do |f|
= f.text_field :title, :autofocus => true, :placeholder => "Poll Title"
= f.text_field :description, :placeholder => 'Description'
= f.fields_for :questions do |builder|
= render "questions/question_fields", :f => builder
= f.submit "Create Poll", :class => 'btn btn-danger'
Questions Partials
%p
= f.label :title, "Question"
= f.text_field :title
= f.check_box :_destroy
= f.label :_destroy, "Remove Question"
%p
= f.fields_for :answers do |builder|
= render "answers/answer_fields", :f => builder
Answers Partial
%p
= f.label :title, "Answer"
= f.text_field :title
= f.check_box :_destroy
= f.label :_destroy, "Remove Answer"
Yet the PollsController isn't persisting the data:
def create
binding.pry
#poll = current_user.polls.new(params[:poll])
# #poll = Poll.create(params[:poll])
binding.pry
#poll.save!
redirect_to root_path
end
def new
#poll = Poll.new
1.times do
question = #poll.questions.build
2.times {question.answers.build}
end
end
Any tips here would be amazing, I've been working on this for a bit and it's stumping me! Thanks in advance!
Also here's the server log:
Started POST "/polls" for 127.0.0.1 at 2013-06-06 20:14:47 -0400
Processing by PollsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"hk+KuNsTLx3sH9pE7Mf8XETGsmxTsRN4/tWUBn3CIVE=", "poll"=>{"title"=>"Testing 1-2-1-2", "description"=>"Up on the mic", "questions_attributes"=>{"0"=>{"title"=>"Cake or Death?", "_destroy"=>"0", "answers_attributes"=>{"0"=>{"title"=>"Cake", "_destroy"=>"0"}, "1"=>{"title"=>"Death", "_destroy"=>"0"}}}}}, "commit"=>"Create Poll"}
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
Question Load (0.5ms) SELECT "questions".* FROM "questions" WHERE "questions"."poll_id" IS NULL
(0.3ms) BEGIN
SQL (47.6ms) INSERT INTO "polls" ("created_at", "description", "end_time", "is_live", "start_time", "title", "updated_at", "user_id") VALUES ($1, $2, $3, $4, $5, $6, $7, $8) RETURNING "id" [["created_at", Fri, 07 Jun 2013 00:16:46 UTC +00:00], ["description", "Up on the mic"], ["end_time", nil], ["is_live", nil], ["start_time", nil], ["title", "Testing 1-2-1-2"], ["updated_at", Fri, 07 Jun 2013 00:16:46 UTC +00:00], ["user_id", 1]]
(0.8ms) COMMIT
Redirected to http://localhost:3000/
Completed 302 Found in 170668ms (ActiveRecord: 54.9ms)
I'm not sure if this is the problem but in your
class Question < ActiveRecord::Base
attr_accessible :poll_id, :title, :answer_attributes
but in your log file it has
Parameters: {"utf8"=>"✓", "authenticity_token"=>"hk+KuNsTLx3sH9pE7Mf8XETGsmxTsRN4/tWUBn3CIVE=", "poll"=>{"title"=>"Testing 1-2-1-2", "description"=>"Up on the mic", "questions_attributes"=>{"0"=>{"title"=>"Cake or Death?", "_destroy"=>"0", "answers_attributes"=>{"0"=>{"title"=>"Cake", "_destroy"=>"0"}, "1"=>{"title"=>"Death", "_destroy"=>"0"}}}}}, "commit"=>"Create Poll"}
The difference being :answers_attributes, rather than :answer_attributes i.e. answer vs answer*s
This may be causing the data to be thrown away.
Using Ryan Bate's RailsCasts #124 Beta Invites (as well as the updated rails 3.1 api) as a crutch, I'm trying to put together my first piece of Action Mailer functionality: inviting someone to collaborate with you on a project.
My issue is that the :recipient_email isn't getting saved in the DB and I can't see what I'm missing.
config/initializers/setup_mail.rb
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => 'blah.com',
:user_name => 'gmail username',
:password => 'gmail password',
:authentication => 'plain',
:enable_starttls_auto => true
}
ActionMailer::Base.register_interceptor(DevelopmentMailInterceptor) if Rails.env.development?
app/models/invitation.rb
class Invitation < ActiveRecord::Base
email_regex = /\A[\w+\-.]+#[a-z\d\-.]+\.[a-z]+\z/i
attr_accessor :recipient_email
belongs_to :sender, :class_name => "User", :foreign_key => "sender_id"
has_one :recipient, :class_name => "User", :foreign_key => "recipient_id"
validates_presence_of :recipient_email, :on => :create, :message => "can't be blank"
validates :recipient_email, :format => email_regex
validate :recipient_is_not_registered
before_create :generate_token
def sender_name
sender.user_name
end
def sender_email
sender.email
end
private
def recipient_is_not_registered
exsisting_user = User.find_by_email(recipient_email)
if exsisting_user
errors.add :recipient_email, 'is already a member.'
else
recipient_email
end
end
def generate_token
self.token = Digest::SHA1::hexdigest([Time.now, rand].join)
end
end
app/models/user.rb (minus all the auth stuff)
class User < ActiveRecord::Base
attr_accessible :invitation_token
has_many :sent_invitations, :class_name => "Invitation", :foreign_key => "sender_id"
belongs_to :invitation
end
app/controller/invitations_controller.rb
class InvitationsController < ApplicationController
before_filter :authenticate
def new
#title = "Invite client"
#invitation = current_user.sent_invitations.new
end
def create
#invitation = current_user.sent_invitations.create!(params[:invitation])
sender_name = #invitation.sender_name
sender_email = #invitation.sender_email
if #invitation.save
Mailer.invitation(#invitation, signup_url(#invitation.token), sender_name, sender_email).deliver
flash[:success] = "Your client has been sent the email. Why not create a booking for them?"
redirect_to bookings_path
else
#title = "Invite client"
render :new
end
end
end
app/mailers/mailer.rb
def invitation(invitation, signup_url, sender_name, sender_email)
#signup_url = signup_url
#sender_name = sender_name
#sender_email = sender_email
mail(:to => invitation.recipient_email,
:subject => "Invitation to Join",
:from => #sender_email)
end
app/views/invitations/_invitation_form.html.erb
<%= form_for #invitation do |f| %>
<%= render 'shared/error_messages', :object => f.object %>
<%= f.hidden_field :email_token %>
<br />
<div class="field">
<%= f.label :recipient_email, "Client's email address" %>
<%= f.email_field :recipient_email %>
</div>
<br />
<div class="action">
<%= f.submit "Send invitation", :class => "a small white button radius" %>
</div>
<% end %>
The SQL log showing that the :recipient_email isn't getting saved
Started POST "/invitations" for 127.0.0.1 at 2011-12-14 21:27:11 +1100
Processing by InvitationsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"7/SGZypGXtf9ShlcjC6o8ZRj2Qe4OJTHdjis2/m3ulc=", "invitation"=>{"recipient_email"=>"users#email.com"}, "commit"=>"Send invitation"}
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
(0.1ms) BEGIN
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."email" = 'users#email.com' LIMIT 1
SQL (0.4ms) INSERT INTO "invitations" ("created_at", "recipient_email", "sender_id", "sent_at", "token", "updated_at") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id" [["created_at", Wed, 14 Dec 2011 10:27:11 UTC +00:00], ["recipient_email", nil], ["sender_id", 1], ["sent_at", nil], ["token", "56fba1647d40b53090dd49964bfdf060228ecb2d"], ["updated_at", Wed, 14 Dec 2011 10:27:11 UTC +00:00]]
(10.2ms) COMMIT
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
(0.1ms) BEGIN
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."email" = 'users#email.com' LIMIT 1
(0.1ms) COMMIT
Rendered mailer/invitation.text.erb (0.4ms)
Sent mail to users#email.com (7ms)
Date: Wed, 14 Dec 2011 21:27:11 +1100
From: admin#email.com
It's probably the attr_accessor :recipient_email line in your Invitation model. Take that line out as recipient_email is a database field, ain't it?
I've following models:
class CapstoneMilestone < ActiveRecord::Base
attr_accessible :capstone_id, :milestone_id, :rank, :id, :status, :statusweight, :rating, :ratingweight
belongs_to :milestone
belongs_to :capstone
accepts_nested_attributes_for :capstone, :allow_destroy => false
accepts_nested_attributes_for :milestone, :allow_destroy => false
end
class Milestone < ActiveRecord::Base
has_many :capstone_milestones
has_many :capstones, :through => :capstone_milestones
attr_accessible :id, :name, :description, :department_id, :project
accepts_nested_attributes_for :capstone_milestones, :allow_destroy => true
end
I also have a formtastic form:
<% semantic_form_for(#capstone_milestone) do |form| %>
<%= form.semantic_errors :state %>
<% form.inputs do %>
<%= form.input :capstone_id , :as => :select, :collection => Capstone.all %>
<%= form.input :milestone_id, :as => :select, :collection => Milestone.all %>
<%= form.input :status, :as => :numeric%>
<%= form.input :statusweight, :as => :numeric%>
<%= form.input :rating, :as => :numeric%>
<%= form.input :ratingweight, :as => :numeric%>
<% end %>
<%= form.inputs :name, :for => :milestone%>
<%= form.buttons %>
<% end %>
And my capstone_milestone controller (should) take care of the update:
def update
#milestone=#capstone_milestone.milestone # I also removed these 2 lines without success
#milestone.update_attributes(params[:milestone_id])
respond_to do |format|
if #capstone_milestone.update_attributes(params[:capstone_milestone])
format.html { redirect_to(session[:return_to], :notice => 'Milestone was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => #capstone_milestone.errors, :status => :unprocessable_entity }
end
end
end
When I submit the form, the capstone_milestone is update but the linked milestone is not.
This is the server log:
Started POST "/capstone_milestones/12" for 127.0.0.1 at 2011-03-18 11:40:30 +0100
Processing by CapstoneMilestonesController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"ZkErrLTpdp56BASPdZiiT6ZcvUx5KsI+Gm3JLnzM6D0=", "capstone_milestone"=>{"capstone_id"=>"100001", "milestone_id"=>"100002", "status"=>"80.0", "statusweight"=>"1.0", "rating"=>"", "ratingweight"=>"1.0", "milestone_attributes"=>{"name"=>"Land Control Analysis 2", "id"=>"100002"}}, "commit"=>"Update Capstone milestone", "id"=>"12"}
User Load (0.4ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 3 LIMIT 1
CapstoneMilestone Load (0.4ms) SELECT `capstone_milestones`.* FROM `capstone_milestones` WHERE `capstone_milestones`.`id` = 12 ORDER BY capstone_milestones.rank LIMIT 1
Milestone Load (0.3ms) SELECT `milestones`.* FROM `milestones` WHERE `milestones`.`id` = 100002 LIMIT 1
SQL (0.1ms) BEGIN
SQL (0.1ms) COMMIT
SQL (0.1ms) BEGIN
WARNING: Can't mass-assign protected attributes: milestone_attributes
Any idea, suggestion to unblock me would be greatly appreciated!
You need to add :milestone_attributes to attr_accessible of CapstoneMilestone.
attr_accessible :capstone_id, :milestone_id, :rank, :id, :status, :statusweight,
:rating, :ratingweight, :milestone_attributes