Search Results

Search found 7116 results on 285 pages for 'nested queries'.

Page 5/285 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Nested attributes in the index view?

    - by user283179
    I seem to be getting error: uninitialized constant Style::Pic when I'm trying to render a nested object in to the index view the show view is fine. class Style < ActiveRecord::Base #belongs_to :users has_many :style_images, :dependent => :destroy accepts_nested_attributes_for :style_images, :reject_if => proc { |a| a.all? { |k, v| v.blank?} } #found this here http://ryandaigle.com/articles/2009/2/1/what-s-new-in-edge-rails-nested-attributes has_one :cover, :class_name => "Pic", :order => "updated_at DESC" accepts_nested_attributes_for :cover end class StyleImage < ActiveRecord::Base belongs_to :style #belongs_to :style_as_cover, :class_name => "Style", :foreign_key => "style_id" has_attached_file :pic, :styles => { :small => "200x0>", :normal => "600x> " } validates_attachment_presence :pic #validates_attachment_size :pic, :less_than => 5.megabytes end <% for style_image in @style.style_images %> <li><%= style_image.caption %></li> <div id="show_photo"> <%= image_tag style_image.pic.url(:normal) %></div> <% end %> As you can see from the above The main model style has many style_images, all these style_images are displayed in the show view but, in the the index view I wish to show one image which has been name and will act as a cover that is displayed for each style. in the index controller I have tried the following: class StylesController < ApplicationController layout "mini" def index @styles = Style.find(:all, :inculde => [:cover,]).reverse respond_to do |format| format.html # index.html.erb format.xml { render :xml => @styles } end end and the index <% @styles.each do |style| %> <%=image_tag style.cover.pic.url(:small) %> <% end %> class StyleImage < ActiveRecord::Base belongs_to :style #belongs_to :style_as_cover, :class_name => "Style", :foreign_key => "style_id" has_attached_file :pic, :styles => { :small => "200x0>", :normal => "600x> " } validates_attachment_presence :pic #validates_attachment_size :pic, :less_than => 5.megabytes end In the style_images table there is an cover_id also. From the about you can see that I have included the cover in the controller and the model. I have know idea where I'm going wrong here! If any one can help please do!

    Read the article

  • Nested Threads?

    - by Olaseni
    What are the rules regarding spawning new threads within other running threads? I have a C# app that handles two basic threads in the background. I recently introduced some heavy duty IO stuff, and I was thinking of setting them off inside threads. Are threads nested within themselves cool?

    Read the article

  • jQuery nested sortables jumpy behaviour

    - by sebbie
    I want to allow user to drag and drop UI elements. I've 'container' and 'control', control may be in container, containers may include other containers (this is important requirement). I created simple prototype using jQuery. HTML: <div class="one"> <div class="control">Control 1</div> <div class="control">Control 2</div> <div class="control container"> Container drag area <div class="control">Subcontrol 1</div> <div class="control">Subcontrol 2</div> <div class="control">Subcontrol 3</div> <div class="control">Subcontrol 4</div> <div class="control">Subcontrol 5</div> <div class="control">Subcontrol 6</div> <div class="control">Subcontrol 7</div> <div class="control">Subcontrol 8</div> <div class="control">Subcontrol 9</div> </div> <div class="control">Control 3</div> Then I created sortables using jQueryUI: $('.one').sortable({ items: 'div.control', placeholder: 'placeholder', forcePlaceholderSize: true }); Now when I'm trying to drag "Subcontrol 8" and place it between "Subcontrol 2" and "Subcontrol 3" for example I'm getting jumpy effect, you can observe it here: http://jsbin.com/egipu4/2 Interesting thing is - when I remove ability to drag "container" then it becomes smooth and perfect (you can see this on jsbin example below "jumpy" example, you can't drag using "Container drag area" span). I tried different "nested" plugins and techniques, google'd for a long time and the only one that worked was on this page: (StackOverflow doesn't allow me to post more than one like, google for "Brian Swartzfager's Blog: Nested List Sort Demo" should be first, sorry!) But it does work great only in jQuery1.2 and very old jQueryUI. If I include latest jQuery (1.3/1.4) and UI (1.7/1.8) it gets jumpy as well. What am I doing wrong?

    Read the article

  • Python - Nested List to Tab Delimited File?

    - by Seafoid
    Hi, I have a nested list comprising ~30,000 sub-lists, each with three entries, e.g., nested_list = [['x', 'y', 'z'], ['a', 'b', 'c']]. I wish to create a function in order to output this data construct into a tab delimited format, e.g., x y z a b c Any help greatly appreciated! Thanks in advance, Seafoid.

    Read the article

  • More nest Python nested dictionaries.

    - by clutch
    After reading http://stackoverflow.com/questions/635483/what-is-the-best-way-to-implement-nested-dictionaries-in-python why is it wrong to do: c = collections.defaultdict(collections.defaultdict(int)) in python? I would think this would work to produce {key:{key:1}} or am I thinking about it wrong?

    Read the article

  • Breaking out of a nested loop

    - by dotnetdev
    If I have a for loop which is nested within another, how can I efficiently come out of both loops (inner and outer) in the quickest possible way? I don't want to have to use a boolean and then have to say go to another method, but rather just to execute the first line of code after the outer loop. What is a quick and nice way of going about this? Thanks

    Read the article

  • Mounting a Nested SSH Location

    - by Brandon Pelfrey
    I have a server that is only SSH-accessible to machines within a network and my only access to that network from the outside world is a single publicly-SSH-accessible node. Is there some way that I can mount the nested machine from the outside? Me - Public SSH-accessible Node - Internal SSH-accessible Machine Thanks!

    Read the article

  • Catching an exception that is nested into another exception

    - by Bernhard V
    Hi, I want to catch an exception, that is nested into another exception. I'm doing it currently this way: } catch (RemoteAccessException e) { if (e != null && e.getCause() != null && e.getCause().getCause() != null) { MyException etrp = (MyException) e.getCause().getCause(); ... } else { throw new IllegalStateException("Error at calling service 'beitragskontonrVerwalten'"); } } Is there a way to do this more efficient and elegant?

    Read the article

  • Using nested classes for constants?

    - by antirysm
    What's wrong with using nested classes to group constants? Like so: public static class Constants { public static class CategoryA { public const string ValueX = "CatA_X"; public const string ValueY = "CatA_Y"; } public static class CategoryB { public const string ValueX = "CatB_X"; public const string ValueY = "CatB_Y"; } } Used like so: Console.WriteLine(Constants.CategoryA.ValueY); Console.WriteLine(Constants.CategoryB.ValueX); You could also make the "Constants"-class partial...

    Read the article

  • Validate number of nested attributes

    - by Damien MATHIEU
    Hello, I have a model with nested attributes : class Foo < ActiveRecord::Base has_many :bar accepts_nested_attributes_for :bar end It works fine. However I'd want to be sure that for every Foo, I have at least two Bar. I can't access the bar_attributes in my validations so it seems I can't validate it. Is there any clean way to do so ?

    Read the article

  • Rails nested form for belongs_to

    - by user1232533
    I'm new to rails and have some troubles with creating a nested form. My models: class User < ActiveRecord::Base belongs_to :company accepts_nested_attributes_for :company, :reject_if => :all_blank end class Company < ActiveRecord::Base has_many :users end Now i would like to create a new company from the user sign_up page (i use Devise btw) by given only a company name. And have a relation between the new User and new Company. In the console i can create a company for a existing User like this: @company = User.first.build_company(:name => "name of company") @company.save That works, but i can't make this happen for a new user, in my new user sign_up form i tried this (i know its wrong by creating a new User fist but im trying to get something working here..): <%= simple_form_for(resource, :as => resource_name, :html => { :class => 'form-horizontal' }, :url => registration_path(resource_name)) do |f| %> <%= f.error_notification %> <div class="inputs"> <% @user = User.new company = @user.build_company() %> <% f.fields_for company do |builder| %> <%= builder.input :name, :required => true, :autofocus => true %> <% end %> <%= f.input :email, :required => true, :autofocus => true %> <%= f.input :password, :required => true %> <%= f.input :password_confirmation, :required => true %> </div> <div class="form-actions"> <%= f.button :submit, :class => 'btn-primary', :value => 'Sign up' %> </div> I did my best to google for a solution/ example.. found some nested form examples but it's just not clear to me how to do this. Really hope somebody can help me with this. Any help on this would be appreciated. Thanks in advance! Greets, Daniel

    Read the article

  • How to make a nested query with an Entity that doesn't really exist (many-to-many)

    - by Calou
    Hi everyone, I'm new with Doctrine2 so my question can be easy to answer (I hope so). First of all, here the SQL query that I'd want : SELECT * FROM Document WHERE id NOT IN (SELECT document_id FROM Documents_Folders) Pretty simple isn't it ? The porblem is that my table 'Documents_Folders' is not an entity. In fact, it was create because I have a many-to-many relation between my entities 'Document' and 'Folder'. I tried several queries, but none worked. Thanks.

    Read the article

  • SQL SERVER – Identify Most Resource Intensive Queries – SQL in Sixty Seconds #028 – Video

    - by pinaldave
    During performance tuning conversation the very first question people often ask is what are the queries offending the server or in another word let us identify the queries which are the most resource intensive. The resources are often described as either Memory, CPU or IO. When we talk about the queries the same is applicable for them as well. The query which is doing lots of reads or writes are for sure resource intensive as well query which are taking maximum CPU time. Performance tuning is a very deep subject and we all have our own preference regarding what should be the first step to tuning and what should be looked with the salt of grain. Though there is no denying that a query which uses more resources than what it should be using for sure require tuning. There are many ways to do identify query using intense resources (e.g. Extended events etc) but in this one we will go by simple DMV. There is a small gotcha we all have to remember about usage of DMV is that it only brings back results from existing cache. So if you have a query which is very resource intensive but is not cached or if you have explicitly removed the query from the cache it will be not part of the result returned by this DMV. It is quite possible that a query is aged and removed from the cache if your cache is not huge. If your cache is large you may want to be careful in running this query during business hours as this query itself can be resource intensive. Get Script to identify resource intensive query from Here Related Tips in SQL in Sixty Seconds: SQL SERVER – Find Most Expensive Queries Using DMV Simple Example to Configure Resource Governor – Introduction to Resource Governor SQL SERVER – DMV – sys.dm_exec_query_optimizer_info – Statistics of Optimizer SQL SERVER – Wait Stats – Wait Types – Wait Queues – Day 0 of 28 Reference: Pinal Dave (http://blog.sqlauthority.com) Filed under: Database, Pinal Dave, PostADay, SQL, SQL Authority, SQL in Sixty Seconds, SQL Query, SQL Scripts, SQL Server, SQL Server Management Studio, SQL Tips and Tricks, T SQL, Technology, Video Tagged: Excel

    Read the article

  • C# - How to store and reuse queries

    - by Jason Holland
    I'm learning C# by programming a real monstrosity of an application for personal use. Part of my application uses several SPARQL queries like so: const string ArtistByRdfsLabel = @" PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT DISTINCT ?artist WHERE {{ {{ ?artist rdf:type <http://dbpedia.org/ontology/MusicalArtist> . ?artist rdfs:label ?rdfsLabel . }} UNION {{ ?artist rdf:type <http://dbpedia.org/ontology/Band> . ?artist rdfs:label ?rdfsLabel . }} FILTER ( str(?rdfsLabel) = '{0}' ) }}"; string Query = String.Format(ArtistByRdfsLabel, Artist); I don't like the idea of keeping all these queries in the same class that I'm using them in so I thought I would just move them into their own dedicated class to remove clutter in my RestClient class. I'm used to working with SQL Server and just wrapping every query in a stored procedure but since this is not SQL Server I'm scratching my head on what would be the best for these SPARQL queries. Are there any better approaches to storing these queries using any special C# language features (or general, non C# specific, approaches) that I may not already know about?

    Read the article

  • Using Queries with Coherence Read-Through Caches

    - by jpurdy
    Applications that rely on partial caches of databases, and use read-through to maintain those caches, have some trade-offs if queries are required. Coherence does not support push-down queries, so queries will apply only to data that currently exists in the cache. This is technically consistent with "read committed" semantics, but the potential absence of data may make the results so unintuitive as to be useless for most use cases (depending on how much of the database is held in cache). Alternatively, the application itself may manually "push down" queries to the database, either retrieving results equivalent to querying the cache directly, or may query the database for a key set and read the values from the cache (relying on read-through to handle any missing values). Obviously, if the result set is too large, reading through the cache may cause significant thrashing. It's also worth pointing out that if the cache is asynchronously synchronized with the database (perhaps via database change listener), that an application may commit a transaction to the database, then generate a key set from the database via a query, then read cache entries through the cache, possibly resulting in a race condition where the application sees older data than it had previously committed. In theory this is not problematic but in practice it is very unintuitive. For this reason it often makes sense to invalidate the cache when updating the database, forcing the next read-through to update the cache.

    Read the article

  • python union of 2 nested lists with index

    - by sbas
    I want to get the union of 2 nested lists plus an index to the common values. I have two lists like A = [[1,2,3],[4,5,6],[7,8,9]] and B = [[1,2,3,4],[3,3,5,7]] but the length of each list is about 100 000. To A belongs an index vector with len(A): I = [2,3,4] What I want is to find all sublists in B where the first 3 elements are equal to a sublist in A. In this example I want to get B[0] returned ([1,2,3,4]) because its first three elements are equal to A[0]. In addition, I also want the index to A[0] in this example, that is I[0]. I tried different things, but nothing worked so far :( First I tried this: Common = [] for i in range(len(B)): if B[i][:3] in A: id = [I[x] for x,y in enumerate(A) if y == B[i][:3]][0] ctdCommon.append([int(id)] + B[i]) But that takes ages, or never finishes Then I transformed A and B into sets and took the union from both, which was very quick, but then I don't know how to get the corresponding indices Does anyone have an idea?

    Read the article

  • nested for loop

    - by Gary
    Hello, Just learning Python and trying to do a nested for loop. What I'd like to do in the end is place a bunch of email addresses in a file and have this script find the info, like the sending IP of mail ID. For now i'm testing it on my /var/log/auth.log file Here is my code so far: #!/usr/bin/python # this section puts emails from file(SpamEmail) in to a array(array) in_file = open("testFile", "r") array = in_file.readlines() in_file.close() # this section opens and reads the target file, in this case 'auth.log' log = open("/var/log/auth.log", "r") auth = log.readlines() for email in array: print "Searching for " +email, for line in auth: if line.find(email) > -1: about = line.split() print about[0], print Inside 'testfile' I have the word 'disconnect' cause I know it's in the auth.log file. It just doesn't find the word 'disconnect'. In the line of "if line.find(email) -1:" i can replace email and put "disconnect" the scripts finds it fine. Any idea? Thanks in advance. Gary

    Read the article

  • Return pointer to nested inner class from generic outer class

    - by helixed
    I'm new to C++, so bear with me. I have a generic class called A. A has a nested class called B. A contains a method called getB(), which is supposed to return a new instance of B. However, I can't get my code to compile. Here's what it looks like:#include A.h template <class E> class A { public: class B { public: int data; }; B * getB(); }; A.cpp #include "A.h" template <class E> A<E>::B * A::getB() { return new B(); } When I try to compile this, I get the following error: error: expected constructor, destructor, or type conversion before '*' token Does anybody know what I'm doing wrong? Thanks, helixed

    Read the article

  • Nasty deep nested loop in Rails

    - by CalebHC
    I have this nested loop that goes 4 levels deep to find all the image widgets and calculate their sizes. This seems really inefficient and nasty! I have thought of putting the organization_id in the widget model so I could just call something like organization.widgets.(named_scope), but I feel like that's a bad short cut. Is there a better way? Thanks class Organization < ActiveRecord::Base ... def get_image_widget_total total_size = 0 self.trips.each do |t| t.phases.each do |phase| phase.pages.each do |page| page.widgets.each do |widget| if widget.widget_type == Widget::IMAGE total_size += widget.image_file_size end end end end end return total_size end ... end

    Read the article

  • Ruby on Rails - nested attributes: How do I access the parent model from child model

    - by TMaYaD
    I have a couple of models like so class Bill < ActiveRecord::Base has_many :bill_items belongs_to :store accepts_nested_attributes_for :bill_items end class BillItem <ActiveRecord::Base belongs_to :product belongs_to :bill validate :has_enough_stock def has_enough_stock stock_available = Inventory.product_is(self.product).store_is(self.bill.store).one.quantity errors.add(:quantity, "only #{stock_available} is available") if stock_available < self.quantity end end The above validation so obviously doesn't work because when I'm reading the bill_items from nested attributes inside the bill form, the attributes bill_item.bill_id or bill_item.bill are not available before being saved. So how do I go about doing something like that?

    Read the article

  • wpf: design time error while writing Nested type in xaml

    - by viky
    I have created a usercontrol which accept type of enum and assign the values of that enum to a ComboBox control in that usercontrol. Very Simple. I am using this user control in DataTemplates. Problem comes when there comes nested type. I assign that using this notation EnumType="{x:Type myNamespace:ParentType + NestedType}" It works fine at runtime. but at design time it throws error saying Could not create an instance of type 'TypeExtension' Why? Due to this I am not able to see my window at design time. Any help?

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >