Undefined Method in HTTParty class - css

I'm somewhat new to rails and every time I think I'm getting it I hit a wall.
I'm using HTTParty and this API. I am just trying to get a response to show up in my index view to get the lowest level of the api working.
It worked for me in the console but not when I tested it in the API. I'm getting an
undefined method `picture' for Snapshots:Class
error for my index view.
Here is the HTTParty class
class Snapshots
include HTTParty
def initialize
#sitename = "google.com"
end
def picture
response = HTTParty.get("http://api.snapito.com/web/516e011353b62078731712566b01e143f56adf0b/full/diditmatter.herokuapp.com/lists")
if respone.success?
response
end
end
end
Here is my lists controller
def index
#it_works = Snapshots.picture
respond_with(#lists = List.all)
end
And here is list view
<%= #it_works %>
<h1 class="page-header">Projects at a glance</h1>
<div class="span12 offset2">
<% #lists.each do |list| %>
<div class="well row span4">
<div class="span3">
</div>
<div class="span4">
What do I seem to be overlooking here?
EDIT
#Benjamin fix worked, but I've come across a problem I'm not sure is related to rails. I'm not sure is I should open another question. But since the context is here and I'm not really even sure how to search this, I have to follow up here.
That instance variable is returning the attached screen shot. Is this related to how I'm calling it from the API I linked to in the first paragraph?
I've never seen this so not to sure where to look or how to approach.

You are treating the picture method as a class method. Change it to this: #it_works = Snapshots.new.picture

Related

How can I find classname an element with multiple classes in cypress

I'm a tester, and I have this HTML code.
<div id="columns">
<div class="column ce-editable c1">
</div>
</div>
I'm using Cypress. I want to examine if there is 'c1' class name found in the div element. If I try:
cy.xpath ('//div[#id="columns"]//div')
.should('have.class', 'c1')
I have this error:
CypressError: Timed out retrying: You attempted to make a chai-jQuery assertion on an object that is neither a DOM object or a jQuery object.
The chai-jQuery assertion you used was:
> class
The invalid subject you asserted on was:
> [<div.column.ce-editable.c1>]
To use chai-jQuery assertions your subject must be valid.
This can sometimes happen if a previous assertion changed the subject.
May I give you a whole other direction. It goes far, far away from using Xpaths :). What you can do to archive what you want is the following:
cy.get('#columns')
.find('div')
.should('have.class','c1')
This results in a few positive things:
1. It's easier to read what is happening
2. Debugging is easier, you'll see that Cypress tries to verify c1 in three steps. First find some ID with 'columns', than find a div below that and finish with asserting that the last searched div has a class called 'c1'.
3. The results show more neath since should() is actual an assertion instead of an action.

How to verify text in a css class with Selenium?

I am using Selenium to automate app creation test. The test includes filling out fields on a web page and clicking a submit button. Once that is done, a new page loads with an alert stating success or failure. The problem for me is, the alert is coded in a css class as follows:
<div class="alert-box notice">
Successfully created application
×
</div>
All I need to do is verify the text "Successfully created application" exists. I do not need to manipulate anything.
I'm not sure what language you are doing, but basically, you need to get the text in the containing div.
So, for example,
driver.findElement(By.cssSelector(".alert-box.notice")).getText()
After some discussion with my peers and much online research, here is the solution I found.
At first I tried capturing the text based on Nathan's suggestion, but decided to store the results as a string.
String happy = driver.findElement(By.className("alert-box notice")).getText();
assertEquals(true, happy.contains("Successfully"));
The problem with this is that I kept getting errors such as, "org.openqa.selenium.InvalidSelectorException: The given selector alert-box notice is either invalid or does not result in a WebElement. The following error occurred:
InvalidSelectorError: Compound class names not permitted"
Since I have no control over the class name, I went the xpath route as follows:
String happy = driver.findElement(By.xpath("html/body/div/div[2]/div/div/div/div[3]/div")).getText();
assertEquals(true, happy.contains("Successfully"));
This version runs correctly and I am able to verify the alert message.

rails 4.1 undefined method for nil class

Hi I am trying to show the current users friend list / or the friends that might be pending, but i got an error like this one
NoMethodError in UserFriendships#index
undefined method `each' for nil:NilClass
this is what is was showing to give out the error
<% #user_friendships.each do |friendship| %>
This is my code in the controller
before_filter :authenticate_user!
def index
#user_friendship = current_user.user_friendships.all
end
this is my code in the index
<% #user_friendships.each do |friendship| %>
<% friend = friendship.friend %>
<div id="<%= dom_id(friendship) %>" class="friend now">
<div class="span1">
<%= link_to image_tag(friend.gravatar_url), profile_path(friend) %>
</div>
</div>
</div>
<% end %>
I have already defined the #user_friendship in my controller but it seems that its not working properly I am a bit new here and getting things together, but this error keeps me from going forward, if anybody can help me that would be great!
Rails cannot see your defined method user_friendships on current_user, hence #user_friendship is nill.
For your use, you would need to only call id directly on current_user, like
#user_id = current_user.id
Then, you can search the database for the User with this particular id
#current_user = User.find(#user_id)
So, you can get any method this new #current_user, in your case;
def index
#user_friendship = #current_user.user_friendships.all
end
And proceed with the list
<% #user_friendships.each do |friendship| %>
Rails is an MVC framework, meaning Models, Views, and Controllers. The Models primarily, enables communication between the database (like MYSql) and the controllers. Views are basically what the users see (like HTML, CSS), they communicate and grasp needed data through the Controller. And the Controller does the most work. The Controller takes in requests from the user, points the request through a model to the database, and returns the result to the view. All these are done by the Controller with the help of the server. For further explanations on Rails MVC framework and MVC generally, please checkout these links
How are Model, View and Controller connected?
What is MVC in Ruby on Rails?
http://betterexplained.com/articles/intermediate-rails-understanding-models-views-and-controllers/
http://www.codelearn.org/ruby-on-rails-tutorial/mvc-in-rails
http://blog.codinghorror.com/understanding-model-view-controller/

Error: ngRepeat:dupes Duplicate Key in Repeater

I have a column(I call it in my codebehind as keyW) in a stored procedure that returns this value
[{key:138},{key:139},{key:140},{key:141},{key:142},{key:143},{key:145},{key:146},{key:148}]
on my design view I have put the code like this
<div id="allerg" ng-repeat="allerg in recipe.keyW">
{{allerg.key}}
</div>
When I run my page it returns the duplicate key error. I am not sure what is wrong. I am returning the right values as what I have read in the ng-repeat documentation
thank you in advance
EDIT: I have also tried the track by $index. It removes the error but still doesn't display the values.
Try changing your div ID to something other than allerg
If your array contains int add "track by $index" to your code.
<div id="allerg" ng-repeat="allerg in recipe.keyW track by $index">
{{allerg.key}}
</div>

Object reference not set while SQL manager says it is

Lately I have run in a strange NullReferenceException. It pops up only occasionally why it is so hard to debug it for me. Today it happened again and I want to fix it now I have the error.
I have the following setup:
An asp.net view with relevant code:
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<WerkStageNu.Profiles>" %>
<%# Import Namespace="WerkStageNu.Helpers" %>
<div class="listing">
<div class="content">
<h3><%=Html.ActionLink(Model.Persons.UserName, "Details", new { id = Model.ID } )%></h3>
And when running this it tells me that Model.Persons is null giving the following error, while the Model itself is loaded with the data from the (SQL) Database. I am using ADO.net entities. Retrieving the profile instead of using the model resulted in the same error.
<%=Html.ActionLink(WerkStageNu.Models.Repository.Instance.GetProfileByID(Model.ID)
.Persons.UserName, "Details", new { id = Model.ID } )%>
Did not do any good.
Some error images:
debug mode http://www.bastijn.nl/zooi/model_persons.png
stack trace http://www.bastijn.nl/zooi/stacktrace.png
So far it seems a normal error, but when I checked my DB behind the request I found that this field is filled in and that the link is correct. SQL manager screens to show this information:
Profiles table:
profiles DB http://www.bastijn.nl/zooi/profiles_sql.png
Persons table:
persons DB http://www.bastijn.nl/zooi/persons_sql.png
As one can see all the PersonIDs are set so normally all the links should be loaded? Sometimes this is the case, but sometimes however this nullreference pops up from out of nowhere. Am I forgetting something? Should I manually load something?
//edit
I notice
<% Model.PersonsReference.Load(); Model.EmploymentsReference.Load(); %>
Fixes this problem, the question is why I need it here and not throughout the rest of my views using the same approach?
It could be related to lazy loading the Persons collection.
I notice
<% Model.PersonsReference.Load(); Model.EmploymentsReference.Load(); %>
Fixes this problem, the question is why I need it here and not throughout the rest of my views using the same approach?

Resources