Search Results

Search found 8634 results on 346 pages for 'base'.

Page 89/346 | < Previous Page | 85 86 87 88 89 90 91 92 93 94 95 96  | Next Page >

  • Rails - using :include to find objects based on their child's attributes

    - by adam
    I have a sentence and correction model class Sentence < ActiveRecord::Base has_one :correction class Correction < ActiveRecord::Base belongs_to :sentence and I'm trying find all sentences which don't have a correction. To do this I'm simply looking for corrections which don't exist i.e. whose id = nil. But it is failing and i can't figure out why Sentence.find :all, :include => :correction, :conditions => {:correction => {:id => nil}} Perhaps its the syntax or maybe just the overall approach. Can anyone help?

    Read the article

  • Magento - Using alternative "reviews count" on category list page

    - by Sam
    Hi All I noticed that on the category list page, the number of reviews (pulled from frontend/base/default/template/review/helper/summary_short.phtml) lists the full amount of reviews for an item, not the amount available to the store view you’re on. So, for example (using the sample data) the Samsung MM-A900M Ace has 5 reviews - however, when you click that link and are taken to the reviews page, it actually just has 2 (as only 2 are available to the English view). But on the reviews page, the review count is correct and says 2 reviews (this time pulled from frontend/base/default/template/review/product/view/count.phtml). Is there any way to use this review count on the category list?

    Read the article

  • How to override virtual function in good style? [C++]

    - by Knowing me knowing you
    Hi, guys I know this question is very basic but I've met in few publications (websites, books) different style of override virtual function. What I mean is: if I have base class: class Base { public: virtual void f() = 0; }; in some publications I saw that to override this some authors would just say: void f(); and some would still repeat the virtual keyword before void. Which form of overwriting is in good style? Thank you for your answers.

    Read the article

  • Ruby on Rails: create records for multiple models with one form and one submit

    - by notblakeshelton
    I have a 3 models: quote, customer, and item. Each quote has one customer and one item. I would like to create a new quote, a new customer, and a new item in their respective tables when I press the submit button. I have looked at other questions and railscasts and either they don't work for my situation or I don't know how to implement them. I also want my index page to be the page where I can create everything. quote.rb class Quote < ActiveRecord::Base attr_accessible :quote_number has_one :customer has_one :item end customer.rb class Customer < ActiveRecord::Base #unsure of what to put here #a customer can have multiple quotes, so would i use: has_many :quotes #<----? end item.rb class Item < ActiveRecord::Base #also unsure about this #each item can also be in multiple quotes quotes_controller.rb class QuotesController < ApplicationController def index @quote = Quote.new @customer = Customer.new @item = item.new end def create @quote = Quote.new(params[:quote]) @quote.save @customer = Customer.new(params[:customer]) @customer.save @item = Item.new(params[:item]) @item.save end end items_controller.rb class ItemsController < ApplicationController def index end def new @item = Item.new end def create @item = Item.new(params[:item]) @item.save end end customers_controller.rb class CustomersController < ApplicationController def index end def new @customer = Customer.new end def create @customer = Customer.new(params[:customer]) @customer.save end end quotes/index.html.erb <%= form_for @quote do |f| %> <%= f.fields_for @customer do |builder| %> <%= label_tag :firstname %> <%= builder.text_field :firstname %> <%= label_tag :lastname %> <%= builder.text_field :lastname %> <% end %> <%= f.fields_for @item do |builder| %> <%= label_tag :name %> <%= builder.text_field :name %> <%= label_tag :description %> <%= builder.text_field :description %> <% end %> <%= label_tag :quote_number %> <%= f.text_field :quote_number %> <%= f.submit %> <% end %> When I try submitting that I get an error: Can't mass-assign protected attributes: item, customer So to try and fix it I updated the attr_accessible in quote.rb to include :item, :customer but then I get this error: Item(#) expected, got ActiveSupport::HashWithIndifferentAccess(#) Any help would be greatly appreciated.

    Read the article

  • C++ Iterators and inheritance

    - by jomnis
    Have a quick question about what would be the best way to implement iterators in the following: Say I have a templated base class 'List' and two subclasses "ListImpl1" and "ListImpl2". The basic requirement of the base class is to be iterable i.e. I can do: for(List<T>::iterator it = list->begin(); it != list->end(); it++){ ... } I also want to allow iterator addition e.g.: for(List<T>::iterator it = list->begin()+5; it != list->end(); it++){ ... } So the problem is that the implementation of the iterator for ListImpl1 will be different to that for ListImpl2. I got around this by using a wrapper ListIterator containing a pointer to a ListIteratorImpl with subclasses ListIteratorImpl2 and ListIteratorImpl2, but it's all getting pretty messy, especially when you need to implement operator+ in the ListIterator. Any thoughts on a better design to get around these issues?

    Read the article

  • Rails: validate presence of parent_id in has_many association

    - by deb
    I have a projects resource that has many tasks. I want to ensure that every task has a project_id by adding validates_presence_of :project_id to the tasks model. However, when creating a new project with tasks, the project_id won't be available until the record saves, therefore I can't use validates_presence_of :project_id. So my question is, how do I validate presence of project_id in the task model? I want to ensure every task has a parent. ... class Project < ActiveRecord::Base has_many :tasks, :dependent => :destroy accepts_nested_attributes_for :tasks, :allow_destroy => true ... class Task < ActiveRecord::Base belongs_to :project validates_presence_of :project_id

    Read the article

  • PHP - turning register globals off, what is the best way to go about fixing the code?

    - by user187809
    I am working on a old code base, where programmers assumed that register_globals will always be on. Hence variables are used without $_GET or $_POST prefix, pretty much in every page (the code base is huge, hundreds of scripts). I tried turning it off, but the very first script (login script) goes on an infinite loop. I understand that going through one script at a time, and one line at a time and fixing the variables is probably the only option (adding the prefix $_GET or $_POST as the case may be). Has anyone does this before? How did you go about doing it? Any advice?

    Read the article

  • How do you pass self to class_eval in ruby?

    - by klochner
    I'm working on a metaprogramming task, where I'm trying to use a single method to define a polymorphic association in the calling class, while also defining the association in the target class. I need to pass in the name of the calling class to get the association right. Here's a snippet that should get the idea across: class SomeClass < ActiveRecord::Base has_many :join_models, :dependent=:destroy end class JoinModel < ActiveRecord::Base belongs_to :some_class belongs_to :entity, :polymorphic=true end module Foo module ClassMethods def acts_as_entity has_many :join_models, :as=:entity, :dependent=:destroy has_many :some_classes, :through=:join_models klass = self.name.tableize SomeClass.class_eval "has_many :#{klass}, :through=:join_models" end end end I'd like to eliminate the klass= line, but don't know how else to pass a reference to self from the calling class into class_eval. any suggestions?

    Read the article

  • rails: Get a list of items tagged x AND y AND z

    - by egarcia
    I've got two models: item and tags. Both have a name attribute. I want to find items tagged with several tags. class Item < ActiveRecord::Base has_many :tags validates_presence_of :name end class Tag < ActiveRecord::Base belongs_to :item validates_presence_of :name end Given a list of tag ids, I can easily enough get the list of items tagged with one tag or the other: # Find the items tagged with one or more of the tags on tag_ids Item.all(:conditions => ['tags.id in (?)', tag_ids], :joins => :tags) If tag_ids is {1,4}, then I get all pictures tagged with 1, or 4, or both. I want to know now how to get the pictures that are tagged with both - 1 AND 4. I can't even imagine the SQL that is needed here.

    Read the article

  • Multiple inclusion of header file c++

    - by iSight
    Hi, I have a problem regarding multiple inclusion of header file in C++ code. say for example, i have three class X,Y,Z. X and Y are derived from Base class Z. And i want to create an instance of X in Y. The code will go like this. class Z{some code} class X:public Z{some code};//here #include header of class Z added class Y:public Z //here #include header of class Z added as well as of X class {private: X* mX;//instance of X some code}; So in this multiple definition of all methods of base class arises. how can i cope with this problem

    Read the article

  • Ruby on rails edit form for has_one relation

    - by user2900873
    I have a clan.rb and clan_options.rb clan.rb class Clan < ActiveRecord::Base has_one :options, :class_name => "ClanOptions", :foreign_key => "clan_id", dependent: :destroy end clan_options.rb class ClanOptions < ActiveRecord::Base belongs_to :clan end To create an edit form for clan.rb I use the following: <%= form_for @clan, :html => {:class => 'form-horizontal'} do |clan| %> <fieldset> <!-- form stuff --> </fieldset> <% end %> It works how I want. But now I want to create an edit form for the clan_options.rb, I have no idea how to do this. If anymore information is needed to solve this, ask me.

    Read the article

  • Rails: Modeling an optional relation in ActiveRecord

    - by Hassinus
    I would like to map a relation between two Rails models, where one side can be optionnal. Let's me be more precise... I have two models: Profile that stores user profile information (name, age,...) and User model that stores user access to the application (email, password,...). To give you more information, User model is handled by Devise gem for signup/signin. Here is the scenario of my app: 1/ When a user register, a new row is created in User table and there is an equivalent in Profile table. This leads to the following script: class User < ActiveRecord::Base belongs_to :profile end 2/ A user can create it's profile without registering (kind of public profile with public information), so a row in Profile doesn't have necessarily a User row equivalent (here is the optional relation, the 0..1 relation in UML). Question: What is the corresponding script to put in class Profile < AR::Base to map optionally with User? Thanks in advance.

    Read the article

  • Mapping to a different view based on child type

    - by Ryan Burnham
    So i have a situation where i have common base type but i need to map to a different view based on the child type. It looks like i can use a generic mapping class to handle the inheritance http://geekswithblogs.net/nharrison/archive/2010/07/09/inheriting-a-class-map-in-fluent-nhibernate.aspx But how can i conditionally map to a different view based on the child type? I see an EntityType property but it says its obsolete and will be made private in the next version. As an example i have a base class of ContactInfo is standard between contact types but the values come from different places depending on the contact type, this I'll handle through the sql view.

    Read the article

  • C# Different class objects in one list

    - by jeah_wicer
    I have looked around some now to find a solution to this problem. I found several ways that could solve it but to be honest I didn't realize which of the ways that would be considered the "right" C# or OOP way of solving it. My goal is not only to solve the problems but also to develop a good set of code standards and I'm fairly sure there's a standard way to handle this problem. Let's say I have 2 types of printer hardwares with their respective classes and ways of communicating: PrinterType1, PrinterType2. I would also like to be able to later on add another type if neccessary. One step up in abstraction those have much in common. It should be possible to send a string to each one of them as an example. They both have variables in common and variables unique to each class. (One for instance communicates via COM-port and has such an object, while the other one communicates via TCP and has such an object). I would however like to just implement a List of all those printers and be able to go through the list and perform things as "Send(string message)" on all Printers regardless of type. I would also like to access variables like "PrinterList[0].Name" that are the same for both objects, however I would also at some places like to access data that is specific to the object itself (For instance in the settings window of the application where the COM-port name is set for one object and the IP/port number for another). So, in short something like: In common: Name Send() Specific to PrinterType1: Port Specific to PrinterType2: IP And I wish to, for instance, do Send() on all objects regardless of type and the number of objects present. I've read about polymorphism, Generics, interfaces and such, but I would like to know how this, in my eyes basic, problem typically would be dealt with in C# (and/or OOP in general). I actually did try to make a base class, but it didn't quite seem right to me. For instance I have no use of a "string Send(string Message)" function in the base class itself. So why would I define one there that needs to be overridden in the derived classes when I would never use the function in the base class ever in the first place? I'm really thankful for any answers. People around here seem very knowledgeable and this place has provided me with many solutions earlier. Now I finally have an account to answer and vote with too. EDIT: To additionally explain, I would also like to be able to access the objects of the actual printertype. For instance the Port variable in PrinterType1 which is a SerialPort object. I would like to access it like: PrinterList[0].Port.Open() and have access to the full range of functionality of the underlaying port. At the same time I would like to call generic functions that work in the same way for the different objects (but with different implementations): foreach (printer in Printers) printer.Send(message)

    Read the article

  • How to make dll referenced by ActiveX component accessible?

    - by sherpa
    I have an ActiveX component developed in C#. I'm referencing a dll which comes with other native dlls and it is loading them on the fly expecting them to be in the same folder (probably using Assembly.GetExecutingAssembly().Location but not sure, I don't have control over them). There is also one ini file which is also expected to be in the same folder. When I run the application as Windows form app, everything is fine, of course. But the trouble comes when I run it within Internet Explorer as the base directory is at the location of iexplore.exe. Obviously neither the dlls or the ini file can be found and many temporary working files outputted by the dlls are located in Internet Explorer folder. The workaround is to copy all ddls and ini file into the ie folder but that is not something I'd be happy about. What is the proper solution to this? Can I somehow set the base path for the ActiveX component?

    Read the article

  • enable_shared_from_this and inheritance

    - by DeadMG
    I've got a type which inherits from enable_shared_from_this<type>, and another type that inherits from this type. Now I can't use the shared_from_this method because it returns the base type and in a specific derived class method I need the derived type. Is it valid to just construct a shared_ptr from this directly? Edit: In a related question, how can I move from an rvalue of type shared_ptr<base> to a type of shared_ptr<derived>? I used dynamic_cast to verify that it really was the correct type, but now I can't seem to accomplish the actual move.

    Read the article

  • How to overwrite virtual fnc in good style? [C++]

    - by atch
    Hi, guys I know this question is very basic but I've met in few publications (websites, books) different style of overwriting virtual function. What I mean is: if I have base class: class Base { public: virtual void f() = 0; }; in some publications I saw that to overwrite this some authors would just say: void f(); and some would still repeat the virtual keyword before void. Which form of overwriting is in good style? Thank you for your answers.

    Read the article

  • Perform SilkTest actions on an Eclipse that's always already open?

    - by Tom
    I want to be able to recognize the Eclipse window, which is always already open, so I won't ever need to open it with SilkTest. Is there a way that I can set the base state to be a window that's always going to be open? It seems the way to set the base state also designates the executable for it to open. The executable won't necessarily always be in the same location, and it would be a pain to configure that. Is this possible? I've already tried desktop.<Window>find("//Window[@caption='Java EE*']");, which doesn't work.

    Read the article

  • Filtering SQLAlchemy query on attribute_mapped_collection field of relationship

    - by bsa
    I have two classes, Tag and Hardware, defined with a simple parent-child relationship (see the full definition at the end). Now I want to filter a query on Tag using the version field in Hardware through an attribute_mapped_collection, eg: def get_tags(order_code=None, hardware_filters=None): session = Session() query = session.query(Tag) if order_code: query = query.filter(Tag.order_code == order_code) if hardware_filters: for k, v in hardware_filters.iteritems(): query = query.filter(getattr(Tag.hardware, k).version == v) return query.all() But I get: AttributeError: Neither 'InstrumentedAttribute' object nor 'Comparator' object associated with Tag.hardware has an attribute 'baseband The same thing happens if I strip it back by hard-coding the attribute, eg: query.filter(Tag.hardware.baseband.version == v) I can do it this way: query = query.filter(Tag.hardware.any(artefact=k, version=v)) But why can't I filter directly through the attribute? Class definitions class Tag(Base): __tablename__ = 'tag' tag_id = Column(Integer, primary_key=True) order_code = Column(String, nullable=False) version = Column(String, nullable=False) status = Column(String, nullable=False) comments = Column(String) hardware = relationship( "Hardware", backref="tag", collection_class=attribute_mapped_collection('artefact'), ) __table_args__ = ( UniqueConstraint('order_code', 'version'), ) class Hardware(Base): __tablename__ = 'hardware' hardware_id = Column(Integer, primary_key=True) tag_id = Column(String, ForeignKey('tag.tag_id')) product_id = Column(String, nullable=True) artefact = Column(String, nullable=False) version = Column(String, nullable=False)

    Read the article

  • Destructors for C++ Interface-like classes

    - by sdg
    Starting to use PC-Lint on an existing code base (fear and trepidation). One thing that it complains about is the following: class IBatch { public: virtual void StartBatch() =0; virtual int CommitBatch() =0; }; Which when another class derives from this to use it like an interface base class 'IBatch' has no destructor So, the question: when you create Interface classes like the above, do you always include a virtual destructor? Why? (is it a style or a coding error?)

    Read the article

  • Why does gcc warn about incompatible struct assignment with a `self = [super initDesignatedInit];' c

    - by gavinbeatty
    I have the following base/derived class setup in Objective-C: @interface ASCIICodeBase : NSObject { @protected char code_[4]; } - (Base *)initWithASCIICode:(const char *)code; @end @implementation ASCIICodeBase - (ASCIICodeBase *)initWithCode:(const char *)code len:(size_t)len { if (len == 0 || len > 3) { return nil; } if (self = [super init]) { memset(code_, 0, 4); strncpy(code_, code, 3); } return self; } @end @interface CountryCode : ASCIICodeBase - (CountryCode *)initWithCode:(const char *)code; @end @implementation CountryCode - (CountryCode *)initWithCode:(const char *)code { size_t len = strlen(code); if (len != 2) { return nil; } self = [super initWithCode:code len:len]; // here return self; } @end On the line marked "here", I get the following gcc warning: warning: incompatible Objective-C types assigning 'struct ASCIICodeBase *', expected 'struct CurrencyCode *' Is there something wrong with this code or should I have the ASCIICodeBase return id? Or maybe use a cast on the "here" line?

    Read the article

  • Calculating color shades

    - by matejv
    I have the next problem. I have a base color with couple of different shades of that color. Example: Base color: #4085c5 Shade: #005cb1 Now, I have a different color (let's say #d60620), but no shades of it. From the color I would like to calculate shades, that have similar difference as colors mentioned in first paragraph. First I tried calculating difference of RGB elements and applying them to second color, but the result was not like I expected to be. Than I tried with converting color to HSV, reading saturation value and applying the difference to second color, but again the resulting color was still weird. The formula was something like: (HSV(BaseColor)[S] - HSV(Shade)[S]) + HSV(SecondColor)[H] Does anyone know how this problem could be solved? I know I am doing something wrong, but I don't know what. :)

    Read the article

  • PHP install sqlite3 extension

    - by Kevin
    We are using PHP 5.3.6 here, but we used the --without-sqlite3 command when compiling PHP. (It stands in the 'Configure Command' column). But, it is very risky to recompile PHP on that server; there are many visitors. How can we install/use sqlite3? Regards, Kevin [EDIT] yum repolist gives: Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirror.nl.leaseweb.net * extras: mirror.nl.leaseweb.net * updates: mirror.nl.leaseweb.net repo id repo name status base CentOS-5 - Base 3,566 extras CentOS-5 - Extras 237 updates CentOS-5 - Updates 376 repolist: 4,179 rpm -qa | grep php gives: php-pdo-5.3.6-1.w5 php-mysql-5.3.6-1.w5 psa-php5-configurator-1.5.3-cos5.build95101022.10 php-mbstring-5.3.6-1.w5 php-imap-5.3.6-1.w5 php-cli-5.3.6-1.w5 php-gd-5.3.6-1.w5 php-5.3.6-1.w5 php-common-5.3.6-1.w5 php-xml-5.3.6-1.w5 php -i | grep sqlite gives: PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/sqlite3.so' - /usr/lib64/php/modules/sqlite3.so: cannot open shared object file: No such file or directory in Unknown on line 0 Configure Command => './configure' '--build=x86_64-redhat-linux-gnu' '--host=x86_64-redhat-linux-gnu' '--target=x86_64-redhat-linux-gnu' '--program-prefix=' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib64' '--libexecdir=/usr/libexec' '--localstatedir=/var' '--sharedstatedir=/usr/com' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--cache-file=../config.cache' '--with-libdir=lib64' '--with-config-file-path=/etc' '--with-config-file-scan-dir=/etc/php.d' '--disable-debug' '--with-pic' '--disable-rpath' '--without-pear' '--with-bz2' '--with-exec-dir=/usr/bin' '--with-freetype-dir=/usr' '--with-png-dir=/usr' '--with-xpm-dir=/usr' '--enable-gd-native-ttf' '--without-gdbm' '--with-gettext' '--with-gmp' '--with-iconv' '--with-jpeg-dir=/usr' '--with-openssl' '--with-pcre-regex=/usr' '--with-zlib' '--with-layout=GNU' '--enable-exif' '--enable-ftp' '--enable-magic-quotes' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-sysvmsg' '--with-kerberos' '--enable-ucd-snmp-hack' '--enable-shmop' '--enable-calendar' '--without-mime-magic' '--without-sqlite' '--without-sqlite3' '--with-libxml-dir=/usr' '--enable-xml' '--with-system-tzdata' '--enable-force-cgi-redirect' '--enable-pcntl' '--with-imap=shared' '--with-imap-ssl' '--enable-mbstring=shared' '--enable-mbregex' '--with-gd=shared' '--enable-bcmath=shared' '--enable-dba=shared' '--with-db4=/usr' '--with-xmlrpc=shared' '--with-ldap=shared' '--with-ldap-sasl' '--with-mysql=shared,/usr' '--with-mysqli=shared,/usr/bin/mysql_config' '--enable-dom=shared' '--with-pgsql=shared' '--enable-wddx=shared' '--with-snmp=shared,/usr' '--enable-soap=shared' '--with-xsl=shared,/usr' '--enable-xmlreader=shared' '--enable-xmlwriter=shared' '--with-curl=shared,/usr' '--enable-fastcgi' '--enable-pdo=shared' '--with-pdo-odbc=shared,unixODBC,/usr' '--with-pdo-mysql=shared,/usr' '--with-pdo-pgsql=shared,/usr' '--with-pdo-sqlite=shared,/usr' '--with-pdo-dblib=shared,/usr' '--enable-json=shared' '--enable-zip=shared' '--with-readline' '--with-pspell=shared' '--enable-phar=shared' '--with-mcrypt=shared,/usr' '--with-tidy=shared,/usr' '--with-mssql=shared,/usr' '--enable-sysvmsg=shared' '--enable-sysvshm=shared' '--enable-sysvsem=shared' '--enable-posix=shared' '--with-unixODBC=shared,/usr' '--enable-fileinfo=shared' '--enable-intl=shared' '--with-icu-dir=/usr' '--with-recode=shared,/usr' /etc/php.d/pdo_sqlite.ini, /etc/php.d/sqlite3.ini, PHP Warning: Unknown: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Berlin' for 'CET/1.0/no DST' instead in Unknown on line 0 PDO drivers => mysql, sqlite pdo_sqlite PWD => /root/sqlite _SERVER["PWD"] => /root/sqlite _ENV["PWD"] => /root/sqlite

    Read the article

  • CVE-2006-3744 Multiple Integer overflow vulnerabilities in ImageMagick

    - by chandan
    CVE DescriptionCVSSv2 Base ScoreComponentProduct and Resolution CVE-2006-3744 Numeric Errors vulnerability 5.1 ImageMagick Solaris 10 SPARC: 136882-03 X86: 136883-03 This notification describes vulnerabilities fixed in third-party components that are included in Sun's product distribution.Information about vulnerabilities affecting Oracle Sun products can be found on Oracle Critical Patch Updates and Security Alerts page.

    Read the article

< Previous Page | 85 86 87 88 89 90 91 92 93 94 95 96  | Next Page >