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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:56:05+00:00 2026-05-26T22:56:05+00:00

It worked before but why it isn’t now? I was trying to to create

  • 0

It worked before but why it isn’t now? I was trying to to create a post by only the signIn user.Or is it my routing problems?
My routing is
resources :users do
resources :microposts
end

microposts controller

def create
    @micropost = current_user.microposts.build(params[:micropost])
    if @micropost.save 
        flash[:success] = "Post created!"
        redirect_to @micropost
    else
        render 'new'
    end
end

new.html.erb

 <%= form_for @micropost do |f| %>
<%= render 'shared/error_messages', :object => f.object %>
<%= f.hidden_field :user_id, :value => current_user.id %>

<%= f.label :title %><br />
<%=h f.text_field :title %><br />

<%= f.label :content %><br />
<%=h f.text_area :content, :row => 30, :cols=> 30 %><br />

<%= f.label :category %><br />
<%=h f.text_field :category %><br />

<%= f.submit "Post" %>

microposts model

class Micropost < ActiveRecord::Base
belongs_to :users
default_scope :order => 'microposts.created_at DESC'

attr_accessible :title,:content,:category

validates :user_id, :presence => true
validates :title,    :presence => true,
                     :length => {:maximum =>500}                            
validates :content,  :presence => true,
                     :length => {:maximum =>3000}                           
validates :category, :presence => true

end

migration microposts

class CreateMicroposts < ActiveRecord::Migration
  def self.up
create_table :microposts do |t|
  t.string :title
  t.string :content
  t.string :user_id
  t.string :category

  t.timestamps
end
    add_index :microposts, [:title, :created_at, :category]
  end

  def self.down
    drop_table :microposts
 end
end
  • 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-26T22:56:05+00:00Added an answer on May 26, 2026 at 10:56 pm

    Your user model needs:

    has_many :microposts
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this Android code worked fine before, but i'm having problems for some reason. here
I've posted this before, but I worded it poorly. I'm trying again with a
I know I have done this before, but it isn't working today, nor can
I had a connection working but something changed and now the data isn't showing
I have setup this HABTM relationship in the past and it has worked before....Now
The Documentation from facebook isn't understandable, atleast for me. I have never worked before
I've written a new application in a network I haven't worked in before, and
I have the following bit of code that worked as expected before we upgraded
I have inherited a SSIS project. I have never worked with SSIS before, and
At my new company, the CMS is ClearCase. I've worked with Perforce before and

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.