I installed IIS on my computer the other day because I'm doing some work for a client who is using ASP. When I tried to start up the server, I got this error message 'Unexpected Error 0x8ffe2740 Occurred'. Having no idea what error 0x8ffe2740 was I hit up google for some answers. Turns out Error 0x8ffe2740 means Port already in use. It would have been nice if they had just supplied a simple explanation in there error message. Is that too much to ask for?
5 comments
I was talking with Mat Harvard on gtalk last night and the idea of starting a Victoria Ruby Users Group came up. I had bought vicruby.com quite a while ago but hadn't had the time to develop it so I quickly whipped up a template for stikipad, changed my DNS and we now have a wiki for the newly formed 'Victoria Ruby Users Group'. We'll see how it goes. Not sure what the interest is going to be like in Victoria. It's not that big of a place. Hopefully we will have our first meeting in the new year. Talk/presentation ideas anyone?
1 comment
I've been playing with liquid templates in rails now for about a month. When I first started there wasn't a great deal of nice, easy to follow, step by step tutorials. There are a few good wiki's but putting all the information together can be a bit quite a bit of work.This guide is meant to be super simple and easy to follow. It will be a start to finish guide on how to install and use liquid in you ruby on rails application. This is part one. Enjoy!
First let's create our project and add the liquid rails plugin.
server:/# cd /rails
server:/# rails liquid
server:/# cd liquid/vendor/plugins
server:/# svn export svn://home.leetsoft.com/liquid/trunk/liquid/
server:/# cd ../../
server:/# rake rails:freeze:edge
server:/# ruby script/server
After starting the server you should be able to see the default rails page.
Now that you have your server up and running create your database and add the right settings to your database.yml.
Now let's get rid of the default rails page and add a couple routes so we'll be able to see our new page that we are going to create a bit later.
server:/# rm public/index.html
server:/# pico config/routes.rb
Add the following lines to the routes.rb file.
1
2
|
map.resources :posts
map.connect '', :controller => "posts" |
Now we need to create our database table. We are going to create a super simple blog, so let's add a posts table.
server:/# cd db
server:/# mkdir migrate
server:/# cd migrate
server:/# pico 001_create_posts.rb
Here is our code for the migration
1
2
3
4
5
6
7
8
9
10
11
12
13
|
class CreatePosts < ActiveRecord::Migration
def self.up
create_table :posts do |t|
t.column :title, :string
t.column :body, :text
t.column :created_at, :datetime
end
end
def self.down
drop_table :posts
end
end |
Now lets run a migration to generate the table in our database. After that we'll create our post resource and then restart the server to make sure that everything is still working properly.
server:/# rake db:migrate
server:/# ruby script/generate scaffold_resource post
server:/# ruby script/server
You should now be able to go to http://localhost:3000 and see the scaffolding for your new site. Now all we have to do is add some liquid.
Let's edit our posts controller first.
server:/# pico app/controllers/posts_controller.rb
In the index method let's change the default find statement.
1
2
|
#@posts = Post.find(:all)
@posts = Post.find(:all).collect(&:attributes) |
This last line might be a bit confusing. Basically all that it is doing is grabbing all of our posts and then creating hashes for each one with all of its attributes. Since liquid likes to use hashes we need to do this conversion.
Now that we have some hashes to work with we need to create our liquid view.
server:/# cd app/views/post
server:/# mv index.rhtml index.liquid
server:/# pico index.liquid
We're going to simplify our index view a little and take out all the editing capabilities and add some liquid methods. For liquid syntax,
check out this site.
1
2
3
4
5
6
7
8
9
10
|
<h1>Our Posts</h1>
<div id="posts">
{% for post in posts %}
<div class="post">
<h2>{{ post.title }}</h2>
<p class="date">{{ post.created_at | date:"%b %d, %Y" }}</p>
<p>{{ post.body }}</p>
</div>
{% endfor %}
</div> |
Ok .. now that that's all done we can add a couple records to the database. When we restart the server we should be able to see the records.
We should probably add our main layout as a liquid template as well.
server:/# pico app/controllers/posts_controller.rb
Add this line just after the class definition
Now we just have to make the default liquid template in our views/layout directory.
server:/# pico app/views/layouts/default.liquid
Here is what we're going to start with.
1
2
3
4
5
6
7
8
9
10
11
12
|
<!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>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title>My Liquid Enabled Site</title>
<link rel="Stylesheet" href="/stylesheets/scaffold.css" type="text/css" media="screen" />
</head>
<body>
{{ content_for_layout }}
</body>
</html> |
Now your on your way to becoming a pro liquid user.
Stay tuned for our next installment, Liquid Drops.
For more information on liquid check out these resources
7 comments