Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7047341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:45:34+00:00 2026-05-28T02:45:34+00:00

I have 3 model the first user.rb: class User has_many :boards, dependent: :destroy has_many

  • 0

I have 3 model the first user.rb:

class User
 has_many :boards, dependent: :destroy
 has_many :posts, dependent: :destroy, :autosave => true
 accepts_nested_attributes_for :boards
 accepts_nested_attributes_for :posts
end

The second model its board.rb

class Board
 has_many :posts, :dependent => :destroy , :autosave => true
 accepts_nested_attributes_for :posts
 belongs_to :user
end

The third model its post.rb

class Post
 belongs_to :user
 belongs_to :board
end

I want create a new post with a parent board in my action new from posts_controllers I have:

@post = Post.new
respond_to do |format|
  format.html # new.html.erb
  format.json { render json: @post }
end

I create a new board with:

def create
  @board = current_user.boards.new(params[:board])
   respond_to do |format|
    if @board.save
      format.html { redirect_to @board, notice: 'Board was successfully created.' }
      format.json { render json: @board, status: :created, location: @board }
    else
      format.html { render action: "new" }
      format.json { render json: @board.errors, status: :unprocessable_entity }
    end
  end
end

In partial _form.thml.erb I have this:

<%= form_for(@post, :html => {:multipart => true}) do |f| %>
<%= f.label :content %><br />
<%= f.text_area :content %>
<%= f.collection_select :board_id, Board.all, :id, :name%>
<%= f.submit %>
<% end %>

The problem is that in my select field appear every boards. I want only show and choose the boards that belongs_to the current_user.

Note I’m using mongoid.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:45:35+00:00Added an answer on May 28, 2026 at 2:45 am

    Your model can be simpler.

    class User
     has_many :boards, dependent: :destroy
     accepts_nested_attributes_for :boards
    end
    
    class Board
     has_many :posts, :dependent => :destroy , :autosave => true
     belongs_to :user
     accepts_nested_attributes_for :posts
    end
    
    class Post
     belongs_to :board
    end
    
    <%= form_for(@post, :html => {:multipart => true}) do |f| %>
    <%= f.label :content %><br />
    <%= f.text_area :content %>
    <%= f.collection_select :board_id, Board.find_by_user_id(current_user.id), :id, :name%>
    <%= f.submit %>
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three models: category.rb class Category include Mongoid::Document # Relationships has_many :posts, :autosave
I have 3 model class User < ActiveRecord::Base has_many :profiles has_many :companies, :through =>
I have a user and post model: class User < ActiveRecord::Base has_many :sent_posts, :class_name
I have an Account model and a User model: class Account < ActiveRecord::Base has_many
I have my models setup like so: class User < ActiveRecord::Base has_many :posts, :foreign_key
I have the models User and StoredItem: class UserData < ActiveRecord::Base has_many :stored_items, :dependent
I have 2 models The first model category.rb class Category include Mongoid::Document # Relationships
I have the following models, with their relevant associations: class User < ActiveRecord::Base has_many
I have this models: class Comment(models.Model): text = models.TextField(max_length = 300) author = models.ForeignKey(User)
I have a model that holds user address. This model has to have first_name

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.