Hi,
I am new to rails. Any support from your side would be very helpful.
I have two models one named Child.rb and the other named
Filtersetting.rb
The general idea is one user can have many children and one child can
have one Filtersetting.
Hence i have done with the User model. Now while adding child to the
user, I need to add many child at a single hit and the Filtersetting for
that child at the same time.
The controller code is as follows,
class ChildrenController < ApplicationController
layout ''standard''
def index
parent_id = session[:user].id
@children = Child.find(:all, :conditions => ["parent_id = ?",
parent_id])
if @children.empty?
flash[:notice] = "No child set"
end
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @children }
end
end
def new
@child = Child.new
@level= Level.find(:all)
@cat = Filtercategory.find(:all)
@filter = Filtersetting.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @child }
end
end
def create
@child = Child.new(params[:child])
@child.parent_id = session[:user].id
childname = @child.childname
@filter = Filtersetting.new(params[:filtersetting])
@filter.childname = childname
if @filter.levelid == 1
@filter.levelname = "Elementary School"
end
if @filter.levelid == 2
@filter.levelname = "Middle School"
else
@filter.levelname = "High School"
end
respond_to do |format|
if @child.save
@filter.childid = @child.id
@filter.save
flash[:notice] = ''Child was successfully created.''
format.html { redirect_to(@child) }
else
format.html { render :action => "new" }
format.xml { render :xml => @child.errors, :status =>
:unprocessable_entity }
end
end
end
end
end
The view code is as follows,
<%= start_form_tag :action => ''create'' %>
<% (1..3).each do |index| %>
<tr>
<% fields_for :child do |f| %>
<td><p>
Childname:
<%= f.text_field :childname, :index => index %>
</p></td>
<% end %>
<% fields_for :filtersetting do |r| %>
<td><p>
Filtering Level:
<%= r.collection_select(:levelid, Level.find(:all), :id, :levelname,
{}, :index => index) %>
</p></td>
<% end %>
<% end %>
</tr>
<tr><td> <p>
<%= submit_tag "Submit" %>
</p></td></tr>
<% end_form_tag %>
</table>
<%= link_to ''Back'', children_path %>
I get the view displayed fine as i require. But insertion is not done. I
get the error in create function.
I am unable to solve the issue.
Can anyone help me please.
Any suggestion or help from your side will be very supportive.
I have attached the screenshot of the view .
The error is unknown attribute ''1''
KIndly help me in this regard please.
Regards,
Swarna
Attachments:
http://www.ruby-forum.com/attachment/3348/Screenshot-2.png
--
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---