Q&A
#環境
Ruby on Rails 5
slim-rails
#状況
現在erbで書かれたviewをslimに変換しようとしています。
しかしrenderの記述が違うのか上手く行きません。
ソースコードは以下の通りです
app/controllers/timeline_controller.rb
class TimelineController < ApplicationController def show @posts = Post.all end end
app/views/post/_post.html.erb
<div class="timeline"> <p><%= posts.content %></p> </div>
app/views/timeline/show.html.erb
<h1>timeline</h1> <div id="timeline"> <%= render @posts %> </div>
上記の記述をslimを使い以下のように直しました
app/views/post/_post.html.slim
.timeline p=posts.content
app/views/timeline/show.html.slim
h1 =@timeline #timeline render 'post', @posts
このように記述すると
'post', @posts
という結果がでます
これを踏まえwikiを改めて確認すると
==renderという記述があり、それに記述し直し実行してみると
NoMethodError in Timeline#show /app/views/timeline/show.html.slim where line #4 raised: undefined method `keys' for #<Post::ActiveRecord_Relation:0x007faf0c5cf270>
というエラーになります。
slimの記述が得意な方ご教授お願いします。
回答1件
あなたの回答
tips
プレビュー
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
2016/08/18 06:26 編集