Archive for June 23rd, 2009

ASP.NET Master Page Advice, Tips, and Tricks

Master pages are an important part of any ASP.NET website. In a nutshell, a master page allows the page developer to define a website template, indicating what portions of the template are to remain fixed across pages that use the template and what regions of the template are customizable on a page-by-page basis. Having the site design and layout centralized in one (or more) master pages makes it easy to add new pages to the site that inherit the same look and feel and greatly simplifies changing the site design or adding or removing content that is common to all pages, such as content in the <head> element, footers, and references to CSS and JavaScript files.

This article presents advice for using master pages, along with assorted tips and tricks that I've picked up over the years in using master pages. Read on to learn more! And if you have additional recommendations and advice on using master pages, please don't hesitate to drop me a line and I'll be happy to add your insight to this article.
Read More >

Comments Off more...

Why Enterprise Software Provider Atlassian Chose OpenSocial

Hi, I'm Mark Halvorson the "Chief Imagineer" at Atlassian Software. Whenever I tell people my title it is usually received in one of two ways - a chuckle and a blank stare, or for those in the know some comment about Walt Disney. No, I don't make rides for an amusement park, but I do get to imagine inventive ways to combine thorny, enterprise challenges with some of the exciting things happening on the consumer web. That is why I'm particularly excited to blog in this forum about how Atlassian is bringing OpenSocial to the Enterprise.

Enterprise, meet OpenSocial

Much like "Imagineer" makes you think Walt Disney when you hear OpenSocial, you are likely thinking: Orkut, MySpace, and other Internet social networks. When we heard OpenSocial we thought: now there's some cool technology we can use to bring our portfolio closer together, and closer to lots of great stuff on the Internet.

Atlassian is a seven-year young software company, hailing from Australia, and building collaboration and productivity tools for developers and teams. Many of you may of come across two of our better known products: JIRA, an issue tracker, and Confluence, an enterprise wiki. The rest of the portfolio includes a series of developer tools: FishEye, for exploring source code on the web; Crucible, for peer code review; Bamboo, a continuous integration server; and Clover, for test coverage analysis. We also offer Studio, which combines several of these products into a hosted integrated development suite.

Development is a social activity

Development is social. Developers work in teams, often with other non-developers like product managers and technical writers. Those teams work together on a variety of shared objects: specifications, tasks, documentation, source code, builds and projects. Each of those shared objects generate lots of activity: comments, subtasks, notifications of changes and edits, build failures, code commits. These teams use lots of different tools and systems: wikis, bug trackers, build automation systems, source code repositories. That's a huge internal social network. People working with people, people working with systems, and systems working with systems - a river of activity that needs to funnel to the people who care about it most. Our mission is to help developers collaborate and communicate easier, and in the process help them write higher quality code faster.

Okay, so why OpenSocial?

With eight products that support various parts of the development process, each with their own dashboard, and each spitting off data and activity that the others could benefit from, OpenSocial gave us an inventive, proven integration pattern: gadgets . We've embraced OpenSocial gadgets as a method of integration between our own products and between other enterprise software, and we're using OpenSocial gadgets as a mechanism to inject functionality and information from our products into other OpenSocial-compliant containers on the Internet, like Gmail or iGoogle.

JIRA 4.0 will be the first OpenSocial container in our portfolio to ship. JIRA has implemented OpenSocial through Shindig as a series of Atlassian plugins, which we call the Atlassian Gadgets plugins. JIRA produces Gadgets that can be displayed by other OpenSocial-compliant containers, including iGoogle and Gmail, and authentication between Gadget producers and consumers is handled through OAuth. We're excited about the possibilities. JIRA dashboards can now quickly assemble build status from Bamboo, project updates from Confluence, assigned code reviews from Crucible, all in the context of the issues and tasks assigned to a developer in the context of a JIRA project. Are you a team lead, and spend most of your time in Gmail? No problem, take all of that same information and park it there, so it's right alongside your inbox.

We've launched a little site that talks more about what we're doing at http://www.atlassian.com/opensocial. You can also follow us on twitter http://twitter.com/atlassian. I hope to do more blogging here about things we learn and cool stuff we're experimenting with. In the meantime, here's short video of how a dev manager, who may live in Gmail, can file issues and track the state of projects and builds using Atlassian Gadgets in Gmail.




A Simple Twitter App with Ruby on Rails – Messages With Ajax


Ruby on Rails is a web application framework that promotes rapid development. Clients’ demands are ever increasing yet they still expect the same quality of output.

Frameworks, like Rails, help to achieve this; why?… here are some of the reasons:


  • Convention over Configuration (CoC):

    This is used to reduce the amount of up-front configuartion. The idea is; if you abide by certain coding conventions, you will have little, to none, configuration to do.
  • Object-Relational Mapping (ORM):

    ORM reducing coupling to the database. This abstraction allows you changed the DBMS provider with little trouble.
  • Structured Code:

    The MVC pattern forces you to organise your code in a clean, structured way. This results in more maintainable code.
  • Plugins:

    Plugins save you from re-inventing the wheel every time you want to add functionality to your app. For instance, making you web app capable of performing searches can be easily added with the acts_as_ferret plugin. There are many more plugins!

Who is this Tutorial for?

This tutorial is for people who have learnt the basics of Rails and want to take things to the next level. This tutorial is not a beginners guide for getting started with Rails. If you are just starting out with Rails I suggest this article from Six Revisions.

What this Tutorial Covers

In the first part of this three part series, we cover setting up a simple message model, which will hold the messages posted. Further to this, we will learn how to post a message asynchronously, using AJAX.

View Demo of Twitter App with Ruby on Rails

Basic Application Design

Ok, so you’ve decided to create a “twitter” style micro-blog using Ruby on Rails. First, we need to think about our basic requirements and from this we can model our application.

There are many ways that this can be done, but we will use a simple technique in which you jot down a few paragraphs about how and what the application is expected to do then highlight the nouns. So, lets try it.

My web app should work in a similar way to twitter. Users should be able to register with the site and create short posts. Users should be able to follow other users. Each user should be able to see their own posts plus the users they are following.

Note that I’ve been selective in what nouns I’ve highlighted. You only really need to take notice of the nouns which you feel will need to store data to the database.

I know there is more to twitter than this, but lets leave it simple. As you can see the “nouns”, which will need to store data to the database are “posts” and “users”. So we require two models:

In the first part of the tutorial, we are going to deal with posts only.

  • Post
  • User

Creating the Project Files

Before we do anything we need to create a project for our twitter web app.

  > rails twitter -d mysql

As you can see, I will be using MySQL as the DBMS, however, feel free to use whatever database you want.

Open the database.yml file in the config folder and modify the password as required. An example is shown below.

development:
  adapter: mysql
  encoding: utf8
  database: twittest_development
  pool: 5
  username: root
  password: yourpassword
  host: localhost

Now, create the database with the “rake” command.

  > rake db:create

Implementing the basic Message Model

So let’s go right ahead and generate the “Post” model and migrate it.

  > ruby script/generate model post message:text
  > rake db:migrate

Controller

Now, let’s create a controller for the post model.

  > ruby script/generate controller posts

We need to set up some methods for interacting with the model. Edit your “posts_controller.rb” file and add the following methods:

class PostsController < ApplicationController
  def index
    @posts = Post.all(:order => "created_at DESC")
    respond_to do |format|
      format.html
    end
  end

  def create
    @post = Post.create(:message => params[:message])
    respond_to do |format|
      if @post.save
        format.html { redirect_to posts_path }
      else
        flash[:notice] = "Message failed to save."
        format.html { redirect_to posts_path }
      end
    end
  end
end

We only need two methods, “index” and “create”. The index method creates an instance variable containing all the posts in descending order. The create method is used to create a new post.

Views

Let’s create the “index” view. First, we’ll create a partial for posts. Create a file called “_post.html.erb” in the views/posts folder and add the code below.

<p><b>Posted <%= time_ago_in_words(post.created_at) %> ago</b></p>
<p><%= post.message %></p>

The index view is now very simple. Create a file called “index.html.erb” in the views/posts folder and add the code below.

<%= render :partial => @posts %>

Create some Posts

Open a console session and create a few new messages, as shown below.

  > ruby script/console
  Loading development environment (Rails 2.3.2)
  >> Post.create!(:message => "My first post" )
  >> Post.create!(:message => "Post number two!" )

Create a Form for Posts

Obviously you’re not going to get the user to use the console to create messages. So, our next task is to inject some functionality into our web app to allow the user to create messages. Twitter has an input box above the indexed messages, which is used for submitting a new message; We will keep our web app the same.

First, we will create a partial for the form, then we will render that partial at the top of the index view. Create a file called “_message_form.html.erb” in the posts view folder and add the following code:

<% form_tag(:controller => "posts", :action => "create") do %>
  <%= label_tag(:message, "What are you doing?") %><br />
  <%= text_area_tag(:message, nil, :size => "44x6") %><br />
  <%= submit_tag("Update") %>
<% end %>

Now, we need to modify the index view to render this partial at the top. Open the index.html.erb file and modify the code as follows:

<%= render :partial => "message_form" %>
<%= render :partial => @posts %>

For this to work we need to make one last modification. Open the route.rb file and map a new “posts” resource, as shown below. (Note: the comments from this file have been removed).

ActionController::Routing::Routes.draw do |map|
  map.resources :posts
  map.connect ':controller/:action/:id'
  map.connect ':controller/:action/:id.:format'
end

This creates a few named routes. If you look back to the “create” method in the posts controller, you’ll see that we make use of the posts_path named route; Defining the posts resource makes this named route available.

So, lets fire up the web server and a see how things look.

  > ruby script/server

Now open a browser and go to http://localhost:3000/posts. You should see a screen, as shown below.

Adding some AJAX

AJAX allows you to make asynchronous requests to the server using JavaScript. We will make use of AJAX to make the posting a message a bit smoother.

When the user clicks on the “Update” button, we want the message to update without refreshing the browser. We have a few things to do to add AJAX functionality. First, lets change the “create” method in the posts controller:

  def create
    @post = Post.create(:message => params[:message])
    respond_to do |format|
      if @post.save
        format.html { redirect_to posts_path }
        format.js
      else
        flash[:notice] = "Message failed to save."
        format.html { redirect_to posts_path }
      end
    end
  end

The only change here is the “format.js” code, allowing the create method to respond to JavaScript. Next, we need to create a posts layout file. In the views/layout folder create a file called “posts.html.erb” and add the following code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <%= javascript_include_tag :all %>
</head>
<body>
  <div id="content">
    <%= yield %>
  </div>
</body>
</html>

The main purpose of this is to make use of the “javascript_include_tag” call, which includes the relevant JavaScript files for AJAX and some visual effects. Next, we need to make a small addition to the index view (”index.html.erb”).

<%= render :partial => "message_form" %>
<div id="posts">
  <%= render :partial => @posts %>
</div>

As you can see all we have added is a div block surrounding the posts partial. This will be used later when we are specifying where the AJAX response should be placed. Nearly there! Now we will add a div_for block to our post partial (”_post.html.erb”).

<% div_for post do %>
  <p><b>Posted <%= time_ago_in_words(post.created_at) %> ago</b></p>
  <p><%= post.message %></p>
<% end %>

Edit the “_message_form.html.erb” partial and change the form_tag call to form_remote_tag as show in the code extract below:

<% form_remote_tag(:controller => "posts", :action => "create") do %>

The div_for operation create a div block with a unique id, this is especially useful when looping through several records. Finally, we need to create the rjs template. To do this, create a file called “create.js.rjs” in the views/posts folder and add the following code.

page.insert_html :top, :posts, :partial => @post
page[@post].visual_effect :highlight

The first line specifies that a new post partial will be rendered at the top of the posts div when the asynchronous call responds. The second line specifies that a “highlight” visual effect will be applied to that block when it is rendered.

That’s it! Start you web server again, browse to http://localhost:3000/posts and give it a go.

Make it Look Pretty!

I’ve created a stylesheet, which we can use to make things look a bit more respectful. Create a file called layout.css in the public/stylesheets folder then add the following CSS code:

body
{
  font-family: tahoma, sans-serif;
  font-size: 18px;
  background-color: #4B7399;
  width: 100%;
  color: #ffffff;
  margin: 0;
  text-align: center;
}

#content
{
  width: 800px;
  margin: 0 auto;
  text-align: left;
}

.post
{
  padding: 5px 20px 5px 20px;
  background-color: #ffffff;
  margin: 20px 0 20px 0;
  color: #000000;
}

Finally, you will need to add stylesheet_link_tag call to the posts.html.erb layout file. As per below, the call should be placed in the head tag.

<head>
  <%= javascript_include_tag :all %>
  <%= stylesheet_link_tag 'layout' %>
</head>

OK! It doesn’t look that pretty, but it will do for our purposes.

Setting up a Home Page

To have the root URL (http://localhost:3000) direct the user towards your posts you will first need to delete the public/index.html file. Do this now.

The second thing you need to do is set up a route in your config\routes.rb file. Open routes.rb in notepad and add a new line to the end using map.root, as shown below.

ActionController::Routing::Routes.draw do |map|
  map.resources :posts
  map.connect ':controller/:action/:id'
  map.connect ':controller/:action/:id.:format'
  map.root :controller => "posts"
end

For more on routes, try the Rails API Documentation

Now if you browse to http://localhost:3000. The request will be routed to the posts controller.

Summary

This concludes the first part of the series. Depending on the popularity of this article, parts 2 and 3 will follow shortly.

What have we Learnt?

You’ve learnt how to carry out basic application design and how to use this design to work out what models are required. Further to this, you’ve learnt how to use the console to help with the development of your application. Finally, you used AJAX to perform asynchronous requests to the server.

Author: Phil McClure

Phil McClure is a Software Developer from Belfast, Northern Ireland. His main interests are software architecture, design patterns and how these can be applied to web development. Phil blogs at Therailworld. Follow him on Twitter.

Write for Us! We are looking for exciting and creative articles, if you want to contribute, just send us an email.

Comments Off more...

Everyday’s a school day – upcoming training classes on ASP.NET controls

I'm hijacking Mehul's blog today and I hope he'll forgive me. The reason is that I have something to say about our ASP.NET products: they are going to be the first to be covered by a course in our new training program!

I have been working on this first course for a while - you wouldn't believe the efforts that go into something like that, especially the first time round. Now we're finally (almost) there, and the title of our first course is this:

Business Applications with DXperience ASP.NET

We will shortly put more details online, syllabus, cost and all that. The gist of it is that this is a two-day training course which provides an overview of several of our ASP.NET products. Within those two days you will learn to use the products to create a web application with an external, public-facing part and an internal management part. As the title says, we'll view these topics from the perspective of a developer creating a business application, so it'll be about presenting data, allowing data input, analysis, reporting, ... and of course using all those "glue" elements that make a web site complete. This is training, so it's all about learning - seeing things demonstrated, sure, but also trying everything yourself and getting questions answered.

We are currently planning the first two dates for this course, so I can't tell you those yet. The rough timeframe is "end of August 2009", and one of the classes is going to be in Las Vegas for people in the US, the second one in Amsterdam for those in Europe. I'm hoping to see lots of you there - meanwhile, if you have any feedback to give, leave it here please!

Comments Off more...

jQuery PageSlide Plugin

PageSlide is a jQuery plugin which slides a webpage over to reveal an additional interaction pane. PageSlide is really easy to incorporate, unobtrusive and has been tested to fully work on IE7+, FireFox 2+, Safari 2+.

  • Sponsored Links

  •  

    June 2009
    M T W T F S S
    « May   Jul »
    1234567
    891011121314
    15161718192021
    22232425262728
    2930  
  • .

    Copyright © 1996-2010 Answer My Query. All rights reserved.
    iDream theme by Templates Next | Powered by WordPress