Search Results

Search found 1976 results on 80 pages for 'helper'.

Page 44/80 | < Previous Page | 40 41 42 43 44 45 46 47 48 49 50 51  | Next Page >

  • Filter a model's attributes before outputting as json

    - by Jorge Israel Peña
    Hey guys, I need to output my model as json and everything is going fine. However, some of the attributes need to be 'beautified' by filtering them through some helper methods, such as number_to_human_size. How would I go about doing this? In other words, say that I have an attribute named bytes and I want to pass it through number_to_human_size and have that result be output to json. I would also like to 'trim' what gets output as json if that's possible, since I only need some of the attributes. Is this possible? Can someone please give me an example? I would really appreciate it.

    Read the article

  • Unity: How to remove(unregister) registered instance from Unity mapping.

    - by bug0r
    Hello, I meet one problem that i can't solve now. I have the following: UnityHelper.DefaultContainer.RegisterInstance(typeof(IMyInterface), "test", instance); where UnityHelper.DefaultContainer is my helper for getting unity container with loaded configuration. here I registered instance as an instance of IMyInterface. So anywhere(some time after using) I want to remove this mapping. Remove it at all. How I can do it? I have tried UnityHelper.DefaultContainer.Teardown(instance) but is was unsuccessfull and the following code returns instance anyway. UnityHelper.DefaultContainer.ResolveAll() Any ideas? Thank you.

    Read the article

  • Can I override task :environment in test_helper.rb to test rake tasks?

    - by Michael Barton
    I have a series of rake tasks in a Rakefile which I'd like to test as part of my specs etc. Each task is defined in the form: task :do_somthing => :environment do # Do something with the database here end Where the :environment task sets up an ActiveRecord/DataMapper database connection and classes. I'm not using this as part of Rails but I have a series of tests which I like to run as part of BDD. This snippet illustrates how I'm trying to test the rake tasks. def setup @rake = Rake::Application.new Rake.application = @rake load File.dirname(__FILE__) + '/../../tasks/do_something.rake' end should "import data" do @rake["do_something"].invoke assert something_in_the_database end So my request for help - is it possible to over-ride the :environment task in my test_helper.rb file so I my rake testing interacts with the my test database, rather than production? I've tried redefining the task in the helper file, but this doesn't work. Any help for a solution would be great, as I've been stuck on this for the past week.

    Read the article

  • Python dictionary: add or increment entry

    - by cursa
    Hi everyone, I'm currently re-engaging with Python after a long absence and loving it. However, I find myself coming across a pattern over and over. I keep thinking that there must be a better way to express what I want and that I'm probably doing it the wrong way. The code that I'm writing is in the following form: # foo is a dictionary if foo.has_key(bar): foo[bar] += 1 else: foo[bar] = 1 I'm writing this a lot in my programs. My first reaction is to push it out to a helper function, but so often the python libraries supply things like this already. Is there some simple little syntax trick that I'm missing? Or is this the way that it should be done?

    Read the article

  • CakePHP: shortcomings with indirectly associated models

    - by Dan
    I'm having some issues with dealing with indirectly associated models in cakephp. My current model setup is as follows: Deliveries hasOne License License belongsTo Delivery License hasAndBelongsToMany Product (and vice-versa) License hasAndBelongsToMany ProductOption (and vice-versa) I'm trying to save information about ALL of these models inside ONE form. The shortcomings I'm running into are the following: The form helper only seems able to see the field type one level deep. saveAll() only seems able to save records one level deep (for multiple model forms). I'm searching everywhere for the solutions to these issues, but since I'm new to CakePHP, I'm not sure what the newest methods or "correct" methods are for dealing with these issues. Any advice is much appreciated. Thank you all! EDIT: I've posted code to my failed attempt here: http://bin.cakephp.org/saved/58501

    Read the article

  • Flow diagram in html/css

    - by viraptor
    Hi, is there some good way to create a flow / swimline diagram without resorting to scripting or tables? I'm talking about showing different hosts sending packets (so hosts on the X axis, time on the Y and arrows to the destination host). It seems like too much elements for tables (especially the arrows spanning multiple columns either way), but on the other hand, divs would be hard to position in the right place horizontally (they'd have to be basically aligned to a specified "column"). Is there any good way out? Any helper frameworks? (I don't want to do canvas stuff unless really needed)

    Read the article

  • Symfony include_component() with components from a plugin

    - by Chris T
    All I'd like to do is use include_component to call a component from a plugin that I'm developing <?php #/plugins/fooPlugin/modules/barModule/actions/components.class.php class barModuleComponents extends sfComponents{ /** * Constructor */ function __construct(){ } function executeHello(){ } } ?> and <!-- /plugins/fooPlugin/modules/barModule/templates/_hello.php --> <p>HELLO WORLD!</p> But it won't load if I do this in #/apps/frontend/modules/homepage/templates/indexSuccess.php <?php include_component("barModule", "hello"); ?> XDebug gives me: ( ! ) Fatal error: Call to a member function add() on a non-object in C:\Program Files\WaterProof\PHPEdit\3.6.2\Extensions\Symfony\distribution\1.4\lib\helper\PartialHelper.php on line 360

    Read the article

  • How do I stub a view in rspec-2

    - by Trey Bean
    I'm in the process of upgrading an app to Rails 3/Rspec 2. I see that stubbing a view helper method has changed in Rspec 2. It looks like instead of doing template.stub!, we're now supposed to do view.stub!, but I can't seem to get this to work on beta 10. I get an "undefined local variable or method `view' for # < RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1:0x106785fd0" error. I see that in this commit David removed the view method, but I can't figure out what it was replaced with. Something in ActionView::TestCase::Behavior? I'm on rails 3.0.0.beta3. Any idea what I'm missing?

    Read the article

  • Howto add a changed file to an older (not last) commit in Git

    - by David Klein
    Hey, I changed several things over the last hour and committed them step by step. But I just realized I've forgot to add a changed file some commits ago. The Log looks like this: GIT TidyUpRequests u:1 d:0> git log commit fc6734b6351f6c36a587dba6dbd9d5efa30c09ce Author: David Klein <> Date: Tue Apr 27 09:43:55 2010 +0200 The Main program now tests both Webservices at once commit 8a2c6014c2b035e37aebd310a6393a1ecb39f463 Author: David Klein <> Date: Tue Apr 27 09:43:27 2010 +0200 ISBNDBQueryHandler now uses the XPath functions from XPath.fs too commit 06a504e277fd98d97eed4dad22dfa5933d81451f Author: David Klein <> Date: Tue Apr 27 09:30:34 2010 +0200 AmazonQueryHandler now uses the XPath Helper functions defined in XPath.fs commit a0865e28be35a3011d0b6091819ec32922dd2dd8 <--- changed file should go here Author: David Klein <> Date: Tue Apr 27 09:29:53 2010 +0200 Factored out some common XPath Operations Any ideas? :)

    Read the article

  • Python class design - Splitting up big classes into multiple ones to group functionality

    - by Ivo Wetzel
    OK I've got 2 really big classes 1k lines each that I currently have split up into multiple ones. They then get recombined using multiple inheritance. Now I'm wondering, if there is any cleaner/better more pythonic way of doing this. Completely factoring them out would result in endless amounts of self.otherself.do_something calls, which I don't think is the way it should be done. To make things clear here's what it currently looks like: from gui_events import GUIEvents # event handlers from gui_helpers import GUIHelpers # helper methods that don't directly modify the GUI # GUI.py class GUI(gtk.Window, GUIEvents, GUIHelpers): # general stuff here stuff here One problem that is result of this is Pylint complaining giving me trillions of "init not called" / "undefined attribute" / "attribute accessed before definition" warnings.

    Read the article

  • Asp.Net MVC does automatic model validation for DateTime but no others

    - by MattSlay
    I'm using MVC 2 with some Models from a LinqToSql project that I built. I see that when I post back to a Controller Action after editing a form that has a DateTime field from the Model, the MVC Html.ValidationMessageFor() helper will nicely display an error beside the Date text box. This seems to happen automatically when the you test ModelState.IsValid() in the Controller Action, as if the MVC model binding automatically knows that the DateTime field cannot be empty. My question is... I have some other string fields in these LinqToSql generated classes that are Not-Nullable (marked as Not Nullable in Sql Server which passes thourgh to the LinqToSql generated classes), so why doesn't Mr. MVC pick up on those as well and display a "Required" message in the ValidationMessageFor() placeholders I have added for those fields? Sure, I have successfully added the MetadataType(typeof) buddy classes to cover these Non-nullable string fields, but it sure does seem redundant to add all this metadata in buddy classes when the LinqToSql generated classes already contain enough info that MVC could sniff out. It MVC validation works with DateTime automatically, why not these Not-nullable fields too?

    Read the article

  • how to add shopping cart url under top links in magento through customer.xml

    - by Ela
    I tried a lot to add shopping cart url in magento please show me how to add shopping cart url under top links in magento through customer.xml i did in this way. <default> <!-- Mage_Customer --> <reference name="top.links"> <action method="addLink" translate="label title" module="checkout"><label>Shopping Cart</label><url helper="checkout/getShoppingCartUrl"/><title>Shopping Cart</title><prepare/><urlParams/><position>10</position></action> </reference> </default>

    Read the article

  • Rendering a derived partial view with Html.RenderPartial

    - by FreshCode
    Calling Html.RenderPartial("~/Views/Payments/MyControl.ascx"); from a view works if Method.ascx is a control that directly inherits System.Web.Mvc.ViewUserControl. However, if the control inherits a new class that derives from System.Web.Mvc.ViewUserControl, the call to Html.RenderPartial("~/Views/Payments/MyDerivedControl.ascx"); fails, reporting that no such view exists. Example derived ViewUserControl: class MyDerivedControl : System.Web.Mvc.ViewUserControl { public Method() { ViewData["SomeData"] = "test"; } } Is there a workaround, or is there another way I should be doing this? Perhaps an HTML helper?

    Read the article

  • Is there a JS diff library against htmlstring just like google-diff-match-patch on plain text?

    - by Steve
    Currently I am using google-diff-match-patch to implement a real-time editing tool, which can synchronize texts between multiple users. Everything works great when operations are only plain texts, each user's operation(add/delete texts) could be diff-ed out by comparing to old text snapshot with the helper of google-diff. But when rich format texts(like bold/italic) are involved, google-diff not working well when comparing the htmlstring. The occurrence of character of < and > messed up the diff results, especially when bold/italic format are embedded within each other. Could anyone suggest a similar library like google-diff to diff htmlstrings? Or any suggestions can get my problem fixed with google-diff? I understood google-diff is designed for plain text, but really didn't find a better library than it so far, so it also works if a doable enhancement to google-diff can help. Thanks for any comments. Regards, Steve

    Read the article

  • Change the Views location

    - by Vinni
    I am developing a website in MVC 2.0. I want to change the View folder location in my website. I wanted to keep the views folder inside other folders, When I try to do so i am getting following errors The view 'Index' or its master was not found. The following locations were searched: ~/Views/Search/Index.aspx ~/Views/Search/Index.ascx ~/Views/Shared/Index.aspx ~/Views/Shared/Index.ascx Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. My Views folder will be in ~/XYZ/ABC/Views instead of ~/Views. Please solve my problem. Will I get any problems If I change the default Views folder location. Do I need to change anything in HTML Helper classes because I don't know anything in MVC as this is my starting project i dont want to risk..Please help me out...

    Read the article

  • Compare Products Sidebar Item Doesn't Show Products

    - by Ben Gribaudo
    Hello, When I click "Add to Compare" on a product, a message stating that "such-and-such product successfully added to compare list" appears, however the compare products sidebar shows "You have no items to compare." If I do a print_r($this->helper('catalog/product_compare')->getItemCount()) in template/catalog/product/compare/sidebar.phtml, "0" is returned. Why won't the sidebar show the products to compare? Info: Magento version 1.4.0.1 Sessions appear to work for I can add products to the cart and they will stay in the cart as I navigate around the site. Thank you, Ben

    Read the article

  • Emacs Column based Narrowing or Folding

    - by froit
    Is there column based narrowing in emacs. I tend narrow in one everything between script tags but that still keeps the original indent (space before var). It would be great if I could actually column narrow to the the beginning of the indent since otherwise the electrict indent tries to bring it to column 0. var foo = 1; var bar = 2; Alternate solution could be to mark the starting indents as uneditable, but I am also not sure how to do this. P.S. I am aware of MMM and NXHTML and html-helper-modes, but I am not looking to use them due to complexities.

    Read the article

  • Kohana and Javscript path

    - by Leonti
    Hi! I have a following Kohana setup: All my files are placed under 'public_html/koh' My js files are placed under 'public_html/koh/media/js/' I use html::script helper to include those javascript files which generates me following html code: In my js I access one of controllers like 'json/getsomething' (which is http://localhost/koh/json/getsomething). It works OK as long as I'm staying in top of the controller: http://localhost/koh/home When I go to 'http://localhost/koh/home/index' it renders the same page of course but 'json/getsomething' is not accessible from Javascript anymore. How can I solve this problem? Include Javascript using absolute path? Create a variable in js like var fullPath = 'http://localhost/koh/'? What is the best practice to do it? Leonti

    Read the article

  • Creating a function in ruby

    - by Micke
    Hello, i have some problem with creating a function to my Rails app. I want it to work like this: str = "string here" if str.within_range?(3..30) puts "It's withing the range!" end To do that i added this into my application helper: def within_range?(range) if self.is_a?(String) (range).include?(self.size) elsif self.is_a?(Integer) (range).include?(self) end end But i get this error: undefined method `within_range?' for &quot;&quot;:String Do you know what the problem is? and could you please help me. If there is a easier way please say so then. Thanks in advance, Micke.

    Read the article

  • Why array size in llvm created by llvm's internal tools is not good enough for llvm?

    - by vava
    I'm getting strange error message from the following code: ArrayType * arrayType = ArrayType::get(Type::getInt32Ty(ctx), 0); stack = builder->CreateAlloca(arrayType, ConstantArray::get(arrayType, std::vector<Constant *>())); This code compiles fine but it gives me llvm::Value* getAISize(llvm::LLVMContext&, llvm::Value*): Assertion `Amt-getType() == Type::getInt32Ty(Context) && "Malloc/Allocation array size is not a 32-bit integer!"' failed. during execution. What's interesting, is that I never said of what type array size should be, it was created somewhere inside helper functions. So I naturally see no good reason for assert to be there. But I must be doing something wrong anyway, can you help me spot the problem? Thanks in advance. PS. LLVM, as good as it is, lacking documentation tremendously.

    Read the article

  • Dictionary is returning false on ContainsKey after item is added

    - by Karel Frajtak
    I have a dictionary declared as follows IDictionary<string, object> _objectIds = new Dictionary<string, object>(); I was experiencing some problems with it and it discovered that the instance returned false as a result of ContainsKey method and from the watch window I was sure that the item was there. So I created helper method private bool IdsContainsKey(string key) { lock (syncObject) { lock (_objectIds) { if (_objectIds.ContainsKey(key)) return true; // A if (_objectIds.ContainsKey(key)) return true; // B return _objectIds.ContainsKey(key); // C } } } During my debugging session I run into situation when the method exited in place B and sometimes I made to C returning true. Can anybody help me? Thanks.

    Read the article

  • Rails 2.x http basic authentication

    - by randombits
    I'm trying to get basic http authentication working on my Rails app. I'm offering a simple REST interface served by a Rails server, only xml/json output. Every method needs authentication, so I put the authenticate filter in ApplicationController: class ApplicationController < ActionController::Base helper :all # include all helpers, all the time before_filter :authenticate protected def authenticate authenticate_or_request_with_http_basic do |u, p| true end end end Even with having the method return true, I'm receiving a 401 from the server: $ curl http://127.0.0.1:3000/myresource/1.xml -i HTTP/1.1 401 Unauthorized Cache-Control: no-cache WWW-Authenticate: Basic realm="Application" X-Runtime: 1 Content-Type: text/html; charset=utf-8 Content-Length: 27 Server: WEBrick/1.3.1 (Ruby/1.9.1/2010-01-10) Date: Thu, 03 Jun 2010 02:43:55 GMT Connection: Keep-Alive HTTP Basic: Access denied. If I'm explicitly returning true, yet getting served a 401.

    Read the article

  • External config file to be used by multiple DLLs.

    - by vikp
    Hi, I have multiple DLLs that are used to read/write data into my database. There is a presentation layer DLL and a data access layer DLL. I want these DLLs to share a set of the connection strings. My idea is to store the connection string in a seperate DLL in the external configuration file. I'm not sure whether it's a good idea and whether I can reference that external DLL in both presentation and data access layers. The other question is whether I should write a helper class to read the data from the external config file or whether I should be using built in .Net methods? Thank you

    Read the article

  • Handy F# snippets

    - by Benjol
    There are already two questions about F#/functional snippets. However what I'm looking for here are useful snippets, little 'helper' functions that are reusable. Or obscure but nifty patterns that you can never quite remember. Something like: open System.IO let rec visitor dir filter= seq { yield! Directory.GetFiles(dir, filter) for subdir in Directory.GetDirectories(dir) do yield! visitor subdir filter} I'd like to make this a kind of handy reference page. As such there will be no right answer, but hopefully lots of good ones.

    Read the article

  • Rails request forgery protection settings

    - by Vitaly
    Hey, please help a newbie in Rails :) I have protect_from_forgery call (which is given by default) with no attributes in my ApplicationController class. Basically here's the code: class ApplicationController < ActionController::Base helper :all # include all helpers, all the time protect_from_forgery helper_method :current_user_session, :current_user filter_parameter_logging :password, :password_confirmation What I assume it should do is: it should prevent any POST requests without correct authenticity_token. But when I send post request with jQuery like the one below, it works fine (there's update statement that is executed in the database)! $.post($(this).attr("href"), { _method: "PUT", data: { test: true } }); I see in console that there's no authenticity_token among sent parameters, but request is still considered valid. Why is that?

    Read the article

< Previous Page | 40 41 42 43 44 45 46 47 48 49 50 51  | Next Page >