を注文します。
stories_controller.rbは次のようになります。それらの両方を注文する私のindex.html.erbイムtryignでルビー - 私はそれらを一緒に注文しようとしています私は2つのモデルのimage.rbとstory.rb <br></p> <p>を持つ2つのモデル
private
def image_params
params.require(:image).permit(:title, :image, :image_file_name, :category)
end
しかし、私はに実行します。
def index
@stories = Story.all.order(:cached_votes_total => :desc)
@images = Image.all.order(:cached_votes_total => :desc)
@combined = (@stories + @images).sort_by {|record| record.created_at}
end
private
def story_params
params.require(:story).permit(:title, :content, :category)
end
images_controller.rbは次のようになりますパラメータが異なるため、未定義のメソッドエラーが発生します。
<% @combined.each do |s| %>
...
<% end %>
これを修正する方法はありますか?
これは間違ったアプローチです。モデルの関連付けを使用する必要があります –