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

  • Home
  • SEARCH
  • 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 7923377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:18:15+00:00 2026-06-03T17:18:15+00:00

I have two models, Category and Post. Category.rb class Category include Mongoid::Document field :title,

  • 0

I have two models, Category and Post.

Category.rb

class Category
include Mongoid::Document

field :title, :type => String
has_many :posts, :autosave => true, dependent: :destroy

end

Post.rb

class Post
include Mongoid::Document

field :title, :type => String
belongs_to :category
end

I’m using simple_form gem

If I write in my post form the next:

<%= simple_form_for(@post) do |f| %>
 <%= f.collection_select :category, Category.all, :id, :title, :prompt => "Choose a Category"%>
 <%= f.input :title %>
 <%= f.button :submit %>
<% end %>

The form does works fine :).

but if I use the next form with simple_form format:

<%= simple_form_for(@post) do |f| %>
  <%= f.association :category, :prompt => "Choose a Category" %>
  <%= f.input :title %>
  <%= f.button :submit %>
 <% end %>

I get the next error:

Completed 500 Internal Server Error in 23ms
ActionView::Template::Error (undefined method `valid_options' for nil:NilClass):

How can I fix it?
Thank you!

  • 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-06-03T17:18:16+00:00Added an answer on June 3, 2026 at 5:18 pm

    The problem was fixed. Thank you to Carlos Antonio da Silva :D.

    you can find the fix in http://groups.google.com/group/plataformatec-simpleform/browse_thread/thread/f384f0445af8468e or:

    <%= f.input :category, :collection => Category.all, :prompt => "Choose a Category" %>
    

    Thank you!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two basic models, Story and Category: class Category(models.Model): title = models.CharField(max_length=50) slug
i have two models: class Category has many :jobs end class Job belongs_to :category
I have two related models such as this: class PartCategory < ActiveRecord::Base has_many :part_types
Let's say you have two models: Post and Category . Each Post has a
I have two models with managers: Category and Project. class PopulatedCategoriesManager(models.Manager): def get_query_set(self): return
Say I have two models, Article and Category: class Article(models.Model): category = models.ForeignKey(Category, related_name='articles')
I have a two models: class Category(models.Model): pass class Item(models.Model): cat = models.ForeignKey(Category) I
I have two models, 'product' with 'belongs_to' and 'category' with 'has_many'. Product has a
I have two models, Category and Point . The associations are defined as: Category
I have two models: class User end class Message belongs_to :sender, :class_name=> 'User' belongs_to

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.