Search Results

Search found 15231 results on 610 pages for 'presentation model'.

Page 82/610 | < Previous Page | 78 79 80 81 82 83 84 85 86 87 88 89  | Next Page >

  • Problems using User model in django unit tests

    - by theycallmemorty
    I have the following django test case that is giving me errors: class MyTesting(unittest.TestCase): def setUp(self): self.u1 = User.objects.create(username='user1') self.up1 = UserProfile.objects.create(user=self.u1) def testA(self): ... def testB(self): ... When I run my tests, testA will pass sucessfully but before testB starts, I get the following error: IntegrityError: column username is not unique It's clear that it is trying to create self.u1 before each test case and finding that it already exists in the Database. How do I get it to properly clean up after each test case so that subsequent cases run correctly?

    Read the article

  • Model callback failure in CakePHP

    - by Benedikt R.
    Hi! Can someone confirm a save process misbehaviour in the AppModel for the method beforeSave( )? This method doesn't seem to be executed before saving a data set. I can remember of reading something about a bug in a current version (btw, I am using 1.3.1). Best regards, Beendikt

    Read the article

  • Nested attributes form for model which belongs_to few models

    - by ExiRe
    I have few models - User, Teacher and TeacherLeader. class User < ActiveRecord::Base attr_accessible ..., :teacher_attributes has_one :teacher has_one :teacher_leader accepts_nested_attributes_for :teacher_leader end class Teacher < ActiveRecord::Base belongs_to :user has_one :teacher_leader end class TeacherLeader < ActiveRecord::Base belongs_to :user belongs_to :teacher end I would like to fill TeacherLeader via nested attributes. So, i do such things in controller: class TeacherLeadersController < ApplicationController ... def new @user = User.new @teacher_leader = @user.build_teacher_leader @teachers_collection = Teacher.all.collect do |t| [ "#{t.teacher_last_name} #{t.teacher_first_name} #{t.teacher_middle_name}", t.id ] end @choosen_teacher = @teachers_collection.first.last unless @teachers_collection.empty? end end And also have such view (new.html.erb): <%= form_for @user, :url => teacher_leaders_url, :html => {:class => "form-horizontal"} do |f| %> <%= field_set_tag do %> <% f.fields_for :teacher_leader do |tl| %> <div class="control-group"> <%= tl.label :teacher_id, "Teacher names", :class => "control-label" %> <div class="controls"> <%= select_tag( :teacher_id, options_for_select( @teachers_collection, @choosen_teacher )) %> </div> </div> <% end %> <div class="control-group"> <%= f.label :user_login, "Login", :class => "control-label" %> <div class="controls"> <%= f.text_field :user_login, :placeholder => @everpresent_field_placeholder %> </div> </div> <div class="control-group"> <%= f.label :password, "Pass", :class => "control-label" %> <div class="controls"> <%= f.text_field :password, :placeholder => @everpresent_field_placeholder %> </div> </div> <% end %> <%= f.submit "Create", :class => "btn btn-large btn-success" %> <% end %> Problem is that select form here does NOT appear. Why? Do i do something wrong?

    Read the article

  • MongoMapper: how do I create a model like this

    - by Vladimir R
    Suppose we have two models, Task and User. So a user can have many tasks and tasks should be able to have many users too. But, a task should also have a unique creator who is also a user. Exemple: A task in this context is like this: Task ID, Task Creator, Users who should do the task User_1 creates a task and he is then the creator. User_1 specifies User_2 and User_3 as users who should do the task. So these two last users are not creators of task. How do I create this models so that if I have a task object, I can find it's creator and users who should complete it. And how do I do, if I have a user, to find all tasks he created and all tasks he should complete. Thank you.

    Read the article

  • accessing Ruby variable(from model or controller) in SASS

    - by corroded
    Is there a way to access ruby variables in sass or do i have to make a custom function for it? What im trying to do is to generate a stylesheet for each user so in the controller, i do something like: def show respond_to do |format| format.css{render :partial => "styles"} end end then in the view name _styles.haml i do this: :sass #header :background url(user.banner.url) is this possible at all?

    Read the article

  • Rails application and multilingual content, Model dilemma

    - by dakull
    I'm writing in Rails a website that will be multilingual, for the application translation part i will use the simple I18n gem, for messages and everything related. Yet, all the content must be translated, and we're talking about lots of pages, that will be stored into the database ( like articles, news, etc. ) For now, I'm thinking of two approaches: Lets say i have a Pages table, the content in diff. languages, i will be storing it in a different table called PagesContent that will belong_to Pages and also to a Languages table. The problem here, is that I'll essentially duplicate the no. of tables needed. Pros: flexibility, in the box validation To skip that duplication i can serialize a hash into the content column of Pages, containing the translation. The problem here, is validation, arguably more code to write, and less flexibility when adding a new language. Pros: Less tables. Any other idea ?

    Read the article

  • spring mvc nested model validation

    - by hguser
    I have two models : User,Project public class Project{ private int id; @NotEmpty(message="Project Name can not be empty") private String name; private User manager; private User operator; //getter/setter omitted } public class User{ private int id; private String name; //omit other properties and getter/setter } Now, when I create a new Project, I will submit the following parameters to ProjectController: projects?name=jhon&manager.id=1&operator.id=2... Then I will create a new Project object and insert it to db. However I have to validate the id of the manager and operator is valid,that's to say I will validate that if there is matched id in the user table. So I want to know how to implement this kind of validation?

    Read the article

  • how to model a many to many relationship

    - by Maulin
    Here is the scenario, Articles have many Comments Users can write many Comments for many Articles The comments table contains both user_id article_id as foreign keys My models are set up like so class User < ActiveRecord::Base has_many :comments has_many :articles, :through => :comments class Article < ActiveRecord::Base has_many :comments has_many :users, :through => :comments class Comment < ActiveRecord::Base belongs_to :users belongs_to :articles My routes.rb has the following code map.resources :articles, :has_many => :comments map.resources :users, :has_many => :comments which produces the following routes new_article_comment edit_article_comment new_user_comment edit_user_comment etc... This is not what I want (atleast not what I think I want), since comments must always be related to users and article, how can I get a route like so new_user_article_comment edit_user_article_comment Then I could just do new_user_article_comment_path([@user, @article]) to create a new comment

    Read the article

  • get and set for class in model - MVC 2 asp.net

    - by bergin
    Hi there, I want to improve the program so it has a proper constructor but also works with the models environment of MVC. I currently have: public void recordDocument(int order_id, string filename, string physical_path, string slug, int bytes) { ArchiveDocument doc = new ArchiveDocument(); doc.order_id = order_id; doc.filename = filename; doc.physical_path = physical_path; doc.slug = slug; doc.bytes = bytes; db.ArchiveDocuments.InsertOnSubmit(doc); } This obviously should be a constructor and should change to the leaner: public void recordDocument(ArchiveDocument doc) { db.ArchiveDocuments.InsertOnSubmit(doc); } with a get & set somewhere else - not sure of the syntax - do I create a partial class? so: creating in the somewhere repository - ArchiveDocument doc = new ArchiveDocument(order_id, idTaggedFilename, physical_path, slug, bytes); and then: namespace ordering.Models { public partial class ArchiveDocument { int order_id, string filename, string physical_path, string slug, int bytes; public archiveDocument(int order_id, string filename, string physical_path, string slug, int bytes){ this.order_id = order_id; etc } } How should I alter the code?

    Read the article

  • Rails Updating Nested Model Collection Select

    - by Timothy
    I have a contrived nested Rails form like the following <% form_for @a do |fa| %> <% fa.fields_for :b do |fb| %> <% fb.fields_for :c do |fc| %> <%= fc.label :option_id %> <%= fc.collection_select :option_id, ModelD.all(:select => "id, name"), :id, :name %> <% end %> <% end %> <% end %> and then somewhere else on the same page I have a remote form <% remote_form_for :modeld, ModelD.new, :url => new_modeld_path, :html => {:method => 'post'} do |f| %> <%= f.label :name %> <%= f.textarea :name %> <%= f.submit "Create" %> <% end %> Is there any way I could update all the collection selects in the first form using Ajax when I submit the second form? There are an arbitrary number of collection selects.

    Read the article

  • Version Control software (client server model)

    - by Amira Elsayed
    Hi All, I'm using windows 7 , and all what i want is to install Version Control server on one machine and let other developers to connect to it using the machine IP address and chekout, update and commit files I have tried VisualSVN and it works well for me , I also have tried to install Apache Server and try to configure it to run with subversion but I failed to do so , so if any one can help me I will appreciated Thanks in Advance Edit what I want if any one can suggest an alternative like VisualSVN that let me compare and choose from different options Thanks in Advance

    Read the article

  • Circular database relationships. Good, Bad, Exceptions?

    - by jim
    I have been putting off developing this part of my app for sometime purely because I want to do this in a circular way but get the feeling its a bad idea from what I remember my lecturers telling me back in school. I have a design for an order system, ignoring the everything that doesn't pertain to this example I'm left with: CreditCard Customer Order I want it so that, Customers can have credit cards (0-n) Customers have orders (1-n) Orders have one customer(1-1) Orders have one credit card(1-1) Credit cards can have one customer(1-1) (unique ids so we can ignore uniqueness of cc number, husband/wife may share cc instances ect) Basically the last part is where the issue shows up, sometimes credit cards are declined and they wish to use a different one, this needs to update which their 'current' card is but this can only change the current card used for that order, not the other orders the customer may have on disk. Effectively this creates a circular design between the three tables. Possible solutions: Either Create the circular design, give references: cc ref to order, customer ref to cc customer ref to order or customer ref to cc customer ref to order create new table that references all three table ids and put unique on the order so that only one cc may be current to that order at any time Essentially both model the same design but translate differently, I am liking the latter option best at this point in time because it seems less circular and more central. (If that even makes sense) My questions are, What if any are the pros and cons of each? What is the pitfalls of circular relationships/dependancies? Is this a valid exception to the rule? Is there any reason I should pick the former over the latter? Thanks and let me know if there is anything you need clarified/explained. --Update/Edit-- I have noticed an error in the requirements I stated. Basically dropped the ball when trying to simplify things for SO. There is another table there for Payments which adds another layer. The catch, Orders can have multiple payments, with the possibility of using different credit cards. (if you really want to know even other forms of payment). Stating this here because I think the underlying issue is still the same and this only really adds another layer of complexity.

    Read the article

  • WPF tree data binding model & repository

    - by Am
    Hi, I have a well defined tree repository. Where I can rename items, move them up, down, etc. Add new and delete. The data is stored in a table as follows: Index Parent Label Left Right 1 0 root 1 14 2 1 food 2 7 3 2 cake 3 4 4 2 pie 5 6 5 1 flowers 8 13 6 5 roses 9 10 7 5 violets 11 12 Representing the following tree: (1) root (14) (2) food (7) (8) flowers (13) (3) cake (4) (5) pie (6) (9) roeses (10) (11) violets (12) or root food cake pie flowers roses violets Now, my problem is how to represent this in a bindable way, so that a TreeView can handle all the possible data changes? Renaming is easy, all I need is to make the label an updatble field. But what if a user moves flowers above food? I can make the relevant data changes, but they cause a complete data change to all other items in the tree. And all the examples I found of bindable hierarchies are good for non static trees.. So my current (and bad) solution is to reload the displayed tree after relocation change. Any direction will be good. Thanks

    Read the article

  • Creating relationship between two model instances

    - by Lowgain
    This is probably pretty simple, but here: Say I've got two models, Thing and Tag class Thing < ActiveRecord::Base has_and_belongs_to_many :tags end class Tag < ActiveRecord::Base has_and_belongs_to_many :things end And I have an instance of each. I want to link them. Can I do something like: @thing = Thing.find(1) @tag = Tag.find(1) @thing.tags.add(@tag) If not, what is the best way to do this? Thanks!

    Read the article

  • pattern to transfer search model to dao

    - by zeroed
    We have a dao as a project (jar file). Clients use its interfaces and factories to operate with database. Using standard CRUD operations, dao allows you to search an entity by some search criteria. What is the best way to represent this criteria? Is transfer object appropriate pattern in this situation? How should client create SearchModel instance? Please, share. Regards.

    Read the article

  • CakePHP model useTable with SQL Views

    - by Chris
    I'm in the process converting our CakePHP-built website from Pervasive to SQL Server 2005. After a lot of hassle the setup I've gotten to work is using the ADODB driver with 'connect' as odbc_mssql. This connects to our database and builds the SQL queries just fine. However, here's the rub: one of our Models was associated with an SQL view in Pervasive. I ported over the view, but it appears using the set up that I have that CakePHP can't find the View in SQL Server. Couldn't find much after some Google searches - has anyone else run into a problem like this? Is there a solution/workaround, or is there some redesign in my future?

    Read the article

  • Writing out sheet to text file using POI event model

    - by Eduardo Dennis
    I am using XLSX2CSV example to parse large sheets from a workbook. Since I only need to output the data for specific sheets I added an if statement in the process method to test for the specific sheets. When the condition is met I continue with the process. public void process() throws IOException, OpenXML4JException, ParserConfigurationException, SAXException { ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(this.xlsxPackage); XSSFReader xssfReader = new XSSFReader(this.xlsxPackage); StylesTable styles = xssfReader.getStylesTable(); XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) xssfReader.getSheetsData(); while (iter.hasNext()) { InputStream stream = iter.next(); String sheetName = iter.getSheetName(); if (sheetName.equals("SHEET1")||sheetName.equals("SHEET2")||sheetName.equals("SHEET3")||sheetName.equals("SHEET4")||sheetName.equals("SHEET5")){ processSheet(styles, strings, stream); try { System.setOut(new PrintStream( new FileOutputStream("C:\\Users\\edennis.AD\\Desktop\\test\\"+sheetName+".txt"))); } catch (Exception e) { e.printStackTrace(); } stream.close(); } } } But I need to output text file and not sure how to do it. I tried to use the System.set() method to output everything from system.out to text but that's not working I just get blank files.

    Read the article

  • Howto: Access a second related model in a nested attribute builder block

    - by Joe Cairns
    I have a basic has_many through relationship: class Foo < ActiveRecord::Base has_many :bars, :dependent => :destroy has_many :wtfs :through => :bars accepts_nested_attributes_for :bars, :wtfs end On my crud forms I have a builder block for the wtf, but I need the label to come from the bar (an attribute called label for instance). What's the proper method to do this? Here's the most simple scaffold: <h1>New foo</h1> <% form_for(@foo) do |f| %> <%= f.error_messages %> <p> <%= f.label :name %><br /> <%= f.text_field :name %> </p> <h2>Bars</h2> <% f.fields_for :wtfs do |builder| %> <%= builder.hidden_field :bar_id %> <p> <%= builder.text_field :wtf_data_i_need_to_set %> </p> <% end %> <p> <%= f.submit 'Create' %> </p> <% end %> <%= link_to 'Back', foos_path %>

    Read the article

  • Setting Rails Checkbox from Another Model

    - by Kevin
    I have a checkbox that belongs to "Foo" class. I have another "Preferences" class that sets the default for what that checkbox should be. I tried using f.check_box :email_preference, :value => preferences.email_preference but it doesn't work. I use this page to do new record creation as well as edit, so obviously for new records I would want to take the preferences.email_preference setting as a default, then for editing the record use the foo.email_preference. Any suggestions?

    Read the article

  • Need help with a memory management problem in my game model

    - by user309030
    Hi, I'm a beginner level programmer trying to make a game app for the iphone and I've encountered a possible issue with the memory management (exc_bad_access) of my program so far. I've searched and read dozens of articles regarding memory management (including apple's docs) but I still can't figure out what exactly is wrong with my codes. So I would really appreciate it if someone can help clear up the mess I made for myself. //in the .h file @property(nonatomic,retain) NSMutableArray *fencePoleArray; @property(nonatomic,retain) NSMutableArray *fencePoleImageArray; @property(nonatomic,retain) NSMutableArray *fenceImageArray; //in the .m file - (void)viewDidLoad { [super viewDidLoad]; self.gameState = gameStatePaused; fencePoleArray = [[NSMutableArray alloc] init]; fencePoleImageArray = [[NSMutableArray alloc] init]; fenceImageArray = [[NSMutableArray alloc] init]; mainField = CGRectMake(10, 35, 310, 340); .......... [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(gameLoop) userInfo:nil repeats:YES]; } So basically, the player touches the screen to set up the fences/poles -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { if(.......) { ....... } else { UITouch *touch = [[event allTouches] anyObject]; currentTapLoc = [touch locationInView:touch.view]; NSLog(@"%i, %i", (int)currentTapLoc.x, (int)currentTapLoc.y); if(CGRectContainsPoint(mainField, currentTapLoc)) { if([self checkFence]) { onFencePole++; //this 3 set functions adds their respective objects into the 3 NSMutableArrays using addObject: [self setFencePole]; [self setFenceImage]; [self setFencePoleImage]; ....... } } else { ....... } } } } The setFence function (setFenceImage and setFencePoleImage is similar to this) -(void)setFencePole { Fence *fencePole; if (!elecFence) { fencePole = [[Fence alloc] initFence:onFencePole fenceType:1 fencePos:currentTapLoc]; } else { fencePole = [[Fence alloc] initFence:onFencePole fenceType:2 fencePos:currentTapLoc]; } [fencePoleArray addObject:fencePole]; [fencePole release]; and whenever I press a button in the game, endOpenState is called to clear away all the extra images(fence/poles) on the screen and also to remove all existing objects in the 3 NSMutableArray. Point is to remove all the objects in the NSMutableArrays but keep the array itself so it can be reused later. -(void)endOpenState { ........ int xMax = [fencePoleArray count]; int yMax = [fenceImageArray count]; for (int x = 0; x < xMax; x++) { [[fencePoleImageArray objectAtIndex:x] removeFromSuperview]; } for (int y = 0; y < yMax; y++) { [[fenceImageArray objectAtIndex:y] removeFromSuperview]; } [fencePoleArray removeAllObjects]; [fencePoleImageArray removeAllObjects]; [fenceImageArray removeAllObjects]; ........ } The crash happens here at the checkFence function. -(BOOL)checkFence { if (onFencePole == 0) { return YES; } else if (onFencePole >= 1 && onFencePole < currentMaxFencePole - 1) { CGPoint tempPoint1 = currentTapLoc; CGPoint tempPoint2 = [[fencePoleArray objectAtIndex:onFencePole-1] returnPos]; // the crash happens at this line if ([self checkDistance:tempPoint1 point2:tempPoint2]) { return YES; } else { return NO; } } else if (onFencePole == currentMaxFencePole - 1) { ...... } else { return NO; } } So the problem here is, everything works fine until checkFence is called the 2nd time after endOpenState is called. So its like tap_screen - tap_screen - press_button_to_call_endOpenState - tap screen - tap_screen - crash What I'm thinking of is that fencePoleArray got messed up when I used [fencePoleArray removeAllObjects] because it doesn't crash when I comment it out. It would really be great if someone can explain to me what went wrong. And thanks in advance.

    Read the article

  • access properties of current model in has_many declaration

    - by seth.vargo
    Hello, I didn't exactly know how to pose this question other than through example... I have a class we will call Foo. Foo :has_many Bar. Foo has a boolean attribute called randomize that determines the order of the the Bars in the :has_many relationship: class CreateFoo < ActiveRecord::Migration def self.up create_table :foos do |t| t.string :name t.boolean :randomize, :default => false end end end   class CreateBar < ActiveRecord::Migration def self.up create_table :bars do |t| t.string :name t.references :foo end end end   class Bar < ActiveRecord::Base belongs_to :foo end   class Foo < ActiveRecord::Base # this is the line that doesn't work has_many :bars, :order => self.randomize ? 'RAND()' : 'id' end How do I access properties of self in the has_many declaration? Things I've tried and failed: creating a method of Foo that returns the correct string creating a lambda function crying Is this possible? UPDATE The problem seems to be that the class in :has_many ISN'T of type Foo: undefined method `randomize' for #<Class:0x1076fbf78> is one of the errors I get. Note that its a general Class, not a Foo object... Why??

    Read the article

  • Model class is not found in zend framework project (quickstart) ,please help

    - by Dumindu
    The things I did is zf create project demo1 in command prompt add the lines to application.ini appnamespace = "Application" resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts" add a layout with header and footer using partial() (They are perfectly worked) create Data.php in models directory and add this simple class <?php class Application_Model_Data{ }//Application for appnamespace then I tried to load this class(by creating instance)from index controller index action $data = new Application_Model_Data(); but when I test it even in this level it gives an error Fatal error: Class 'Application_Model_Data' not found in C:\Zend\...\IndexController.php Question Do I want to add a autoloader to load models in the application( I'm not used modules) if not what was I missed to add please help I'm stuck in the beginning,Thank you

    Read the article

  • Using scope, defined in parent model, inside it's child (STI pattern)

    - by Anton
    I implement a class hierarchy using STI pattern class A scope :aaa, where([someField]:[someValue]) end class B < A end The problem is that when I try to call something like: B.limit(5).aaa => SELECT "[table]".* FROM "[table]" WHERE "[table]"."type" IN ('A') AND ([someField] = [someValue]) LIMIT 5 So I am getting 5 objects of type A, which satisfies scope :aaa But I need to do the same with rows where type = "B" Is there any way to use scopes from parent, without redifinning it in childs in STI pattern? Thanks in advance EDITED I just discussed it with my frind and he showed me one important thing. A in not the root class of STI. IN fact whole hierarchy looks like class O < ActiveRecord::Base end class A < O scope ..... ..... end class B < A end maybe the reason is in hierarchy itself?...

    Read the article

  • Weird code appearing when I loop over model instances in Rails

    - by Tom Maxwell
    In my Rails app I'm trying to loop over the Submission instances inside my Folder instances with Rails templating code. It works. However, it's also returning each instance in code which doesn't seem to be JSON. It's what's returned when you look up an instance in the Rails console. Here's an example: #<Submission id: 112, title: nil, content: nil, created_at: "2013-10-10 23:29:39", updated_at: "2013-10-10 23:29:39", user_id: 1, folder_id: 1, parent_id: nil> Here's what the code looks like for the loop: <%= @folder.submissions.each do |x| %> <% if x.title != nil %> <div id="<%= x.id %>" class="submission-textual"> <h1><%= x.title %></h1> </div> <% else %> <% end %> <% end %> I checked my Folder and Submissions controllers but am not sure what this is. Why are these strings being rendered whenever I try and render an instance in my view? I'm still new to Ruby so that explains why I haven't seen this.

    Read the article

< Previous Page | 78 79 80 81 82 83 84 85 86 87 88 89  | Next Page >