Very confused about what is probably a simple issue. Trying to show just a column of my table by iterating through it but somehow before this happens my entire table is displayed.
Output:
All My Stories
[#Story id: 1, thought: nil, created_at: "2016-02-11 03:20:07", updated_at: "2016-02-11 03:20:07", #Story id: 2, thought: "hello my name is Patrick", created_at: "2016-02-11 03:22:04", updated_at: "2016-02-11 03:22:04", #Story id: 3, thought: "Dennis is cool", created_at: "2016-02-11 03:22:37", updated_at: "2016-02-11 03:22:37"]
Thoughts
hello my name is Patrick
Dennis is cool
Controller code:
class StoriesController < ApplicationController
def index
@stories = Story.all
end
def show
@story = Story.find(params[:id])
end
def new
@story = Story.new
end
def create
@story = Story.new(story_params)
if @story.save
redirect_to @story
else
render 'new'
end
end
private
def story_params
params.require(:story).permit(:thought)
end
end
View Code:
<h1>All My Stories</h1>
<table>
<tr>
<th>Thoughts</th>
</tr>
<%= @stories.each do |s| %>
<tr>
<td><%= s.thought %>
</tr>
<% end %>
</table>
Created my model using rails generate model Story thought:string