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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:01:05+00:00 2026-06-11T16:01:05+00:00

Here is the users show view where they are supposed to show up. ..

  • 0

Here is the users show view where they are supposed to show up. ..

<section>
  <div id= "purchases">
    <%= render 'shared/micropost_form_purchase' %>
  </div>
  <div id="sales">
    <%= render 'shared/micropost_form_sale' %>
  </div>
</section>

<%= @sales %>  <%# This is just to see if it outputs anything. It doesn't :( %>
<div id="purchases list">
  <ol class="microposts">
    <%= render @purchases unless @purchases.nil? %>
  </ol>
</div>

<div id="sales list">
  <ol class="microposts">
    <%= render @sales unless @sales.nil? %>
  </ol>
</div>

so the forms (partials) are loading fine, but then when I make a post, in either one, neither the purchases list nor the sales list shows up. I checked the database and they are being created along with an entry in the column indicating kind (either sale or purchase).

Here are the forms:

<%= form_for (@micropost) do |f| %>

  <div class="field no-indent">
    <%= f.text_area :content, placeholder: "What's something else you want to buy?" %>
    <%= hidden_field_tag 'micropost[kind]', "purchase" %>
  </div>
  <%= f.submit "Post", class: "btn btn-large btn-primary" %>
<% end %>

and

<%= form_for (@micropost) do |f| %>

  <div class="field no-indent">
    <%= f.text_area :content, placeholder: "What's something else you want to buy?" %>
    <%= hidden_field_tag 'micropost[kind]', "sale" %>
  </div>
  <%= f.submit "Post", class: "btn btn-large btn-primary" %>
<% end %>

also, here is the show part of the users_controller.rb

 def show
    @user = User.find(params[:id])
    @micropost=Micropost.new
    @microposts = @user.microposts.paginate(page: params[:page])
  end

and here is the show part of the microposts_controller.rb

def show

    @micropost = Micropost.find(params[:id])
    @microposts = Micropost.where(:user_id => @user.id)
    @purchases= @microposts.collect{ |m| m if m.kind == "purchase"}.compact
    @sales = @microposts.collect{ |m| m if m.kind == "sale"}.compact

  end

additionally, with the help of this post (http://stackoverflow.com/questions/12505845/ruby-error-wrong-number-of-arguments-0-for-1#12505865) the variables @microposts, @purchases, and @sales are all outputting correctly in the console.

can anyone help me out?

edit: using scopes as suggested by the answer given works in the console (it outputs everything correctly, but they still don’t show up in the view. Does this mean it is something wrong with my syntax for the users show page?

edit 2:

Here is the view/microposts/_micropost.html.erb code

<li>
  <span class="content"><%= micropost.content %></span>
  <span class="timestamp">
    Posted <%= time_ago_in_words(micropost.created_at) %> ago.
  </span>
  <% if current_user?(micropost.user) %>
    <%= link_to "delete", micropost, method:  :delete,
                                     confirm: "You sure?",
                                     title:   micropost.content %>
  <% end %>
</li>
  • 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-11T16:01:06+00:00Added an answer on June 11, 2026 at 4:01 pm

    I’m making some assumptions without seeing more of your code, but it looks like you could
    write what you’ve shown a little differently. I’m assuming your databases are migrating
    and have the required columns, e.g., Micropost#kind, Micropost#user_id, etc.
    You can use scopes to refine a collection of microposts more expressively. It might be helpful to read
    up about ActiveRecord scopes: http://guides.rubyonrails.org/active_record_querying.html#scopes.

    class Micropost < ActiveRecord::Base
      belongs_to :user
    
      scope :purchases, where(:kind => "purchase")
      scope :sales, where(:kind => "sale")
    
      # your code
    end
    

    I’m also assuming your user has many microposts:

    class User < ActiveRecord::Base
      has_many :microposts
    
      # your code
    end
    

    For your forms, I’d suggest attaching your hidden field to the form object (f.hidden_field) so
    you don’t have to specify the name as ‘micropost[kind]’.

    <%= form_for(@micropost) do |f| %>
      <div class="field no-indent">
        <%= f.text_area :content, placeholder: "What's something else you want to buy?" %>
        <%= f.hidden_field :kind, :value => "sale" %>
      </div>
      <%= f.submit "Post", class: "btn btn-large btn-primary" %>
    <% end %>
    

    In MicropostsController#show, you can use your new scopes:

    def show
      @micropost = Micropost.find(params[:id])
      @microposts = @user.microposts
      @purchases = @microposts.purchases
      @sales = @microposts.sales
    end
    

    You should also confirm that your MicropostsController#create action is actually adding
    the microposts to the user sending the form (I’m assuming a current user method).

    def create
      @micropost = current_user.microposts.create(params[:micropost])
      # yada
    end
    

    You can also confirm expected results on rails console after creating purchases or sales micropost with:

    Micropost.purchases
    Micropost.sales
    

    Again, I could be missing something without seeing more of the code base.

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

Sidebar

Related Questions

Here is the users show view where they are supposed to show up. ..
I've got 3 tables that are something like this (simplified here ofc): users user_id
This Question has been modified to show working code. When they click an item
I have a view that dynamically updates depending on user input - here's how
i crate @Html.ActionLink helper here i check permissions of user. if yes i show
Here are my models: **Resource** has_many :users, :through => :kits has_many :kits **User** has_many
Here are the list of methods for selecting users by different parameters. For example
Here is a snippet from a Sinatra app where users will be submitting urls.
The goal here is maximum conversion of users to an application. I tried to
Here is my problem in codeigniter MVC. Suppose I have 3 models: (users, email

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.