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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:52:07+00:00 2026-06-14T12:52:07+00:00

I just finished Hartl’s RoR tutorial and am now trying to mess around with

  • 0

I just finished Hartl’s RoR tutorial and am now trying to mess around with some more stuff.

Specifically: I’m trying to allow the user to create microposts on any page, by rendering the micropost partial in the header.html.erb file (which is rendered on every page).

the partial:

<%= form_for(@micropost) do |f| %>
  <%= render 'shared/error_messages', object: f.object %>
  <div class="field">
    <%= f.text_area :content, placeholder: "micropost" %>
  </div>
  <%= f.submit "Post", class: "btn btn-large btn-primary" %>
<% end %>

Doing this has resulted in the error on line #1 of the partial: undefined method 'model_name' for NilClass:Class on any page which I have not fixed by adding @micropost = current_user.microposts.build in the controller method that links to said view. For example:

#in controllers/static_pages_controller.rb
def about
  if signed_in?
    @micropost = current_user.microposts.build
  end
end

Would fix this error when I visit the about page

I’ve been trying to figure out a way to do a “blanket fix” that will work on all pages without me having to paste in the declaration everywhere, any ideas?

  • 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-14T12:52:09+00:00Added an answer on June 14, 2026 at 12:52 pm

    You don’t need to use the form_for builder here; Rails also provides a form_tag helper for more generic forms:

    <%= form_tag create_micropost_path, method: :post do %>
      <%= text_area_tag :micropost_content, placeholder: "micropost" %>
      <%= submit_tag "Post", class: "btn btn-large btn-primary" %>
    <% end %>
    

    This way, you don’t need to build the object when loading every page, but microposts#create can still pull data from params[:micropost]. See here for more info.

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

Sidebar

Related Questions

I just finished my first Site Template on ThemeForest. Now i searched for some
Just finished Michael's Hartl online tutorial . So my current state is: a little
I just finished the Django tutorial and started work on my own project, however,
I just finished the Netbeans introduction to Hibernate tutorial ( http://netbeans.org/kb/docs/web/hibernate-webapp.html#01 ) and I
I just finished adding and removing different database models (I was trying to figure
just finished writing a five card poker hand evaluator in C++. now im looking
I just finished coding a C# project targeting .Net v4. I'm trying to put
I just finished a little 5000-line PHP application and are now going into testing
I just finished a tutorial for test driven development in c# with Nunit. I
I just finished a couple of activities in my game and now I was

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.