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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:07:10+00:00 2026-05-28T03:07:10+00:00

Here is my test in my controller: describe GET index do it assigns all

  • 0

Here is my test in my controller:

describe "GET index" do
  it "assigns all comments as @comments" do
    comment = Comment.create! valid_attributes
    get :index, { :url => "http://localhost:3000", :use_route => :good_comments}
    assigns(:comments).should eq([comment])
  end
end

When I run the test, it has different values for :comments and comment. The first is what one would expect:

#<MyComments::Comment _id: BSON::ObjectId('4f0f7c41516d9f5a4a000001'), comment: "Some comment", created_at: Fri, 13 Jan 2012 00:35:13 UTC +00:00, images: [], resource_hash: "aHR0cDovL2xvY2FsaG9zdDozMDAwLw==", updated_at: Fri, 13 Jan 2012 00:35:13 UTC +00:00, urls: [], user_id: nil>

The second is just odd:

#<Plucky::Query sort: [["created_at", -1]], transformer: #<Proc:0x007fe86e3184c8@/Users/shamoon/.rvm/gems/ruby-1.9.2-p290@global/gems/mongo_mapper-0.10.1/lib/mongo_mapper/plugins/querying.rb:79 (lambda)>

I’m not sure what’s going on, so any help would be greatly appreciated.

Thanks =)

EDIT: Adding Controller Code

# POST /comments
# POST /comments.json
def create
  @comment = Comment.new params[:comment]
  respond_to do |format|
    if @comment.save
      format.html { redirect_to :back, notice: 'Comment was successfully created.' }
      format.json { render json: @comment, status: :created, location: @comment }
    else
      format.html { render action: "new" }
      format.json { render json: @comment.errors, status: :unprocessable_entity }
    end
  end
end

# GET /comments
# GET /comments.json
def index
  url = ""
  if params[:url]
    url = params[:url]
  end
  resource_hash = Comment.encode_url url

  @newComment = Comment.new
  @newComment.resource_hash = resource_hash

  @comments = Comment.find_all_by_resource_hash resource_hash
  @comments = Comment.sort(:created_at.desc)

  respond_to do |format|
    format.html # index.html.erb
    format.json { render json: @comments }
  end
end

EDIT: UPDATED index ACTION

def index
  url = ""
  if params[:url]
    url = params[:url]
  end
  resource_hash = Comment.encode_url url

  @newComment = Comment.new
  @newComment.resource_hash = resource_hash

  @comments = Comment.where(:resource_hash => resource_hash).sort(:created_at.desc)

  respond_to do |format|
    format.html # index.html.erb
    format.json { render json: @comments }
  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-28T03:07:11+00:00Added an answer on May 28, 2026 at 3:07 am
    @comments = Comment.find_all_by_resource_hash resource_hash
    @comments = Comment.sort(:created_at.desc)
    

    Thats your problem, you are overwriting the @comments variable in the second line, try this for a start, I’m not sure if it is going to let you call sort on that but well see:

    @comments = Comment.find_all_by_resource_hash resource_hash
    @comments = @comments.sort(:created_at.desc)
    

    UPDATE

    Try doing this:

    @comments = Comment.where(:resource_hash => resource_hash).sort(:created_at.desc).all
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is a test description, testing the Create New Widget use-case. Confirm that you
here is the test page http://www.studioteknik.com/html/test-portfolio.html I got no error, but no hover-slide effect...
Here is a test framework to show what I am doing: create a new
http://steph.net23.net/work.php here is my test link. This page has a jquery script in it
Here is the create in rfq controller: def create if has_create_right? @rfq = Rfq.new(params[:rfq],
I'm having trouble writing a unit test for one of my controller actions. Here's
I am trying to test my controller's create action. I am using Devise for
Here's my http basic authentication in the application controller file (application_controller.rb) before_filter :authenticate protected
I followed the rails cast of omniauth to create authentication for twitter ( http://railscasts.com/episodes/235-omniauth-part-1?view=comments
def mock_category(stubs={}) @mock_category ||= mock_model(Category, stubs).as_null_object end describe GET show do it assigns the

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.