Daily Archives

Articles indexed Friday April 16 2010

Page 13/120 | < Previous Page | 9 10 11 12 13 14 15 16 17 18 19 20  | Next Page >

  • What's the best way to refactor this Rails controller?

    - by Robert DiNicolas
    I'd like some advice on how to best refactor this controller. The controller builds a page of zones and modules. Page has_many zones, zone has_many modules. So zones are just a cluster of modules wrapped in a container. The problem I'm having is that some modules may have some specific queries that I don't want executed on every page, so I've had to add conditions. The conditions just test if the module is on the page, if it is the query is executed. One of the problems with this is if I add a hundred special module queries, the controller has to iterate through each one. I think I would like to see these module condition moved out of the controller as well as all the additional custom actions. I can keep everything in this one controller, but I plan to have many apps using this controller so it could get messy. class PagesController < ApplicationController # GET /pages/1 # GET /pages/1.xml # Show is the main page rendering action, page routes are aliased in routes.rb def show #-+-+-+-+-Core Page Queries-+-+-+-+- @page = Page.find(params[:id]) @zones = @page.zones.find(:all, :order => 'zones.list_order ASC') @mods = @page.mods.find(:all) @columns = Page.columns # restful params to influence page rendering, see routes.rb @fragment = params[:fragment] # render single module @cluster = params[:cluster] # render single zone @head = params[:head] # render html, body and head #-+-+-+-+-Page Level Json Conversions-+-+-+-+- @metas = @page.metas ? ActiveSupport::JSON.decode(@page.metas) : nil @javascripts = @page.javascripts ? ActiveSupport::JSON.decode(@page.javascripts) : nil #-+-+-+-+-Module Specific Queries-+-+-+-+- # would like to refactor this process @mods.each do |mod| # Reps Module Custom Queries if mod.name == "reps" @reps = User.find(:all, :joins => :roles, :conditions => { :roles => { :name => 'rep' } }) end # Listing-poc Module Custom Queries if mod.name == "listing-poc" limit = params[:limit].to_i < 1 ? 10 : params[:limit] PropertyEntry.update_from_listing(mod.service_url) @properties = PropertyEntry.all(:limit => limit, :order => "city desc") end # Talents-index Module Custom Queries if mod.name == "talents-index" @talent = params[:type] @reps = User.find(:all, :joins => :talents, :conditions => { :talents => { :name => @talent } }) end end respond_to do |format| format.html # show.html.erb format.xml { render :xml => @page.to_xml( :include => { :zones => { :include => :mods } } ) } format.json { render :json => @page.to_json } format.css # show.css.erb, CSS dependency manager template end end # for property listing ajax request def update_properties limit = params[:limit].to_i < 1 ? 10 : params[:limit] offset = params[:offset] @properties = PropertyEntry.all(:limit => limit, :offset => offset, :order => "city desc") #render :nothing => true end end So imagine a site with a hundred modules and scores of additional controller actions. I think most would agree that it would be much cleaner if I could move that code out and refactor it to behave more like a configuration.

    Read the article

  • ActiveRecord table inheritence using set_table_names

    - by Jinyoung Kim
    Hi, I'm using ActiveRecord in Ruby on Rails. I have a table named documents(Document class) and I want to have another table data_documents(DataDocument) class which is effectively the same except for having different table name. In other words, I want two tables with the same behavior except for table name. class DataDocument < Document #set_table_name "data_documents" self.table_name = "data_documents" end My solution was to use class inheritance as above, yet this resulted in inconsistent SQL statement for create operation where there are both 'documents' table and 'data_documents' table. Can you figure out why and how I can make it work? >> DataDocument.create(:did=>"dd") ActiveRecord::StatementInvalid: Mysql::Error: Unknown column 'data_documents.did' in 'where clause': SELECT `documents`.id FROM `documents` WHERE (`data_documents`.`did` = BINARY 'dd') LIMIT 1 from /Users/lifidea/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract_adapter.rb:212:in `log' from /Users/lifidea/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/mysql_adapter.rb:320:in `execute' from /Users/lifidea/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/mysql_adapter.rb:595:in `select' from /Users/lifidea/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `select_all_without_query_cache' from /Users/lifidea/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/query_cache.rb:62:in `select_all'

    Read the article

  • Run C# code after running all javascript codes

    - by Devi
    I am having a form in which a button is there on click of that button i am calling a javascript function in which i am displaying like 3.. 2.. 1 kind of effect then i am returning true. But after showing 3 only return true is getting executed and the form is getting submitted. How to stop form submitting before running the script. Edit: function jsFun() { timerCount(3); //Calling the Timer Function. } var t; function timerCount(cDown) { if (cDown == 0) { clearTimeout(t); return true; } $('#<%= mainContainer.ClientID %>').html(cDown); cDown = cDown - 1; t = setTimeout('timerCount(' + cDown + ')', 1000); } <asp:Button ID="btnStarts" runat="server" Text="Start" OnClientClick="return jsFun();" OnClick="btn_click" />

    Read the article

  • iPhone UITableView populateing from connectionDidFinishLoading

    - by fourfour
    Hey all. I have been trying for hours to figure this out. I have some JSON from a NSURLConnection. This is working fine and I have parsed it into an array. But I can't seem to get the array out of the connectionDidFinishLoading method. I an am getting (null) in the UITableViewCell method. I am assuming this is a scope of retain issue, but I am so new to ObjC I am not sure what to do. Any help would be greatly appreciated. Cheers. -(void)connectionDidFinishLoading:(NSURLConnection *)connection { [connection release]; NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; [responseData release]; SBJSON *json = [[SBJSON alloc] init]; NSDictionary *results = [json objectWithString:responseString]; self.dataArray = [results objectForKey:@"data"]; NSMutableArray *tableArray = [[NSMutableArray alloc] initWithObjects:nil]; for (NSString *element in dataArray) { //NSLog(@"%@", [element objectForKey:@"name"]); NSString *tmpString = [[NSString alloc] initWithString:[element objectForKey:@"name"]]; [tableArray addObject:tmpString]; } } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } // Configure the cell. //cell.textLabel.text = [self.tableView objectAtIndex:indexPath.row]; cell.textLabel.text = [self.tableArray objectAtIndex:indexPath.row]; NSLog(@"%@", tableArray); return cell; }

    Read the article

  • One Update Panel vs. Multiple Update Panels

    - by mattruma
    I have an ASP.NET web page that displays a variety of fields that need to be updated best on certain conditions, button clicks and so on. We've implemented AJAX, using the ASP.NET Update Panel to avoid visible postbacks. Originally there was only one area that needed this ability ... that soon expanded to other fields. Now my web page has multiple UpdatePanels. I am wondering if it would be best to just wrap the entire form in a single UpdatePanel, or keep the individual UpdatePanels. What are the best practices for using the ASP.NET UpdatePanel?

    Read the article

  • PHP & MySQL form question.

    - by peakUC
    How do I allow all users to have there username field empty without having them to enter a username when they submit the form using PHP and MySQL? Here is part my PHP and MySQL code. $username = mysqli_real_escape_string($mysqli, $purifier->purify(htmlentities(strip_tags($_POST['username'])))); if(isset($_POST['username'])) { // Make sure the username address is available: $u = "SELECT * FROM users WHERE username = '$username' AND user_id <> '$user_id'"; $r = mysqli_query ($mysqli, $u) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($mysqli)); if (mysqli_num_rows($r) == TRUE) { // Unavailable. echo '<p class="error">Your username is unavailable!</p>'; $username = NULL; } else if(mysqli_num_rows($r) == 0) { // Available. $username = mysqli_real_escape_string($mysqli, $purifier->purify(htmlentities(strip_tags($_POST['username'])))); } }

    Read the article

  • lightweight cryptography toolkit(s) for c++ and python

    - by Joey
    Hi, I'm looking to do some basic encryption of server messages which'd be encrypted with C++ and decrypted using Python serverside. I was wondering if anyone knew if there were good solutions that were simpler or more lightweight than Keyczar. I see that supports both C++ and python, but would using Crypto++ and PyCrypto be simpler for a newbie that just wants to get something up and running for the time being? Or should I use Keyczar for python and Crypto++ for the C++ end? The C++ libraries seem to have dependencies to hundreds of files.

    Read the article

  • Why do i get a 403 error when viewing a Drupal custom menu item via clean url?

    - by Chaulky
    Hi all, I've created a custom menu item in my Drupal 6 website by defining it in a custom module. This is an extremely simple MENU_NORMAL_ITEM menu item. The menu item is defined as /** * Implementation of hook_menu(). */ function menu_test_menu() { $items['menu_test'] = array( 'title' => 'Menu Test', 'page callback' => 'menu_test_hello', 'access callback' => TRUE, 'type' => MENU_NORMAL_ITEM, ); return $items; } Since I have clean URLs on, the path should be www.example.com/menu_test. That URL gives me a 403 error. But, if I enter www.example.com/?q=menu_test, everything works fine. Why am I getting the 403 error? The menu item is useless because it's always trying to go to the clean URL path, which should work but doesn't for some reason. Thanks for the help!

    Read the article

  • Getting Recognition for Open-Source Computer Language Projects

    - by Jon Purdy
    I like language a lot, so I write a lot of language-based solutions for programming, automation, and data definition. I'm very much a believer in open-source software, so lately I've started to push these projects to Sourceforge when I start them. I feel that these tools could be quite valuable in the right hands, and that they fill niches that otherwise go unfilled. The trouble, for me, is gaining recognition. No matter how useful the software I write, after a certain point I can no longer come up with anything to add or improve. Basically no one but me uses it, so it's not being attacked from enough angles to discover any new weaknesses. I cannot work on a project that doesn't have anything to do, but I won't have anything to do unless I gain recognition by working on it! This is greatly discouraging. It's like giving what you think is a really thoughtful gift to someone who just isn't paying attention. So I'm looking for advice on how to network and disseminate information about my projects so that they don't fizzle out like this. Are there any sites, newsgroups, or mailing lists that I've been completely missing?

    Read the article

  • Disabling SMB2 on Windows Server 2008

    - by Alan B
    There are a couple of reasons you might do this, the first is an exploit. The second is potential locking and corruption issues with legacy flat-file databases. There is a performance penalty in doing this - but how noticeable is it? What other reasons are there for not disabling SMB2 (assuming the security vulnerability is fixed) ?

    Read the article

  • where to look for computer technician jobs

    - by Kareem
    Hi I am currently studying for the A+ certification, I plan to have it by the end of this month and I plan to go for farther education. I’ve built two high end computers by myself for a friend and family member. Install OS and everything. I’m looking in to finding either a computer assembly or computer technician job . Where is the best place to look for one? I’ve looked in to best buy but I find their geek squad to be a little bit shady. Where is a good place to look for a full time entry level computer technician job just starting out in Tampa, FL?

    Read the article

  • Innodb : cannot allocate the memory for the buffer pool

    - by mingyeow
    My innodb keeps crashing. This is the error message below. Does anyone know why this keeps happening? InnoDB: by InnoDB 49201616 bytes. Operating system errno: 12 InnoDB: Check if you should increase the swap file or InnoDB: ulimits of your operating system. InnoDB: On FreeBSD check you have compiled the OS with InnoDB: a big enough maximum process size. InnoDB: Note that in most 32-bit computers the process InnoDB: memory space is limited to 2 GB or 4 GB. InnoDB: We keep retrying the allocation for 60 seconds... 0 processes alive and '/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf ping' resulted in /usr/bin/mysqladmin: connect to server at 'localhost' failed error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)' Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists! InnoDB: Fatal error: cannot allocate the memory for the buffer pool [ERROR] Default storage engine (InnoDB) is not available

    Read the article

  • Asus z53 laptop overheating problem

    - by Tiberiu Hajas
    hi all, wondering if anyone encountered overheating of asus laptop ? especially the z53 model ? usually the right side of the laptop and vent in the upper corner is blowing hot air when under even minimal load, the CPU temperature can easily get to 65-70C and GPU is even above 80C. I'm using NHC (notebook health control) to set to a higher conservatory power consumption but that helps only a bit, anyone opened up the case ? wondering is require a dust clean ...etc ? I still have some warranty on it. thanks

    Read the article

  • ImageMagick vs. Cairo on Vector Graphics rasterization

    - by Sherwood Hu
    I am working on a project that needs rasterizing of drawings into image files. I have already got it work using GDI+. Wanting to create a portable solution, I am also looking into other solutions and found two - cairo and imagemagick. I am new to both, but it seems that ImageMagick can do almost all the stuff - drawing lines, arcs, circles, text etc.. plus many bitmap manipulation. However, Cairo is mentioned as competitor to GDI+ in web sites. ImageMagick is never mentioned for this purpose. I do not have time to invest on both libraries. I need to decide which one is worthy. I prefer to ImageMagick, as it seems much more powerful. What's your opinion on the two graphic libs?

    Read the article

  • Android TranslateAnimation resets after animation

    - by monmonja
    I'm creating something like a SlideDrawer but with most customization, basically the thing is working but the animation is flickering at the end. To further explain, I got an TranslateAnimation then after this animation it returns back to the original position, if i set setFillAfter then the buttons inside the layout stops working. If i listen to onAnimationEnd and set other's layout to View.GONE the layout fickers. Judging from it is that on animation end, the view goes back to original position before the View.GONE is called. Any advice would be awesome. Thanks

    Read the article

  • Application self aware of external database record modifications.

    - by Khou
    How do you make your application aware that a database record was changed or created by an external application rather than the application itself? Do you add a special check sum to the database record or what do you do to stop external changes to the database? (in case it was hacked and the hacker decides to add a new record or change an existing database record)

    Read the article

  • Dynamically inserting an image with JavaScript does not work on images that 302 redirect

    - by Samuel Clay
    I am dynamically inserting an image into an HTML document using jQuery. Here is the code: var image_url = "http://www.kottke.org/plus/misc/images/castro-pitching.jpg"; var $image = $('<img src="'+image_url+'" width="50" height="50" />'); $('body').prepend($image); Notice that the image http://www.kottke.org/plus/misc/images/castro-pitching.jpg is actually a 302 redirect to http://kottkegae.appspot.com/images/castro-pitching.jpg. If you were to go to the original image in your browser, it works fine. If you were to load an HTML page with that image in an img tag, it would load fine. However, if you were to insert it dynamically using jQuery (or JavaScript, for that matter), the browser will not show the 302'ed image. If you show the redirected image, it would work fine. var image_url = "http://kottkegae.appspot.com/images/castro-pitching.jpg"; var $image2 = $('<img src="'+image_url+'" width="50" height="50" />'); $('body').prepend($image2); That's crazy, right? What gives and how can I force the image to load when inserted dynamically?

    Read the article

< Previous Page | 9 10 11 12 13 14 15 16 17 18 19 20  | Next Page >