Answer the question
In order to leave comments, you need to log in
How to make selection filters in rails?
In general, I’ve been sitting for 4 hours now and I can’t figure out how to make a selection list for users ...
The bottom line: There are posts with status and cities and categories, now index.html.erb displays all posts for all cities and statuses, but you need to do so that you can was to select posts by city and by status. For example, in a drop-down list or cheb box, you could select the city and post status.
and how can the user by default see the posts of the city selected during registration?
Post Model
class Post < ActiveRecord::Base
NORMAL = 1
ACTIVE = 2
COMPLETED = 3
STATUSES = {
NORMAL => 'не опубликовано',
ACTIVE => 'опубликовано',
COMPLETED => 'помечено для удаления'
}
def status_name
STATUSES[status]
end
belongs_to :user
belongs_to :category
belongs_to :city
default_scope -> { order('created_at DESC') }
end
class PostsController < ApplicationController
def index
@category = Category.find(params[:category_id])
@feed_items = @category.posts.paginate(page: params[:page])
end
end
<h1><%= @category.name %></h1>
<%= link_to 'Все категории', all_post_path %>
<% Category.all.each do |category| %>
<%= link_to category.name, category_posts_path(category) %>
<% end %>
<%= render 'categories/feed' %>
<% if @feed_items.any? %>
<%= render partial: 'categories/feed_item', collection: @feed_items %>
<%= will_paginate @feed_items %>
<% end %>
<%= link_to (truncate feed_item.name,:length => 35), feed_item %>
<%= link_to feed_item.user.name, (feed_item.user) %>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question