Sunday, November 04, 2012

6.5 years later

So it's 6.5 years since I last did any Ruby on Rails. After getting the book Agile Web Development with Rails I didn't go too much farther.

Well, I decided to try again and my how things have changed. The book is pretty much out of date. It was stinking ridiculous getting set up with RoR again. I tried Apache, but could never get it to work. The book says to run "Ruby script/server" to start up WEBrick so that you can see your app at localhost. It took 2 hours for me to finally figure out that it is now "Rails server." There is no documentation anywhere that says in a simple way how to get up and running. I had to install several other gems just to get "Rails server" to work.

But finally, I got it working and am ready to dive in again. Wish me luck.

Tuesday, January 03, 2006

agile web development

so, i went about as far as i knew how to go with the blog. i went through almost every tutorial i could find on the internet--not very many at all. so i ordered Agile Web Development with Rails by Dave Thomas and David Heinemeier Hansson, the guy who created Rails, and have begun to go through the book. i went through the first seven chapters yesterday--pretty much a refresh on everything i've learned so far, but i've got a ways to go in the book. i'm sure i'll learn more as i go through it.

Monday, November 14, 2005

script.aculo.us effects

script.aculo.us has some javascript effects that are installed with rails. i just figured out how to use them. i put a highlight on the recent posts part of the menu for when it expands. i also put a "less" link under the expanded recent posts that shrinks back to just 5 recent posts when clicked. didn't take too long to figure out how to do that. i just made another function called less_cats, plus a view associated with it. you can see the hightlight code:

link_to_remote( "more", :update => "recent_posts",
  :url =>{ :action => :more_cats },
  :complete => visual_effect(:highlight, "recent_posts"))

ajax in menu

i figured out how to incorporate ajax into the recent posts section of the menu. i have it set to only show 5 recent posts by default. i put a link that says "more" under the five posts. when clicked, it expands the list to 20 automatically. very nice.

i probably went about it the wrong way, but hey, it works. what i did was put a link_to_remote function in the index under the recent posts list. i put the recent posts in its own div--recent_posts. here's what the code looks like:

link_to_remote( "more", :update => "recent_posts",
  :url =>{ :action => :more_cats })

so i made a function in the controller called more_cats that declares a @recent variable to find_by_sql the 20 most recent posts:

def more_cats
  @recent = Post.find_by_sql "SELECT id, title FROM posts
  ORDER BY created_on DESC LIMIT 20"
end

that worked, except for that it was using the same template and loading the whole header and footer part into the menu. i found out how there's an :except attribute that can be passed to the layout call. so all i had to do was this:

layout "posts", :except => :more_cats

now it doesn't use a layout for more_cats and it works fine.

Thursday, November 10, 2005

why was that so difficult

okay, so i was thinking way too deep into this whole 5 most recent posts thing. all i had to do was take out the WHERE clause and put a LIMIT 5 on the end.

SELECT id, title FROM posts ORDER BY created_on DESC LIMIT 5

and there you go.

i also added a links table to the database to put links into the menu. for the controller, i added a @links variable and used another find_by_sql statement:

@links = Link.find_by_sql "SELECT name,url FROM links ORDER BY 'name'"

then, of course, i added the code to the index to display them. same kind of loop as the rest of the menu.

for link in @links
<li><a href="<%= link.url %>"><%= link.name %></a></li>
end

not working

okay, so when i restart the server, the last 5 recent posts thing doesn't work anymore. i need to figure out how to make it work without doing the LAST_INSERT_ID thing.

Wednesday, November 09, 2005

recent posts limited

i found out how to limit the number of recent posts in the menu. there is a find_by_sql function in ruby. i added the following to the index section in the controller:

def index
...
@recent = Post.find_by_sql "SELECT id, title FROM posts where id >= (LAST_INSERT_ID()-4) ORDER BY created_on DESC"
end

before, i was sharing the variable @posts to display the actual post content and also the recent posts links in the menu (@post.title). so i made the @recent variable to use for just the menu and limit the amount of records to the latest 5 in descending order.

so far

this is what i have so far...

ruby blog

i figured out how to include images, so i made a header.

categories

i've added categories. only one category per post, though. not sure about how to go about doing more than one. i also need to figure out how to link the category names in the menu to only show the relevant posts when clicked. i also figured out how to add the category in the post info under each post that each one is in. it came out like this (i'm sure there's an easier way):

<% @categories.each do |category| %>
<%= category.name if category.id == post.category_id %>
<% end %>

i created a categories table in the database and added a category_id field to the posts table. that's how the categories are linked to the posts.

created on

i changed the format of the time and date where it shows under each post by using strftime. this is what i did:

<%= post.created_on.strftime("%m.%d.%Y at %I:%M%p") %>

well, after i did it, it changed all the previous post dates to 9:30AM on today (11.9.05). strange. i have no idea why it did that.

ajax on rails

i went through oreilly's ajax on rails tutorial. i can't believe how easy it is to use ajax with ruby on rails built in functionality. very nice.

what i want to do now is incorporate ajax for the menu. i'm trying to figure out how to paginate the recent posts to say, five or so, then have the pagination links at the bottom and when clicked will XMLHttpRequest the next 5 recent posts and replace the current links with new links. hmmm... i tried mentally going through it to figure it out, but i can't quite grasp how to do it yet.

ie problems with styles

of course, what i have so far looks whack in ie. i don't really know what to do except try some of the ie bug fixes in css.

progress

i've made progress on the template. i actually got the menu styles right by a little bit of wordpress style reference and my own trial-and-error. haven't had much experience styling lists.

i really want to get more into the ruby syntax. i'll probably need to get a book that deals specifically with ruby and data manipulation.

i figured out how to put a "recent posts" part in the menu. i just copied the ...

<% for post in @posts %>

...

<% end %>

... code from the main post listings and used it in the menu. there has to be a way i can make a function for that in the controller so that i minimize the amount of code in the index.rhtml file. i'm also not sure about how to only show like 10 recent posts rather than all of them without doing pagination.

images

i'm not sure about how to show images. i know how to show images, but i don't understand how to link to them if all of the view files are under the app folder. i don't know how to link to public/images from there. i know the stylesheet from public/stylesheets is used, because i've been editing it, but i'm not sure how it's linked to the app folder.

working on template

right now, i'm trying to figure out the templates and the syntax for ruby, like displaying only the fields i want in a record rather than just looping through and displaying each field.

ruby on rails

i've installed apache, mysql, ruby, rails...everything i need to learn ruby on rails. i've gone through a couple of tutorials by o'reilly, and now i've picked my first project to be a blog. you can't view it because it's running on apache on my machine, but i created this blog to post all of the posts from the blog that i'm creating in ruby on rails. basically, you can follow my learning experience as i go through this.

i won't edit the timestamps on any of the old posts that i put on here because i don't feel like it. i'm just gonna copy and paste what i have so far (about 10 i guess), then i'll update this blog as i update the ruby on rails blog on my machine.

so, beginning with the next post, you can see my thoughts and problems as i progress.