Ir al contenido principal

Entradas

Mostrando entradas de abril, 2014

Rails - Basic Steps V

Request Processing http://localhost:3000/posts/1 Call method show in PostsController class passing the params [:id] The class' path is   root_app/app/controllers/posts_controller.rb The show method will use ActiveRecord#find method to retrieve the post with id=1 from the database and assign to variable @post The controller will pass @post to the view (template file):  root_app/app/views/posts/show.html.erb Session Ex:  session[ :current_user] = user_id flash is part of the session that is clear in each request Ex:  flash[:notice] = 'Post was created' Views To see the view files Go to  root_app/app/views/posts The form is in the file  _form.html.erb Embedded Ruby (ERb) is the most common templating framework Takes a .html.erb template file and transform as HTML  <%=    %> the code is assigned to the html file <%  %> the code is only executed Layout The default layo...

Rails - Basic Steps IV

Controls Structures If              if  expression                 code              end if- else              if  expression                 code              elsif  expression2                 code              else                 code              end until              until expression do                   code              end for              for var in collection               ...

Rails - Basic Steps III

pValidations Validations are a type of ActiveRecord Validations are defined in our models Implement Validations Go to   root_app/app/models Open files  *.rb for each model Mandatory field validates_presence_of   :field Ex:   validates_presence_of    :title Classes The basic syntax is class MyClass        @global_variable                def my_method              @method_variable        end end Create an instance myInstance = MyClass.new Invoke a mehod mc.my_method class() method returns the type of the object In Ruby, last character of method define the behavior If ends with a question -> return a boolean value If ends with an exclamation -> change the state of the object Getter / Setter method def global_variable       return @global_variable end ...

AJAX - Tabs C#

I had a problem at the moment of hide a tab and after show (active) another tab. This cause me an error in javascript. Solution The first time the TabContainer is shown, ajax read the number of tabs and is all the tabs he knows. In my case at the beginning show 2 tabs and hide other 2 tabs     In the aspx bind the method OnActiveTabChanged ="TabContainerUpdate_ActiveTabChanged" In the method TabContainerUpdate_ActiveTabChanged I add the condition:   if (TabContainerUpdate.ActiveTabIndex != 0)             TabContainerUpdate.ActiveTabIndex = 1; With this condition when I show another tab I assigned the new tab to the second index that ajax knows  I prefer to use the ActiveTabIndex property instead of ActiveTa b   Knowledge The error is caused because at the beginning ajax only know that have 2 tabs, and when reload the page in an AutoPostback try to go to another tab with index bigger that 2

Rails - Basic Steps II

Database The scaffold generator create a database migration file in root_app/db/migrate rake command execute the migration files The DB to be used is specified in  root_app/db/database.yml Rails environment Development - When the application is created is in this mode, all changes are reflected immediately rails server - Deploy in development mode Use SQLite as part of the development environment  Test - To run the tests Production - When the application is deployed rails server -e production  - Deploy in production mode  Active Record Is a design pattern In Ruby is used as a mean of persisting data Is used to access data stored in relational databases Perform CRUD operations without worrying about the specific underlying database Encapsulates that notion an object-relational mapping (ORM) Active Record Module This pattern is provided in a module called ActiveRecord Establish a connection ActiveRecord::Base.establish_connnec...

Rails - Basic Steps

Installation for Windows Execute the installer   http://rubyinstaller.org/downloads Install rails, type in the console: gem install rails Install Ruby installer Develpment Kit from the same page Open the Ruby console and type : ruby dk.rb init ruby dk.rb install Install a timezone with  TZInfo::Data  Open file Gemfile Add the lines:   gem 'tzinfo-data' gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw] Type:   gem install tzinfo-data Type in the console:  bundle update Files Structure Rails.root     ->  Folder with your application name   |- app      -> Models, Views and Controller code   |- bin          -> Helper scripts (bundle, rails, rake)   |- config   -> App, database & route configuration   |- db           ->  Database schema and migration   |- Gemfile ->  ...

Web Application - Patterns

n-Tier Arquitecture Break the system into different pieces or tiers that can be physically separated: Each tier is responsible for providing a specific functionality A tier only interacts with the tiers adjacent, to it through a well-defined interface Advantages  Manages complexity of the design Create a balance between innovation and standardization Systems are much easier to build, maintain, scale and upgrade 3-Tier Architecture Presentation tier:  User interface and subdivided into two tiers: Client tier: client-side user interface components Presentation logic tier: server-side scripts for generating web pages Application (logic) tier :  Retrieves, modifies, delete data in the data tier and sends the results to presentation tier. Also process the data itself and is subdivided into two pieces Business logic tier: Models the business objects associated with the application and captures the business rules and workflows associated with how t...

Web Application - Basic Concepts

Web 1.0 Creation of static web sites, first web business models Web 2.0 Interactivity (Ajax), social networking,mash-ups, media sharing,online commerce, lightweight collaboration, wikis Web 3.0 (Intelligent web) Machine-facilitated understanding of information Ex.semanticweb, NLP, machine learning/reasoning, recommender  systems Enablers of Web 2.0 & 3.0 JavaScript XML JSON (Ajax) Web services interoperability Cloud Computing: Infrastructure, platform and SAS (software-as-a-service) Mobile platforms and apps leading to ubiquitous computing Metadata, linked data and machine processing by intelligent agents Web Application Collection of client and server-sides scripts. The application itself is accessed by users via specific path within a web server

Python - Basics

Download python.org Basics commands dir(__builtins__)    Show all the defined functions help(function_name)  Show function description print(string_text) (__name__) print the scope in which the functionality is been executed Define a function Type word def follow by name function with the parameters Type word return with the functionality Ex:    def  f(x):   return  x**2 Testing Inside your function description define the result expected inside the comments. ''' >>> function_name(parameter_value) result >>> function_name(parameter_value_2) result2 >>> ''' To run the test cases type import doctest doctest.testmod() You can also run the test cases after your return statement, so each time you include your function the test cases are executed. Unittest You can also use Unit Test  Import unittest Create a class inherits from  unittest.TestCase class TestMain(unittest.TestCase): Create your test case  def test...