<%= form_for([:admin, @post]) do |f| %>
  <% if @post.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2>

      <ul>
      <% @post.errors.full_messages.each do |message| %>
        <li><%= message %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= f.label :title %><br>
    <%= f.text_field :title %>
  </div>
  <div class="field">
    <%= f.label :body %><br>
    <%= f.text_area :body %>
  </div>
  <div class="field">
    <%= f.label :site_id %><br>
    <%= f.collection_select :site_id, Site.all, :id, :name %>
  </div>
  <div class="field">
    <%= f.label :published_at %><br>
    <%= f.datetime_select :published_at %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

<%= form_for([:admin, @post]) do |f| %>
  <% if @post.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2>

      <ul>
      <% @post.errors.full_messages.each do |message| %>
        <li><%= message %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= f.label :title %><br>
    <%= f.text_field :title %>
  </div>
  <div class="field">
    <%= f.label :body %><br>
    <%= f.text_area :body %>
  </div>
  <div class="field">
    <%= f.label :site_id %><br>
    <%= f.collection_select :site_id, Site.all, :id, :name %>
  </div>
  <div class="field">
    <%= f.label :category_id %>
    <%= f.grouped_collection_select :category_id, Site.all, :categories, :name, :id, :name %>
  </div>
  <div class="field">
    <%= f.label :published_at %><br>
    <%= f.datetime_select :published_at %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

Select category in post form
Select category in post form

But I want to display only categories related to selected site.
