Submit a form with Mechanize and Rails - ruby-on-rails

I'm trying to estimate the cost of the shipment from the shipping company page.
The problem is that I don't know what I'm doing wrong.
This is my approach:
mechanize = Mechanize.new
page = mechanize.get('http://www.chilexpress.cl/cotizador-envios-de-encomiendas-tarifas')
origen = page.at("#ddlOrigenCotizacion")
destino = page.at("#ddlDestinoCotizacion")
producto = page.at("#ddlProductoCotizacion")
link = page.at("#btnSig")
largo = page.at("#txtLargo")
ancho = page.at("#txtAncho")
alto = page.at("#txtAlto")
peso = page.at("#txtPeso")
origen['value'] = 'AHOS'
destino['value'] = 'AHOS'
producto['value'] = '3'
largo['value'] = '5'
alto['value'] = '5'
ancho['value'] = '5'
peso['value'] = '2'
puts mechanize.click(link).uri
puts '---------'
But is not working, mechanize.click(link).uri return the same page that page.uri
Also I tried page.form_with(:id => 'formPrincipal') approach, but i was not able to get the form inputs.

Related

Django Admin Change Form : How To avoid using __str__ in header of Django Admin Change Form?

Hi does anyone know if it is possible to avoid Django rendering str for model when in the change admin form? My str method has multiple attributes rendered as shown below:
class Product(models.Model):
"""
Product
"""
id = models.PositiveBigIntegerField(primary_key=True)
attributes = models.JSONField()
labels = models.JSONField()
name = models.TextField()
relative_url = models.TextField(max_length=250)
image = models.URLField()
delivery = models.TextField(max_length=50)
online = models.BooleanField()
is_customizable = models.BooleanField()
is_exclusive = models.BooleanField()
url = models.URLField()
max_price = models.PositiveIntegerField()
min_price = models.PositiveIntegerField()
currency = models.ForeignKey(Currency, on_delete=models.CASCADE)
discount_percentage = models.PositiveSmallIntegerField(default=0)
recommended_retail_price = models.PositiveIntegerField()
def __str__(self) -> str:
product_str = (
f"id: {self.id}\n"
f"attributes: {self.attributes}\n"
f"labels: {self.labels}\n"
f"name: {self.name}\n"
f"relative_url: {self.relative_url}\n"
f"image: {self.image}\n"
f"delivery: {self.delivery}\n"
f"online: {self.online}\n"
f"is_customizable: {self.is_customizable}\n"
f"is_exclusive: {self.is_exclusive}\n"
f"url: {self.url}\n"
f"max_price: {self.max_price}\n"
f"min_price: {self.min_price}\n"
f"currency: {self.currency}\n"
f"discount_percentage: {self.discount_percentage}\n"
f"recommended_retail_price: {self.recommended_retail_price}\n"
)
return product_str

rake db:seed_fu not populating database

I'm using the seed-fu gem and am able to get 2 files to seed the db successfully. The following file, while it produces output in the terminal, isn't populating the db:
# residents.rb
Resident.seed do |r|
r.account_id = 1
r.employee_id = 1
r.first_name = "solomon"
r.last_name = "gibsom"
r.gender = "Male"
r.dob = Date.parse("1937-02-20")
r.case_number = "H-3827-JKZ-0329"
r.veteran_status_number = "G-15 classified"
r.marital_status = "Married"
r.arrival_date = Date.today
r.religious_preferences = "None"
r.insurance_info = "Medicaid"
r.burial_provisions = "Cremation"
r.admission_weight = "121 lbs"
r.admission_height = "5ft 9in"
r.allergies = "Corn, wheat and peanut allergies"
end
Address.seed do |r|
r.account_id = 1
r.employee_id = 1
r.resident_id = 1
r.street_address = "55298 solomon hills blvd"
r.city = "Flint"
r.state = "MI"
r.zip = "48289"
end
PrimaryPhone.seed do |r|
r.account_id = 1
r.employee_id = 1
r.resident_id = 1
r.area_code = "810"
r.number = "565-0255"
end
Terminal output:
The output looks good so I check for the records in the console:
I'm sort of at a loss on where further to look to check for errors.
Here are two files that work as expected:
#accounts.rb
Account.seed do |a|
a.facility_name = "Chuck Norris AFC"
end
#admins.rb
Employee.seed do |a|
a.account_id = 1
a.is_admin = true
a.first_name = "kenneth"
a.last_name = "the paige"
a.email = "test#example.com"
a.password = "12345678"
a.password_confirmation = "12345678"
a.dob = Date.parse("1965-05-05")
a.gender = "Male"
end
Address.seed do |address|
address.account_id = 1
address.employee_id = 1
address.street_address = "123 Chuckleburger dr."
address.city = "New York"
address.state = "NY"
address.zip = "00001"
end
some background:
I'm using seed-fu ~>2.3,
residents.rb lives inside of db/fixtures/, and the rails version is 4.2
Thank you in advance for having a look!
Pay attention to the SQL queries printed in the console when you run Resident.all: they have condition WHERE resident.account_id is NULL. But in seeds file Resident has account_id = 1.
You might've set default_scope for Resident model. Try running Resident.unscoped.all or remove the default scope.

IE11 clears password fields on page refresh:

Happens only in IE (Chrome and Firefox, no issues... go figure)
I have a page where customer's can update their details (name, address,password etc.) and everything is working fine, however if the customer submits the form (which also works fine) and then presses the back button all the customer's information will repopulate the form except for the password field.
My boss would like this to repopulate as well, like it does in Chrome and Firefox, but IE won't do it. I'm hoping it's something simple I've missed but I can't see it. I've tried adjusting the lines where the text fields are populated to match the rest of the form, but that just results in empty fields. Code below.
Page_Load
If TypeOf Session("Customer") Is GPCUser Then
c = CType(Session("Customer"), GPCUser)
Else
Response.Redirect("default.aspx")
End If
If Not Page.IsPostBack Then
If c.CustomerID > 0 Then
'populate the table
lblAccountName.Text = c.AccountName
txtFirstName.Text = c.FirstName
txtLastName.Text = c.LastName
txtEmail.Text = c.Email
txtAddress.Text = c.Address
txtSuburb.Text = c.Suburb
txtCityTown.Text = c.City
txtPostcode.Text = c.PostCode
txtPhone.Text = c.Phone
txtMobile.Text = c.Mobile
'chkNewsletter.checked = c.Newsletter
txtPassword.Attributes.Add("value", c.GeneratedPassword)
txtConfirmPassword.Attributes.Add("value", c.GeneratedPassword)
'txtPassword.Text = c.GeneratedPassword
'txtConfirmPassword.Text = c.GeneratedPassword
Dim subscriptions As ContactSubscriptions = New ContactSubscriptions(c.CustomerID)
chkGenernalNewsletters.Checked = subscriptions.IsGenernalNewsletters
End If
Else
End If
Update Button
If TypeOf Session("Customer") Is GPCUser Then
c = CType(Session("Customer"), GPCUser)
Else
Exit Sub
End If
c.AccountName = lblAccountName.Text
c.FirstName = txtFirstName.Text
c.LastName = txtLastName.Text
c.Email = txtEmail.Text
c.Address = txtAddress.Text
c.Suburb = txtSuburb.Text
c.City = txtCityTown.Text
c.PostCode = txtPostcode.Text
c.Phone = txtPhone.Text
c.Mobile = txtMobile.Text
'c.Newsletter = chkNewsletter.Checked
c.GeneratedPassword = txtPassword.Text
c.CustomerUpdatedRequired = false
'Update password field
txtPassword.Attributes.Add("value", c.GeneratedPassword)
txtConfirmPassword.Attributes.Add("value", c.GeneratedPassword)
GPCUser.AddUpdateCustomer(c)
subscriptions.IsGenernalNewsletters = chkGenernalNewsletters.Checked
subscriptions.Save()
Session("Customer") = c
lblMessage.Text = "Your details have been successfully updated."
pnlUpdateAccount.Visible = False

rally_api query for getting defects based on iteration

I am using rally_api gem in Ruby. Could any one suggest me how to write query that gets all the defects under a particular iteration?
require 'rally_api'
headers = RallyAPI::CustomHttpHeader.new()
headers.version = "1.0"
config = {:base_url => "https://rally1.rallydev.com/slm"}
config[:username] = "mvcmxb"
config[:password] = "kjkjk"
config[:workspace] = "Persons"
config[:project] = "Business he does"
config[:headers] = headers
#rally = RallyAPI::RallyRestJson.new(config)
test_query = RallyAPI::RallyQuery.new()
test_query.type = "defect"
test_query.fetch = true
results = #rally.find(test_query)
Here is a code example when defects are queried by iteration and their description is updated. You may either query by iteration name:
query.query_string = "(Iteration.Name = \"i10\")"
or iteration ref:
query.query_string="(Iteration = /iteration/13589769934)"
Names are not unique, but the query is also bound by the project:
rally = RallyAPI::RallyRestJson.new(config)
query = RallyAPI::RallyQuery.new()
query.type = :defect
query.fetch = "Name,FormattedID,Iteration,Description"
query.project = {"_ref" => "https://rally1.rallydev.com/slm/webservice/v2.0/project/12352608219.js" }
query.project_scope_up = false
query.project_scope_down = false
query.order = "Name Asc"
#query.query_string = "(Iteration.Name = \"i10\")"
query.query_string="(Iteration = /iteration/13589769934)"
results = rally.find(query)
results.each do |d|
puts "FormattedID: #{d["FormattedID"]}, Iteration: #{d["Iteration"]["Name"]}"
d.read
fieldUpdates = { "Description" => "bad defect"}
d.update(fieldUpdates)
end

Wrong Number of Arguments

I understand what causes the wrong number of arguments error but my code doesn't pass any parameters to initialize any of the classes so I'm not sure at all why my code is giving me this error. I'm also pretty new to Ruby on Rails so that doesn't help things. My code is below:
def create_google_file
#products = Product.find(:all)
file = File.new('dir.xml','w')
doc = REXML::Document.new
root = REXML::Element.new "rss"
root.add_attribute("xmlns:g", "http://base.google.com/ns/1.0")
root.add_attribute("version", "2.0")
channel = REXML::Element.new "channel"
root.add_element channel
title = REXML::Element.new "title"
title.text = "Sample Google Base"
channel.add_element title
link = REXML::Element.new "link"
link.text = "http://base.google.com/base/"
channel.add_element link
description = REXML::Element.new "description"
description.text = "Information about products"
channel.add_element description
#products.each do |y|
item = channel.add_element("item")
id = item.add_element("g:id")
id.text = y.id
title = item.add_element("title")
title.text = y.title
description = item.add_element("description")
description.text = y.description
googlecategory = item.add_element("g:google_product_category")
googlecategory.text = y.googlecategory
producttype = item.add_element("g:product_type")
producttype.text = y.producttype
link = item.add_element("link")
link.text = y.link
imglink = item.add_element("g:image_link")
imglink.text = y.imglink
condition = item.add_element("condition")
condition.text = y.condition
availability = item.add_element("g:availability")
availability.text = y.availability
price = item.add_element("g:price")
price.text = y.price "USD"
gtin = item.add_element("g:gtin")
gtin.text = y.gtin
brand = item.add_element("g:brand")
brand.text = y.brand
mpn = item.add_element("g:mpn")
mpn.text = y.mpn
expirationdate = item.add_element("g:expiration_date")
expirationdate.text = y.salepricedate
end
doc.add_element root
file.puts doc
file.close
end
The error I'm getting is:
ArgumentError in ProductsController#create_google_file
wrong number of arguments (1 for 0)
At the request of the poster, I am putting my comments in to an answer:
Based purely on the consistency of the other lines, but without knowing which line is actually failing, it may be this part: price.text = y.price "USD". Is y.price a method that takes in a parameter? Is it defined as def price(type) or something? If not, if it doesn't take any parameters, then it's because you're not supposed to send any parameters to that method. It looks like it's just a getter.
#FranklinJosephMoormann As I suspected, that's the line. Were you trying to make a string like "4.50 USD"? Then you probably wanted: price.text = "#{y.price} USD". That will take the result of y.price and put it in a string, and allow you to keep typing more in the string. It's called string interpolation.

Resources