I am stuck in weird problem. I have few recall values that are created and deleted correctly, but when i try to edit the values and save them, it created new recall.
here is my controller for Edit/update
def edit
#recall = Recall.find(params[:id])
end
def update
#recall = Recall.find(params[:id])
if #recall.update_attributes(params[:recall])
# Handle a successful update.
flash[:success] = "Recall updated"
redirect_to '/recalls'
else
render 'edit'
end
end
def show
#user = Recall.find(params[:id])
end
my edit.html.erb is as follows
<%= form_for(#recall) do |f| %>
<%= f.label :Category, "Category" %>
<div class="control-group">
<div class="controls">
<%= f.select :Category,options_for_select(["Consumer Products",
"Foods, Medicines, Cosmetics",
"Meat and Poultry Products",
"Motor Vehicles",
"Child Safety Seats",
"Tires",
"Vehicle Emissions",
"Environmental Products",
"Boats and Boating Safety"]), {:style => "height:40px"} %>
</div>
</div>
<div class="form-inline">
<%= f.label :Title, "Title" %>
</div>
<%= f.text_field :Title %>
<div class="form-inline">
<%= f.label :Summary, "Summary" %>
</div>
<%= f.text_field :Summary %>
<div class="form-inline">
<%= f.label :Details, "Details" %>
</div>
<%= f.password_field :Details %>
<%= f.submit "Save changes", class: "btn btn-large btn-primary" %>
<% end %>
please let me know where i did wrong. i tried to define :action => 'edit' but it didn't worked out.
Thanks in advance
EDIT
rake routes output is here
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
sessions POST /sessions(.:format) sessions#create
new_session GET /sessions/new(.:format) sessions#new
session DELETE /sessions/:id(.:format) sessions#destroy
root / administrator_pages#home
signup /signup(.:format) users#new
signin /signin(.:format) sessions#new
signout DELETE /signout(.:format) sessions#destroy
about /about(.:format) administrator_pages#about
recalls /recalls(.:format) administrator_pages#Recalls
recall /recall(.:format) administrator_pages#create
destroy /destroy(.:format) administrator_pages#destroy
edit /edit(.:format) administrator_pages#edit
users_new GET /users/new(.:format) users#new
paid_user_paid GET /paid_user/paid(.:format) paid_user#paid
basic_user_basic GET /basic_user/basic(.:format) basic_user#basic
search_Search GET /search/Search(.:format) search#Search
here is my routes.rb, looking at rake routes and my routes.rb i can see something wrong. but unable to firgure out the problem
resources :users
resources :sessions, only: [:new, :create, :destroy]
root to: 'administrator_pages#home'
match '/signup', to: 'users#new'
match '/signin', to: 'sessions#new'
match '/signout', to: 'sessions#destroy', via: :delete
match '/about', to: 'administrator_pages#about'
match '/recalls', to: 'administrator_pages#Recalls'
match 'recall', to:'administrator_pages#create'
match 'destroy', to: 'administrator_pages#destroy'
match 'edit', to: 'administrator_pages#edit'
# get "administrator_pages/Recalls"
get "users/new"
get "paid_user/paid"
get "basic_user/basic"
get "search/Search"
I'm not seeing an update method on your routes, just add to your routes.rb
(if an update method on administrator_pages_controller.rb)
match '/recalls', to: 'administrator_pages#recalls', :as => :recalls
match '/edit/:id', to: 'administrator_pages#edit', :as => :edit_recall
put '/update/:id', to: 'administrator_pages#update'm :as => :update_recall
And run rake routes and you will see looks like
recalls GET /recalls administrator_pages#recalls
edit_recall GET /edit/:id(.:format) administrator_pages#edit
update_recall PUT /update/:id(.:format) administrator_pages#update
http://localhost:3000/recalls recalls action
http://localhost:3000/edit/:id edit action
http://localhost:3000/update/:id update action
Your form edit looks like :
<%= form_for(#recall, :url => update_recall_path(#recall), :html => { :method => :put }) do |f| %>
:url => update_recall_path(#recall) for call update action and using :html => { :method => :put }
Your controller update method
def update
#recall = Recall.find(params[:id])
if #recall.update_attributes(params[:recall])
# Handle a successful update.
flash[:success] = "Recall updated"
redirect_to recalls_path
else
render 'edit'
end
end
recalls_path is after update will redirect into http://localhost:3000/recalls
I have try it on my localhost like your code and it's works. Hope this help.
Started PUT "/update/1" for 127.0.0.1 at 2013-07-02 20:37:14 +0700
Processing by AdministratorPagesController#update as HTML
Parameters: {"utf8"=>"V", "authenticity_token"=>"s0tVbNt0JedecA+iCVlJ9GmIhGCsf
ltTbb1ep+mZmcY=", "recall"=>{"name"=>"test"}, "commit"=>"Update Recall", "id"=>"1"
}
←[1m←[36mRecall Load (0.0ms)←[0m ←[1mSELECT "recalls".* FROM "recalls" WHERE "recalls"."id" = ? LIMIT 1←[0m [["id", "1"]]
←[1m←[35m (0.0ms)←[0m begin transaction
←[1m←[36m (1.0ms)←[0m ←[1mUPDATE "recalls" SET "name" = 'test', "updated_at" =
'2013-07-02 20:37:14.772915' WHERE "recalls"."id" = 1←[0m
←[1m←[35m (6.0ms)←[0m commit transaction
Redirected to http://localhost:3000/recalls
Completed 302 Found in 13ms (ActiveRecord: 7.0ms)
you need to send an id of a recallwithin your route, because in edit/update actions you do:
#recall = Recall.find(params[:id])
your route for edit should look like this:
match 'edit/:id', to: 'administrator_pages#edit', as: 'edit_recall'
and looks like you'll need one more for update but with method: :put
with the above route you'll have a url like this:
localhost:3000/3/edit #3 is the id of recall
but if you want administrator_pages ahead you'll have to modify your routes:
match 'administrator_pages/recall/edit/:id', to: 'administrator_pages#edit', as: 'edit_recall'
result:
localhost:3000/administrator_pages/recall/3/edit
at the request params of id will be sent and you can use that Recall.find(params[:id]) in your controller. And you'll have to draw a route for update action too with method put
A better solution, I would add resource recalls to routes:
resources :recalls
this would give me all needed routes to work with recall, edit, new, show, etc..
Try the following code
<%= form_for(#recall, :url => recall_path(#recall), :method => 'PUT') do |f| %>
Related
In my application.html.erb I have a menu, which is displayed on every page. But I can't use 'sign out' link, an error appears.
undefined local variable or method 'main_page'
I have 'main_page' in my routes and I don't understand why it's not working.
I've tried to use 'sign out' link from my show view in the User controller's action, and it worked fine.
show.html
<% content_for :user_form do %>
<p id="notice"><%= notice %></p>
<p>
<strong>Name:</strong>
<%= #user.name %>
</p>
<p>
<strong>Email:</strong>
<%= #user.email %>
</p>
<%= link_to 'Edit', edit_user_path(#user) %>
<%= link_to 'My dates', :controller => :calendar, :action => :month_for_user %>
<%= link_to 'sign out', :controller => :sessions, :action => :destroy %>
<%end%>
Why there is an error when the link is used from application.html? Although 'My dates' link works. How can I fix it?
application.html
<div id = 'user_menu' >
<p id="notice"><%= notice %></p>
<p>
<strong>Name:</strong>
<%= current_user.name %>
</p>
<p>
<strong>Email:</strong>
<%= current_user.email %>
</p>
<%= link_to 'Edit', edit_user_path(current_user) %>
<%= link_to 'My dates', :controller => 'calendar', :action => 'month_for_user' %>
<%= link_to 'sign out', :controller => 'sessions', :action => 'destroy' %>
<% end %>
</div>
sessions_controller
def destroy
redirect_to main_page
sign_out
end
routes
Prefix Verb URI Pattern Controller#Action
meetings GET /meetings(.:format) meetings#index
POST /meetings(.:format) meetings#create
new_meeting GET /meetings/new(.:format) meetings#new
edit_meeting GET /meetings/:id/edit(.:format) meetings#edit
meeting GET /meetings/:id(.:format) meetings#show
PATCH /meetings/:id(.:format) meetings#update
PUT /meetings/:id(.:format) meetings#update
DELETE /meetings/:id(.:format) meetings#destroy
new_user GET /users/new(.:format) users#new
users GET /users(.:format) users#index
main_page GET /main_page(.:format) welcome#domain
new_session GET /sign_in(.:format) sessions#new
signout GET /sign_out(.:format) sessions#destroy
sessions POST /sessions(.:format) sessions#create
GET /sessions/new(.:format) sessions#new
edit_session GET /sessions/:id/edit(.:format) sessions#edit
session PATCH /sessions/:id(.:format) sessions#update
PUT /sessions/:id(.:format) sessions#update
DELETE /sessions/:id(.:format) sessions#destroy
GET /sessions/:id(.:format) welcome#domain
GET /users(.:format) users#index
POST /users(.:format) users#create
GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PATCH /users/:id(.:format) users#update
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
month_for_user GET /month_for_user(.:format) calendar#month_for_user
Rails is new for me, and maybe it's a silly question, but I honestly tried to find an answer unfortunately without results. Please, help me to fix this problem! Thank you
undefined local variable or method 'main_page'
The error comes from the destroy method in your sessions_controller. It should be
def destroy
redirect_to main_page_url #or action: "main_page"
sign_out
end
I'm trying to implement a Twitter Boostrap login form, that's gonna be used on every page (because the navigation bar is a part of the layout).
However, when trying the code below I get the following error:
No route matches {:action=>"show", :controller=>"users"}
User controller:
class UsersController < ApplicationController
def index
#users = User.all
end
def show
...
end
def login
...
end
end
_navigation.html.erb:
<div class="dropdown-menu" style="padding: 15px; padding-bottom: 0px;">
<%= form_for("user", :url => user_path) do |f| %>
<%= f.label :email%>
<%= f.text_field(:email, :size => 30, :class => 'login_field', :placeholder => 'Användarnamn')%>
<%= f.label :password%>
<%= f.text_field(:password, :size => 30, :class => 'login_field', :placeholder => 'Lösenord')%>
<%= f.submit "Logga in", :class => 'login_submit btn btn-primary' %>
<% end %>
</div>
config/routes.rb:
get "home/index"
resources :users
resources :projects
resources :tickets
root :to => 'home#index'
rake routes (that has to do with users):
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
I'm new to Rails but find it strange that it complains that the route doesn't exist because the action "show" is to be found inside the user controller.
The other thing I'm wondering about is why it looks for the action "show", while it should be "login" in this case?
Why is this happening and what shall I do?
your error is in this line
<%= form_for("user", :url => user_path) do |f| %>
user_path is expecting an id. if you change that to users_path, that should fix it but I don't think that's your intention.
UPDATE: to use the login action on the users controller, you need to update your routes
resources :users do
post :login, on: :collection, as: :login
end
passing the :as option creates a named_route for you called login_users_path which you can use on your form_for. and since we wanted to do a post, we also need to specify that in the form_for
<%= form_for("user", :url => login_users_path, :html => { :method => :post }) do |f| %>
Update your routes.rb to look like:
get "home/index"
resources :users do
post :login, :on => :collection
end
resources :projects
resources :tickets
root :to => 'home#index'
and in your view file change the form_for line to be:
<%= form_for("user", :url => login_users_path) do |f| %>
resources :users only adds default routes. If you want to add new action (other then defaults) you need to use 'collection. And you can specify the method get or post. After adding to routes.rb. You can get the path by running rake routes then you add the correct route in the action of form.
resources :users, :collection => {:login => :post}
I am encountering a routing error when I try to render a partial in an ajax call:
Routing Error
No route matches {:action=>"destroy", :controller=>"relationships", :user_id=>#<User id: 2, username: .....
Within my app, I have a list of followers for a user displayed on the profile page. Instead of paginating the followers, I would like to try to return the next offset of followers from the server through AJAX. My view already utilizes partials for displaying a list of these followers (limited to 5 records).
My goal is to use an AJAX call to return this partial with the next offset of records formated (I haven't implemented the functionality to return offset records yet - I'm just trying to get the ajax working first). The partials work fine when I visit the profile page in my browser (and view the first 5 records), the error occurs when I make the AJAX call.
Here is the form in the view where the ajax call originates:
<%= form_tag user_relationships_path(#user), method: :get, remote: true do %>
<%= submit_tag 'load more...' %>
<% end %>
Here is the route:
resources :users, only: [:index, :show, :new, :create, :edit, :update, :destroy] do
resources :relationships, only: [:create, :destroy, :index]
end
Here is my controller action (relationships#index) which responds to the request:
def index
#user = User.find_by_username(params[:user_id])
respond_to do |format|
format.js { render 'load_followers' }
end
end
The load_followers.js.erb partial:
$('ul#followers').append("<%= render 'users/following_items', users: #user.followers %>")
The users/following_items.html.erb partial:
<% users.each do |user| %>
<li class="clearfix">
<div class="box-gravatar pull-left">
<%= link_to user do %>
<%= gravatar_for user, 40 %>
<% end %>
</div>
<div class="pull-right">
<%= render 'relationships/follow', user: user %>
</div>
<%= link_to user.username, user %>
<div class="box-author">joined <%= join_date_for user %></div>
</li>
<% end %>
And finally the relationships/follow.html.erb partial:
<% unless current_user?(user) %>
<% if current_user.following? user %>
<p><%= link_to 'unfollow', user_relationship_path(user), method: :delete, class: "btn" %></p>
<% else %>
<p><%= link_to 'follow', user_relationships_path(user), method: :post, class: "btn btn-primary" %></p>
<% end %>
<% end %>
I have tracked down the offending code to the relationships/follow.html.erb partial. When that is removed, the ajax call works fine and the partial is appended to the end of the ul. Clearly it has to do with rails having an issue with the link_to to the relationships#destroy method - however, nothing I've tried seems to work.
Edit: Here are the results of running rake routes:
root / posts#index
posts_test /posts/test(.:format) posts#test
submit /submit(.:format) posts#new
signup /signup(.:format) users#new
login /login(.:format) sessions#new
logout DELETE /logout(.:format) sessions#destroy
about /about(.:format) about#index
search /search(.:format) search#index
sessions POST /sessions(.:format) sessions#create
new_session GET /sessions/new(.:format) sessions#new
session DELETE /sessions/:id(.:format) sessions#destroy
post_comments POST /posts/:post_id/comments(.:format) comments#create
post_votes POST /posts/:post_id/votes(.:format) votes#create
posts GET /posts(.:format) posts#index
POST /posts(.:format) posts#create
new_post GET /posts/new(.:format) posts#new
post GET /posts/:id(.:format) posts#show
user_relationships GET /users/:user_id/relationships(.:format) relationships#index
POST /users/:user_id/relationships(.:format) relationships#create
new_user_relationship GET /users/:user_id/relationships/new(.:format) relationships#new
edit_user_relationship GET /users/:user_id/relationships/:id/edit(.:format) relationships#edit
user_relationship GET /users/:user_id/relationships/:id(.:format) relationships#show
PUT /users/:user_id/relationships/:id(.:format) relationships#update
DELETE /users/:user_id/relationships/:id(.:format) relationships#destroy
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
categories GET /categories(.:format) categories#index
POST /categories(.:format) categories#create
new_category GET /categories/new(.:format) categories#new
category GET /categories/:id(.:format) categories#show
/:category(.:format) posts#index
Thanks!
Notices your rake routes outputted this line:
DELETE /users/:user_id/relationships/:id(.:format)
This means your named route user_relationship is expecting both user and relationship IDs. Reason being, relationship is a nested resource of user.
So for instance you currently have this in your link to:
= link_to 'unfollow', user_relationship_path(user), method: :delete, class: "btn"
Instead it should be something like:
= link_to 'unfollow', user_relationship_path(user, relationship), method: :delete, class: "btn"
I'm a noob that's been struggling with this problem for longer than I care to admit. I used to have a routing issue with my STI model, but now I think that's solved (thanks to SO).
My problem is once I update the form at : /kids/1/edit, instead of having the record saved, it seems to get the record again. I know I'm missing something basic, yet after working the issue a long time the answer eludes me. You can see I'm explicitly calling the kidupdate action with the form submission.
thanks in advance.
kidedit.html.erb
<% provide(:title, "Edit user") %>
<h1>Update your profile</h1>
<div class="row">
<div class="span5 offset3">
<%= form_for(#kid, url: kidedit_path) do |f| %>
<#%= render 'shared/error_messages', object: f.object %>
<%= f.label :fname, "First Name" %>
<%= f.text_field :fname %>
<%= f.label :lname, "Last Name" %>
<%= f.text_field :lname %>
<%= f.label :email %>
<%= f.text_field :email %>
<%= f.label :type, "Are you a Kid or Parent" %>
<%= f.select :type, [['Kid','Kid'],['Parent','Parent']] %>
<%= f.label :password %>
<%= f.password_field :password %>
<%= f.label :password_confirmation, "Confirmation" %>
<%= f.password_field :password_confirmation %>
<%= f.submit "Save changes", class: "btn btn-large btn-primary", :controller => 'users', :action => 'kidupdate' %>
<% end %>
</div>
</div>
users_controller.rb
def kidupdate
#kid = Kid.find(params[:id])
if #kid.update_attributes(params[:kid])
flash[:success] = "Profile updated"
sign_in #kid
redirect_to kidshow_path
else
render kidedit_path(#kid)
end
end
routes.rb
Kidtunes::Application.routes.draw do
root to: 'static_pages#home'
match '/help', to: 'static_pages#help'
match '/contact', to: 'static_pages#contact'
match '/signup', to: 'users#new'
match '/signin', to: 'sessions#new'
match '/signout', to: 'sessions#destroy', via: :delete
match 'kids/:id' => 'users#kidupdate', via: :put, :as => :kidupdate
match 'kids/:id' => 'users#kidshow', via: :get, :as => :kidshow
match 'kids/:id/edit' => 'users#kidedit', :as => :kidedit
resources :users
resources :sessions, only: [:new, :create, :destroy]
Here's what's in the server log:
Started PUT "/kids/1/edit" for 127.0.0.1 at 2012-11-05 07:52:28 -0500
Processing by UsersController#kidedit as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"T8RqFt9lxdbZU+1cOh2E5yu2CFbVRDGmRcj2XdDN1ZU=", "user"=>{"fname"=>"Dante", "lname"=>"Refford", "email"=>"drefford#example.com", "type"=>"Kid", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Save changes", "id"=>"1"}
Kid Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."type" IN ('Kid') AND "users"."id" = ? LIMIT 1 [["id", "1"]]
Rendered users/kidedit.html.erb within layouts/application (4.1ms)
Rendered layouts/_shim.html.erb (0.0ms)
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."remember_token" = '1RZr3qfB6QSh42_jQ9qNWQ' LIMIT 1
Rendered layouts/_header.html.erb (2.5ms)
Rendered layouts/_footer.html.erb (0.3ms)
Completed 200 OK in 67ms (Views: 46.3ms | ActiveRecord: 1.0ms)
Routes
$rake routes
root / static_pages#home
help /help(.:format) static_pages#help
contact /contact(.:format) static_pages#contact
signup /signup(.:format) users#new
signin /signin(.:format) sessions#new
signout DELETE /signout(.:format) sessions#destroy
kidupdate PUT /kids/:id(.:format) users#kidupdate
kidshow GET /kids/:id(.:format) users#kidshow
kidedit /kids/:id/edit(.:format) users#kidedit
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
sessions POST /sessions(.:format) sessions#create
new_session GET /sessions/new(.:format) sessions#new
session DELETE /sessions/:id(.:format) sessions#destroy
As the first comment said, the form should be using the update_path method:
<%= form_for(#kid, url: kidupdate_path) do |f| %>
First SO post, but I've read so many. I'm new to Rails and building first site since studying Hartl's RailsTutorial.
My issue is routing using STI. I believe the routes are set up correctly, but the subclass Kid doesn't find a "show" route.
Class inheritance using STI
class User < ActiveRecord::Base
class Kid < User
Kid Controller
def show
#kid = Kid.find(params[:id])
end
User Controller create
def create
#user = User.new(params[:user])
if #user.save
flash[:success] = "Welcome to kidtunes!"
if (#user.type = "Kid")
***redirect_to #kid***
else
redirect_to #parent
end
else
render 'new'
end
routes.rb
resources :users, :kids, :parents
root to: 'static_pages#home'
match '/help', to: 'static_pages#help'
match '/contact', to: 'static_pages#contact'
match '/signup', to: 'users#new'
Results in:
kids_new GET /kids/new(.:format) kids#new
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
kids GET /kids(.:format) kids#index
POST /kids(.:format) kids#create
new_kid GET /kids/new(.:format) kids#new
edit_kid GET /kids/:id/edit(.:format) kids#edit
kid GET /kids/:id(.:format) kids#show
PUT /kids/:id(.:format) kids#update
DELETE /kids/:id(.:format) kids#destroy
parents GET /parents(.:format) parents#index
POST /parents(.:format) parents#create
new_parent GET /parents/new(.:format) parents#new
edit_parent GET /parents/:id/edit(.:format) parents#edit
parent GET /parents/:id(.:format) parents#show
PUT /parents/:id(.:format) parents#update
DELETE /parents/:id(.:format) parents#destroy
root / static_pages#home
help /help(.:format) static_pages#help
contact /contact(.:format) static_pages#contact
signup /signup(.:format) users#new
Error
I get the following on redirect_to #kid
ActionController::ActionControllerError (Cannot redirect to nil!):
app/controllers/users_controller.rb:16:in `create'
I feel like I've checked everything I can check, but I'm still missing something. #kid should properly redirect to the kids#show route. I'm not sure if I have a poorly crafted single table inheritance or a basic routing issue.
thanks in advance.
-John
Form
This form is used in users/new.html.erb and it creates the User.
<div class="row">
<div class="span5 offset2">
<%= form_for(#user) do |f| %>
<%= render 'shared/error_messages' %>
<%= f.label :fname, "First Name" %>
<%= f.text_field :fname %>
<%= f.label :lname, "Last Name" %>
<%= f.text_field :lname %>
<%= f.label :email %>
<%= f.text_field :email %>
<%= f.label :type, "Are you a Kid or Parent?" %>
<%= f.select :type, [['Kid','Kid'],['Parent','Parent']] %>
<%= f.label :password %>
<%= f.password_field :password %>
<%= f.label :password_confirmation, "Confirmation" %>
<%= f.password_field :password_confirmation %>
<%= f.submit "Create my account", class: "btn btn-large btn-primary" %>
<% end %>
Have you defined/assigned values to the #kid or #parent variables? If not, they will be nil, and you'll get the cannot redirect to nil error you've included in your question.
Please include the full code for the create action. Otherwise we're left to trust (rather than read for ourselves) precisely what's happening in the redirect.
Your redirects might also need some work. For example, you could do:
if (#user.is_a? Kid)
redirect_to kid_path(#user)
else
redirect_to parent_path(#user)
end
...or something very similar to that.
First thing I noticed is that you're using = instead of ==:
if (#user.type = "Kid")
I think it's nicer to test it like that:
if #user.is_a? Kid
Can you show us how you set #kid and #parent?