Executive Summary
- Goal: I am creating an admin dashboard, editable by a form_for
- I have a Post model which has two attributes: Subject and Title
- I have created an Admin Controller, which has an index action
- I get an error claiming it can't find the undefined method `subject' for ActionView:FormBuilder:0x000000031e02c8>
- Clearly I have a 'subject' item! I am staring at it right now... and cursing.
Dear Friends,
As you can see I have within my post.title, post.subject; I iterate through each @posts.each and then pass each individual object a form! What gives it claims i don't have an item. This is so strange?
Model: class Post < ActiveRecord::Base attr_accessor :title, :subject
end
routes:
resources :admin_dashboards
admin_dashboards_controller.rb
class AdminDashboardsController < ApplicationController
def index
@posts = Post.all()
end
View: index.html.erb
<tr>
<%= @posts.each do |post| %>
<%= form_for post do |single_post| %>
<td> <%= single_post.subject %> </td>
<td> <%= single_post.submit %> </td>
</tr>
<% end %>
<% end %>
scheme.rb
create_table "posts", force: true do |t|
t.text "title"
t.text "subject"
t.text "url"
t.datetime "created_at"
t.datetime "updated_at"
end
Aucun commentaire:
Enregistrer un commentaire