Reputation: 2282
class ItemController < ApplicationController
def create
item = current_user.items.build(params[:presentstem])
item.created_at = Time.now
item.save!
redirect_to root_path
end
def destroy
end
end
And my form in views/home/index/html.erb to add an item
<div id="add_item">
<p>Add a new item</p>
<% form_for Item.new do |f| %>
<div id="add_item_container">
<%= f.text_field :present %>
<%= f.text_field :stem %>
<%= f.text_field :secondary %>
<%= f.check_box :atype %>
<%= f.text_field :comment %>
</div>
<%= f.submit "Add to List" %>
<% end %>
</div>
How do I define Item
?
at localhost:3000 I get
Expected /Users/user/Desktop/test/app/models/item.rb to define Item
Extracted source (around line #3):
Upvotes: 0
Views: 2378
Reputation: 2280
You are thinking wrong.
You have an model in app/models/item.rb
for this you have an controller in app/controllers/items_controller.rb
and you have views in app/views/items/template.haml
if you want to do a form_for you do the form for a object. rails is looking what type of action you want to participate (new, update) and generates automatically the route (restful).
so you just gave an object to the form_for helper
#in view
=form_for Item.new do |f|
or
#in items_controller.rb
def new
@item = Item.new
end
#in new.haml
=form_for @item
Upvotes: 0
Reputation: 19176
You should have Item class definition in this file /Users/user/Desktop/test/app/models/item.rb
, probably you don't...
class Item < ActiveRecord::Base
#class definition goes here
end
Upvotes: 1