Skip to content

anonymous /\app\models\user.rb
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Server error log when running accepts_nested_attributes_for
class User < ActiveRecord::Base
has_many :events, :dependent => :destroy
accepts_nested_attributes_for :events, :reject_if => lambda { |attributes| attributes['event_name'].blank? }, :allow_destroy => true
attr_accessible :name
end
<label>Name of event:
<p> <%= builder.text_area :event_name, :rows => 1 %> </p>
</label>
<label>Tracks
<p><%= builder.text_area :tracks, :rows => 1 %><p>
</label>
<label>Event starts:
<p><%= builder.text_area :starts_at, :rows => 1 %> <p>
</label>
<label>Event Finishes:
<p><%= builder.text_area :finish, :rows => 1 %><p>
</label>
</p>
<% end %>
ActionView::Template::Error (undefined method `events' for nil:NilClass):
9: </tr>
10: <td>
11:
12: <% @user.events.each do |event| %>
13: <tr>
14: <td><%= event.starts_at %></td>
15: <td><%= event.finishes %></td>
app/views/users/index.html.erb:12:in `_app_views_users_index_html_erb___603337143_36309060_0'
Rendered C:/Ruby/lib/ruby/gems/1.8/gems/actionpack-3.0.1/lib/action_dispatch/middleware/templates/rescues/_trace.erb (0.0ms)
User Load (0.0ms) SELECT "users".* FROM "users" ORDER BY name asc
Rendered C:/Ruby/lib/ruby/gems/1.8/gems/actionpack-3.0.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (15.6ms)
Rendered C:/Ruby/lib/ruby/gems/1.8/gems/actionpack-3.0.1/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (62.5ms)
<% title "Events" %>
<table >
<tr>
<th><%= sortable "Starts_at" %></th>
<th><%= sortable "Finishes" %></th>
<th><%= sortable "Event_name" %></th>
<th><%= sortable "Tracks" %></th>
</tr>
<td>
<% @user.events.each do |event| %>
<tr>
<td><%= event.starts_at %></td>
<td><%= event.finishes %></td>
<td><%= event.event_name %></td>
<td><%= event.tracks %></td>
</tr>
<% end %>
</table>
<%= link_to "Add new event", new_user_path %>
<%= button_to "Delete", @user,:confirmation => "Are you sure?", :method => :delete %>
ActiveRecord::Schema.define(:version => 20101201180355) do
create_table "events", :force => true do |t|
t.string "event_name"
t.string "tracks"
t.datetime "starts_at"
t.datetime "finish"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "user_id"
end
create_table "users", :force => true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
end
end
class UsersController < ApplicationController
respond_to :html, :xml, :js
def index
@users = User.all
end
def new
debugger
@user = User.new
1.times do
event = @user.events.build
#event = @user.build_event
end
end
def create
@user = User.new(params[:user])
if @user.save
flash[:notice] = "New user created"
redirect_to user_url(@user)
else
flash[:notice] = " User not created"
redirect_to new_user_url
end
end
def show
@user = User.find(params[:id])
end
def edit
@user = User.find(params[:id])
end
def update
@user = User.find(params[:id])
if @user.update_attributes(params[:user])
flsh[:notice] ="successfully updated."
redirect_to @user
else
render :action => 'new'
end
end
def destroy
@user = User.find(params[:id])
@user.destroy
flsh[:notice] ="successfully deleted user."
redirect_to @user
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.