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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:41:23+00:00 2026-05-20T21:41:23+00:00

Im trying to setup a simple environment: class Member < ActiveRecord::Base has_many :microposts, :dependent

  • 0

Im trying to setup a simple environment:

class Member < ActiveRecord::Base
  has_many :microposts, :dependent => :destroy
end

class Webpage < ActiveRecord::Base
  has_many :microposts, :dependent => :destroy
end

class Micropost < ActiveRecord::Base
  attr_accessor :content

  belongs_to :member
  belongs_to :webpage
end

I am trying to setup an environment that when the ‘show’ method of a Webpage contains a ‘create’ form for a Micropost.

Initially, Microposts were only associated with Members – and this was working fine (the member_id is being set upon login as a cookie and that cookie is being stacked to the Micropost.build method).

The problem here is that I cannot pass the webpage_id – I have tried setting the webpage_id as a cookie and passing it, but that was no good. And currently I am trying to pass the webpage_id as a hidden variable.

The controller for Micropost :create

class MicropostsController < ApplicationController
  def create
    @micropost  = current_member.microposts.build(params[:micropost])
    @webpage = Webpage.find(params['webpage_id'])
    @micropost.webpage = @webpage
    if @micropost.save
      flash[:success] = "Micropost created!"
      redirect_to root_path
    else
      @feed_items = []
      render 'pages/home'
    end
  end
end

and the Webpage :show View:

<table class="front" summary="For signed-in members">
    <tr>
      <td class="main">
        <h1 class="micropost">What's up?</h1>
        <%= form_for @micropost do |f| %>
          <%= render 'shared/error_messages', :object => f.object %>
          <div class="field">
            <%= f.text_area :content %>
            <input type="hidden" id="webpage_id" name="micropost[webpage_id]" value="<%= @webpage.id %>"/>
          </div>
          <div class="actions">
            <%= f.submit "Submit" %>
          </div>
        <% end %>
      </td>
    </tr>
</table>

Everytime I submit the create form, I can see the webpage_id being passed but it is not being saved and the error I get is:

“Couldn’t find Webpage without an ID”

Any help would be greatly appreciated 🙂

Cheers,

Damo

  • 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-20T21:41:24+00:00Added an answer on May 20, 2026 at 9:41 pm

    You could make the microposts a nested resource of webpage in your routes.rb file.

    This way you can make a form:

    form_for([@webpage, Micropost.new]) do |f|
    

    It will then POST to:

    webpage_microposts POST   /webpage/:webpage_id/microcomments
    

    And you will access the webpage id in your Micropost controller as such:

    @webpage = Webpage.find(params[:webpage_id])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to setup a simple demo of activemq and mina. I edited
I am trying to setup a dev environment at home. My primary development environment
I'm trying to setup a simple mod_rewrite for formatting pretty URLs. All I need
I'm trying to setup a simple slide show using ContentFlow javascript ( http://www.jacksasylum.eu/ContentFlow/index.php ),
I'm a new Java programmer, and I've been trying to setup a simple Swing
I am trying to set up a simple transaction for my Linq-to-Sql actions against
I'm trying setup a subset of boost and get it properly compiled using bjam,
Trying to setup an SSH server on Windows Server 2003. What are some good
After trying to setup my site for Google Webmaster Tools I found that my
I'm trying to setup CruiseControl.net at the moment. So far it works nice, but

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.