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 8112475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:30:48+00:00 2026-06-06T02:30:48+00:00

I am trying to learn by doing and need some help. So formtastic can

  • 0

I am trying to learn by doing and need some help.

So formtastic can handle belongs_to associations (like Post belongs_to :author), rendering a select or set of radio inputs with choices from the parent model.

What I am trying to do is create a post without having to select the author in the create form.

I want to set the author id via a hidden form field but when I try this

 <%= f.input :author, :as => :hidden, :value => '33' %>

I get uninitialized constant author and tried various other ways that Ive failed to get to work.

The closest Ive got has been by trying to customise the choices for the select and hiding the select as follows:

<%= f.input :author, :as => :select, :collection => ["33"], :input_html => { :style => 'visibility: hidden' } %>

But even though the above hides the select and works, it still displays a form label for author which I dont want it to display

Here is an example to better explain my scenario if what Im trying to achieve is still unclear:

Imagine you have a list of authors page and as an author you click on your name to get into an area where you can manage various things and create posts.

The problem: When you click create a post and the form renders, you dont want to have to select your name from one of the fields to tell the app that the post you are creating belongs to you because you want the system to know its yours because you are in a config area that belongs to you.

I am trying to do this by using a hidden form field to set the author id so that the post is saved with the correct association when the user submits the form.

Can anyone provide me with an example of how to do this? and as Im a learner maybe there is a better way to approach this so can anyone please advise and point me to some good examples

  • 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-06T02:30:51+00:00Added an answer on June 6, 2026 at 2:30 am

    You should not be populating it in a hidden form field; hidden form fields can still be changed by the user and in the end you are allowing users to create posts by other authors.

    The correct way to do this would be to assign @post.author = current_user in the create action of your PostsController.

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

Sidebar

Related Questions

so, i'm trying to learn ruby by doing some project euler questions, and i've
So i'm trying to learn how to program with Task's and i'm doing an
Trying to learn Sencha Touch 2 and I can't seem to find out how
Trying to learn about php's arrays today. I have a set of arrays like
I'm trying to learn how to use HTMLUnit in order to test some website's
trying to learn some html/css and I'm having a problem with fixed position divs.
I'm trying to learn servlets and JSP and would like to do this with
I'm trying to learn some programming with jQuery. I have a div that has
Im trying to learn php by doing a little project using apache server. I
I'm trying to learn C# from some YouTube videos, but I have a few

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.