所以在我的崗位控制器,我有Rails的:無法與「ID」 =指數
def index
@post = Post.all.order('created_at DESC')
end
def show
@post = Post.find(params[:id])
end
private
def post_params
params.require(:post).permit(:title, :body)
end
,並在我的.erb文件
<% @post.each do |post| %>
<h2 class="post_wrapper">
<h2 class="title"><%= link_to post.title, post %></h2>
<p class="date"><%= post.created_at.strftime("%B, %d, %Y")</p>
<% end %>
鏈接應該是找到帖子拿起6 in/posts/6,但我想這不是。
編輯:這是我的routes.rb
Rails.application.routes.draw do
resources :posts
root "index#index"
end
我大多使用YouTube教程。這樣做的人並不是最好的,但我明白他在做什麼。感謝您的幫助! –
訪問http:// localhost:3000/posts時會發生什麼? – oreoluwa
它的工作。我有一些內聯錯誤,我覺得已經太遲了。 我通常很擅長命名我的變量,特別是他們需要的東西。剛剛到達,女朋友正在強調我一點點。 感謝您的幫助。這是很好的修復這些東西,並正確張貼:) 我upvoted你,但它說我太新手了。 –