Wednesday, 11 September 2013

Rails ActiveRecord object not saving

Rails ActiveRecord object not saving

I have this table that stores serialized objects:
class CachedObject < ActiveRecord::Base
attr_accessible :key, :data
validates_uniqueness_of :key
end
The data column stores a serialized object indexed by key. Pretty simple.
I'm running this code to test:
key = "test"
obj = {"test" => "test"}
row = CachedObject.find_or_create_by_key key
row.data = obj.to_json
row.save
The object is getting created, but it's not saving back to the database.
No error messages. What am I doing wrong here?

Meteor integration with external services

Meteor integration with external services

This may seem like a very basic question. I need my small Meteor app to
integrate with an external service. Specifically ZeroRPC -
http://zerorpc.dotcloud.com/
Here's some example ZeroRPC client code.
Are there any potential issues with this and Is there a preferred way to
do this?
var zerorpc = require("zerorpc");
var client = new zerorpc.Client();
client.connect("tcp://127.0.0.1:4242");
client.invoke("hello", "RPC", function(error, res, more) {
console.log(res);
});

Case within Case statement

Case within Case statement

I have to get an instructor approval date from a table called section. If
that table doesn't have the date (null), then I have to get a date from
offering table, and even if that table doesn't have what I am looking for,
then from Term table.
How do I create a case statement to handle that?
so far here's what I have:
SELECT @dInstructApprDate = case when a.InstructorApprovalDate is null
then
select @dInstructApprDate = instructorapprovaldate from
SSS_OfferingAcademicPeriods where
SSS_OfferingRegPeriods.SSS_OfferingsID = @lSSS_OfferingsID
I am not sure why it doesn't like me using select statement within "THEN"
Any help would be appreciated.

Invalid attempt to read data when no data is present

Invalid attempt to read data when no data is present

I have a Sql Dbase in C#[built before i got to my present job,creator is
gone], and it was fine until last week. On the first page
clerk_search.aspx it searches SQL for people and posts back to a datagrid
thats fine. There is a ASP Image button thats clicked on and it goes
forward to the next page, to enter the reason the for the customers visit
with loaded fields about the customer that post back. For some persons the
next page populates, for others it does not. The SQL statement used checks
out fine in query analyzer, i dont understand. I dont think its the reader
because others are logged in fine, and the other customers are present in
the rows in SQL and can be queried just fine. All is posted below, I am
not savvy with coding, please assist.
`System.InvalidOperationException: Invalid attempt to read when no data
is present.
Line 40: SqlDataReader reader2 = cmd.ExecuteReader();
Line 41: reader2.Read();
Line 42: LblLName.Text = "" + reader2["LAST_NAME"];
Line 43: LblFName.Text = "" + reader2["FIRST_NAME"];
Source File: "....clerk_create.aspx.cs" Line: 42
[InvalidOperationException: Invalid attempt to read when no data is
present.]
System.Data.SqlClient.SqlDataReader.GetValue(Int32 i) +118
System.Data.SqlClient.SqlDataReader.get_Item(String name) +27
clerk_create.Page_Load(Object sender, EventArgs e)
in "c:......\clerk_create.aspx.cs:42
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o,
Object t,
EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender,
EventArgs e)
+35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean
includeStagesAfterAsyncPoint) +627
Here is the actual: ....clerk_create.aspx.cs
public partial class clerk_create : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Cookies["us"] == null)
{
Response.Write("Sorry, you do not have access to this page.
Please see
data systems.");
Response.End();
}
if (!IsPostBack)
{
using (SqlConnection connection = new SqlConnection
(WebConfigurationManager.ConnectionStrings["walkin2"].ConnectionString))
{
TextBox txtsct =
(TextBox)Page.PreviousPage.FindControl("Txtsct");
Txtsct.Text = txtsct.Text;
TextBox txt =
(TextBox)Page.PreviousPage.FindControl("Txtssn");
Txtssn.Text = "" + txt.Text;
connection.Open();
string strsql2 = "SELECT dbo.table_name.SSN,
dbo.table_name.LAST_NAME,
dbo.table_name.FIRST_NAME, dbo.table_name.MIDDLE_INITIAL,
dbo.table_name.COMPONENT_CODE, dbo.table_name.PRESENT_CODE
FROM
dbo.table_name INNER JOIN dbo.table_name ON
dbo.table_name.SSN = '" +
Txtssn.Text + "')";
SqlCommand cmd = new SqlCommand(strsql2, connection);
SqlDataReader reader2 = cmd.ExecuteReader();
reader2.Read();
LblLName.Text = "" + reader2["LAST_NAME"];
LblFName.Text = "" + reader2["FIRST_NAME"];
`

How to do an HTML select form where the selected option update a JSON value?

How to do an HTML select form where the selected option update a JSON value?

I currently have one HTML+JS webpage where I hard code the starting
condition (the West, North, East, South geographic coordinate of a
country) :
var WNES = { "W": 67.0, "N":37.5, "E": 99.0, "S": 5.0, "item":"India" };
I however just datamined data for ~180 countries, so I also have :
var WSEN_list = [
{"W":60.504050405040545;"S":29.306134923492337;"E":75.1575157515752;"N":38.47551472547255;"item":"Afghanistan"},
{"W":11.611161116111646;"S":-17.94743030603061;"E":24.068406840684105;"N":-4.453854347434742;"item":"Angola"},
{"W":19.279927992799315;"S":39.62168720072006;"E":21.00810081008106;"N":42.67814713471347;"item":"Albania"},
{...}
];
I want my end-user to pick a country using a html <select> element :
<form>
Select your country:
<select id="mySelect">
<option>Afghanistan</option>
<option>Albania</option>
<option>Angola</option>
</select>
</form>
then, to store the user's selected item value (by exemple "Angola"), and
state :
var WNES =
{"W":11.611161116111646;"S":-17.94743030603061;"E":24.068406840684105;"N":-4.453854347434742;"item":"Angola"};
How to do a such select button and system which update my WNES from the
WSEN_list ?

Can't get link_to_unless_current to work

Can't get link_to_unless_current to work

After someone pointed link_to_unless_current out to me, I would like to
apply it to my dashboard sidebar. However, I can't get it to work, so I'm
guessing I'm doing something wrong.
This is my current sidebar
.dashboard_bar
%ul
= link_to admin_dashboard_path do
%li.icon-dashboard
= link_to admin_cs_dashboard_path do
%li.icon-heart
= link_to admin_dashboard_path do
%li.icon-money
= link_to admin_dashboard_path do
%li.icon-group
= link_to admin_dashboard_path do
%li.icon-bug
= link_to admin_dashboard_path do
%li.icon-hdd
When I change link_to to link_to_unless_current, it just screws up my css
and the icons are no longer clickable.
Can someone enlighten me on how to fix it?

Tuesday, 10 September 2013

Access 2010 - How would you pass the returned result from an if statement to set field criteria that contains logical operators

Access 2010 - How would you pass the returned result from an if statement
to set field criteria that contains logical operators

Im looking to set field criteria with an if statement but the result of
the if statement will contain a logical opertor.
eg
If([Code]="PEN", "GENR", "GENR OR GENR-R")
The result is that for a given row the expression would set the criteria
to GENR if column Code = PEN and if Code <> PEN then the criteria would be
GENR OR GENR-R
Your help is greatly appreciated. thanks