{"QuestionId": 9410414, "AnswerCount": 1, "Tags": "", "CreationDate": "2012-02-23T09:38:47.513", "AcceptedAnswerId": "9410640", "Title": "Rails: Forum has_many topics, saving the association?", "Body": "

I might be going about this the wrong way in the first place, so I will give a bit of background first.

\n\n

As you can tell from the title, I am building a forum from scratch. I thought it was working correctly; however, I am a bit unsure as to how to update/save the forum object from within the topics \"create\" method in it's controller.

\n\n

What I tried to do:\nIn the \"New\" method, I sent the Forum's id via the routing. So on the new-topic page has a address that looks like this: \"localhost:3000/new-topic/1\". The one being the Forum's id. In the method itself, I try to attach it to the new topic object.

\n\n
@topic = Topic.new\n@topic.forum = Forum.find(params[:id])\n
\n\n

My create method then tries to use that forum.

\n\n
@topic = Topic.new(params[:topic])\n@topic.forum.topics << @topic #Simplified down.\nif @topic.save\n  @topic.forum.save\n...\n
\n\n

I get the feeling that I am going about this the wrong way. I was looking at someone's tutorial and they got the forum by calling params[:forum_id] but they didn't show they routing they did to achieve that.

\n\n

How do I do this correctly and/or what is the correct way to route all of this? For the record, I do plan on using this same method for the Topic => Post association. Thanks for any help.

\n", "Lable": "No"} {"QuestionId": 9490260, "AnswerCount": 1, "Tags": "", "CreationDate": "2012-02-28T21:48:00.390", "AcceptedAnswerId": "9575650", "Title": "Pass JSON data from a .NET WebHandler to redraw Pie Highcharts with new series data", "Body": "

I want to create a page displaying a default pie chart and a few buttons. When the user clicks on the buttons, the page will get new JSON data from a WebHandler and redraw the chart. I'm using .net 2.0, C#, web forms.

\n\n

I have this WebHandler json.ashx generating the JSON:

\n\n
public void ProcessRequest (HttpContext context) {        \n    String data = String.Empty;\n    data += \"[{\\\"Male\\\": 80.0}, {\\\"Female\\\": 20.0}]\";\n    context.Response.ContentType = \"application/json\";\n    context.Response.Write(data);\n}\n
\n\n

Here is my script on the aspx page:

\n\n
    var chart = null;\n\n    $(document).ready(function () {\n\n        var options = {\n            chart: {\n                renderTo: 'container',\n                defaultSeriesType: 'pie'\n            },\n            tooltip: {\n                formatter: function () {\n                    return '<b>' + this.point.name + '</b>: ' + this.y + ' (' + this.percentage + '%)';\n                }\n            },\n            plotOptions: {\n                pie: {\n                    allowPointSelect: true,\n                    cursor: 'pointer',\n                    dataLabels: {\n                        enabled: true,\n                        color: '#000000',\n                        connectorColor: '#000000',\n                        formatter: function () {\n                            return '<b>' + this.point.name + '</b>: ' + this.y + ' (' + this.percentage + '%)';\n                        }\n                    }\n                }\n            },\n            series: [{\n                data: [['Yes', 60], ['No', 40]]\n            }]\n\n        };\n\n        var chart = new Highcharts.Chart(options);\n\n\n        $(\"#Gender\").click(function () {\n            $.get('json.ashx', function (data) {\n                options.series = data;\n                var chart = new Highcharts.chart(options);\n            });\n        });\n\n    });\n
\n\n

when I click on the Gender button, it does not generate the new chart. How do I properly parse the JSON data and feed it to the series.data of the new pie chart?

\n", "Lable": "No"} {"QuestionId": 9519546, "AnswerCount": 1, "Tags": "<.net>", "CreationDate": "2012-03-01T16:02:27.417", "AcceptedAnswerId": "11615051", "Title": ".NET C# - Passing parent controls to a pagination .ascx control?", "Body": "

On a project I'm working on, I have many <asp:ListView> controls, which are paginated using <asp:DataPager> controls. Instead of copying and pasting the controls to each .aspx page where I have a paginated list, would it be possible to break out the <asp:DataPager> controls into a reusable/modular .ascx control and create a field on it to pass in the PagedControlID?

\n\n

I've tried this in the past but couldn't not seem to target the PagedControlID in the Parent page.

\n\n

Here's what I've got so far. Any help would be much appreciated.

\n\n

.aspx Page

\n\n
<abc:Pagination ID=\"uxPagination\" ListControlID=\"uxEventListView\" runat=\"server\" />\n
\n\n

.ascx Pagination Control

\n\n
<asp:DataPager ID=\"uxDataPager\" PageSize=\"1\" runat=\"server\" />\n
\n\n

.ascx.cs Pagination Control

\n\n
public partial class ABC_UserControls_Pagination : System.Web.UI.UserControl\n{\n    private string listControlID;\n\n    public string ListControlID\n    {\n        get { return listControlID; }\n        set { listControlID = value; }\n    }\n\n    protected void Page_Load(object sender, EventArgs e)\n    {\n        if (!string.IsNullOrEmpty(ListControlID))\n        {\n            uxDataPager.PagedControlID = ListControlID;\n        }\n    }\n}\n
\n", "Lable": "No"} {"QuestionId": 9604589, "AnswerCount": 2, "Tags": "", "CreationDate": "2012-03-07T15:46:18.340", "AcceptedAnswerId": "9604661", "Title": "Run PHP CLI from Windows Powershell ISE", "Body": "

This question is regarding dollar signs \"$\" $ in Windows PowerShell ISE.

\n\n

I have PHP CLI and want to run one liner command scripts from the prompt in Windows PowerShell ISE.

\n\n

php -r \"$foo = 'foo';\"

\n\n

Just returns Parse error: parse error in Command line code on line 1 and I've narrowed it down to the pesky dollar sign which is significant in PowerShell. Can I escape it somehow?

\n\n

I also tried

\n\n

php -r '$foo = \"foo\";'

\n\n

and get

\n\n

Notice: Use of undefined constant foo - assumed 'foo' in Command line code on line 1

\n", "Lable": "No"} {"QuestionId": 9917131, "AnswerCount": 2, "Tags": "", "CreationDate": "2012-03-28T23:29:56.047", "AcceptedAnswerId": "9917539", "Title": "virtualenv bug?", "Body": "

I am trying to run the following script in my virtualenv:

\n\n
(python2.7.2-gonvaled1)gonvaled@lycaon:~/.virtualenvs/python2.7.2-gonvaled1$ couchy.py\nTraceback (most recent call last):\n  File \"/home/gonvaled/projects/bin/couchy.py\", line 46, in <module>\n    from   couchdb_support           import CouchdbLists\n  File \"/home/gonvaled/projects/test_project/python_modules/couchdb_support.py\", line 3615, in <module>\n    from   asterisk_support          import AsteriskSupport\n  File \"/home/gonvaled/projects/test_project/python_modules/asterisk_support.py\", line 4, in <module>\n    from   starpy_support                   import AmiCommand\n  File \"/home/gonvaled/projects/test_project/python_modules/starpy_support.py\", line 7, in <module>\n    from   starpy                    import manager, fastagi, utilapplication, menu\n  File \"/usr/lib/python2.5/site-packages/starpy/utilapplication.py\", line 2, in <module>\n    from basicproperty import common, propertied, basic, weak\n  File \"/usr/lib/python2.5/site-packages/basicproperty-0.6.12a-py2.5-linux-i686.egg/basicproperty/common.py\", line 159, in <module>\n    from basictypes import datedatetime_types as ddt\n  File \"/usr/lib/python2.5/site-packages/basicproperty-0.6.12a-py2.5-linux-i686.egg/basictypes/datedatetime_types.py\", line 4, in <module>\n    from dateutil import parser \n  File \"/usr/lib/python2.5/site-packages/python_dateutil-2.1-py2.5.egg/dateutil/parser.py\", line 8\n    from __future__ import unicode_literals\nSyntaxError: future feature unicode_literals is not defined\n
\n\n

So somehow python is trying to import from:

\n\n
/usr/lib/python2.5/site-packages/starpy/utilapplication.py\n
\n\n

This does not make any sense. My virtualenv is very clean:

\n\n
(python2.7.2-gonvaled1)gonvaled@lycaon:~/.virtualenvs/python2.7.2-gonvaled1$ python\nPython 2.7.2 (default, Mar 29 2012, 00:31:29) \n[GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu4)] on linux2\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n>>> import sys\n>>> sys.path   \n['', '/home/gonvaled/.virtualenvs/python2.7.2-gonvaled1/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg', '/home/gonvaled/.virtualenvs/python2.7.2-gonvaled1/lib/python2.7/site-packages/pip-1.1-py2.7.egg', '/home/gonvaled/.virtualenvs/python2.7.2-gonvaled1/lib/python2.7/site-packages/Twisted-12.0.0-py2.7-linux-i686.egg', '/home/gonvaled/.virtualenvs/python2.7.2-gonvaled1/lib/python2.7/site-packages/zope.interface-3.8.0-py2.7-linux-i686.egg', '/home/gonvaled/.virtualenvs/python2.7.2-gonvaled1/lib/python2.7/site-packages/basicproperty-0.6.12a-py2.7-linux-i686.egg', '/home/gonvaled/projects/gonvaled_settings', '/home/gonvaled/django_apps', '/home/gonvaled/projects/test_project/ipc', '/home/gonvaled/projects/test_project/python_modules', '/home/gonvaled/projects/test_project/gdata', '/home/gonvaled/projects/callisto/libraries', '/home/gonvaled/.virtualenvs/python2.7.2-gonvaled1', '/home/gonvaled/.virtualenvs/python2.7.2-gonvaled1/lib/python27.zip', '/home/gonvaled/.virtualenvs/python2.7.2-gonvaled1/lib/python2.7', '/home/gonvaled/.virtualenvs/python2.7.2-gonvaled1/lib/python2.7/plat-linux2', '/home/gonvaled/.virtualenvs/python2.7.2-gonvaled1/lib/python2.7/lib-tk', '/home/gonvaled/.virtualenvs/python2.7.2-gonvaled1/lib/python2.7/lib-old', '/home/gonvaled/.virtualenvs/python2.7.2-gonvaled1/lib/python2.7/lib-dynload', '/usr/local/python/2.7.2/lib/python2.7', '/usr/local/python/2.7.2/lib/python2.7/plat-linux2', '/usr/local/python/2.7.2/lib/python2.7/lib-tk', '/home/gonvaled/.virtualenvs/python2.7.2-gonvaled1/lib/python2.7/site-packages']\n
\n\n

And:

\n\n
(python2.7.2-gonvaled1)gonvaled@lycaon:~/.virtualenvs/python2.7.2-gonvaled1$ pip freeze\nCouchDB==0.9dev\nDateUtils==0.5.1\nTwisted==12.0.0\nbasicproperty==0.6.12a\npystache==0.4.0\npython-dateutil==2.1\npytz==2012b\nsimplejson==2.4.0\nsix==1.1.0\nstarpy==1.0.0a12\nwsgiref==0.1.2\nzope.interface==3.8.0\n
\n\n

So to summarize: python is importing from /usr/lib/python2.5/site-packages even though I am inside a virtualenv. How can this be?

\n", "Lable": "No"} {"QuestionId": 10119397, "AnswerCount": 2, "Tags": "", "CreationDate": "2012-04-12T07:38:51.677", "AcceptedAnswerId": "10119466", "Title": "database design with variable columns (mysql)", "Body": "

I am working on a problem where I am trying to figure out the best way to design the Db tables for this. Lets say I have multiple books and each book has variable number of pages in it...I need to track page views for every book

\n\n

e.g. Book 1 = 10 pages , Book 2 = 20 pages, Book 3 and 100 pages and so on \nAs the user views each page in a book, I need to log that information.

\n\n

The motive is to come up with some aggregation numbers on the %views of each book. I should be able to say e.g. \"70% people read Book 1 upto Page 7 and then drop off\"

\n\n

I envision it as

\n\n
book 1 page 1 1000 views\nbook 1 page 2 950 views\nbook 1 page 3 800 views\n.....\n...\nbook 1 page 10 50 views\n
\n\n

and with this I can generate a drilldown report of sorts

\n\n

however, with variable page numbers in each book, what is the best way to store this information?

\n\n

any help would be much appreciated

\n", "Lable": "No"}