February 23rd, 2007
Adding a rating system to your rails application is easy even the Grunt can do it! Check it out here
Follow the directions carefully and you should be up in no time.
The only tricky part that i came accross was the div part in the view.
basically just replace article.id with the id of whatever model you are displaying in your view, and also place the type in the :asset definition. What this does is that the particular div will get updated without a whole page refresh and the asset is used to keep track of the type in the database.
February 23rd, 2007
What is a website without the ability to add comments to something? Well acts_as_commentable makes this really easy. Check out this thread on the ruby forum here
To install:
ruby script/plugin install
svn://rubyforge.org//var/svn/commentable/acts_as_commentable
In the readme there is a sample migration you will need to use, with
directions on how to modify it if need be. I’m still learning how the
plugins work, and do not know if there is a way to autogenerate this.
Once the migration is completed and ran, you can just add:
acts_as_commentable to those objects you want to comment on and you’re
all set.
Lets say you have a Person object:
class Person < ActiveRecord::Base
acts_as_commentable
end
Then you have a person:
p = Person.find(:first)
Create a comment:
c = Comment.new
Fill out the comment
c.name = “Name of Commentor”
c.content = “What they wrote”
then add it to your object:
p.add_comment©
to remove a comment:
p.remove_comment©
February 23rd, 2007
For this task, the grunt is currently using acts_as_attachment. Information about the plugin can be found here . Follow the directions carefully and you can easily add file upload option to your rails application. Al the files are stored in the public folder in its own id directory. Also whats cool about it is that acts_as_attachment also creates thumbnails of each photo you upload. So in your view you can have something like this…assume that artices has one articlephoto
<% for articles in @toparticles%>
<= article.title>%>
<%if article.articlephoto != nil %>
<= image_tag article.articlephoto.thumbnails0.public_filename>
<% end %>
easy aint it?
February 17th, 2007
just realized the zip files went missing when changing domains. will update asap!
Come check them out…. i havent been able to use the zip option when uploading and using the theme, but you can unzip, upload the theme directory to the themes folder, and then select the theme via the admin. in most of the themes, ‘pages’ acts as the menu navigation (like about, gallery, etc…) and categories are the side menu.
Read the rest of this entry
February 17th, 2007
Installing mephisto is a straightforward process but can be a little challenging if you are new to web development(remember z’Grunt is also new as well) or new to working in a terminal.
My current host that I am using, who I plan to use for a long time because of the awesome service and helpful forum, is hostingrails.com. I assume that most shared hosting services come with a ‘control panel’ where you can graphically create mysql databases. Here is what I did…
Create the database
- Go to your mysql icon in your control panel and create a database. You can title it mephisto if you’d like.
- Now, create a user and password with all the necessary permissions and add this user to your newly created mephisto database.
- Take note of the user name and database name that was created. Some hosting companies append your login name to the username and database name
Create a subdomain (optional)
##This is pretty straight forward. Just go to the add subdomain option and create a place holder for your blog. so you can have myphisto.myhotsauce.com if you like, or skip this step if you plan on using your main domain name.
Downloading mephisto
- Log into your web account via a terminal window. In my case, I need to ssh (“secure shell”) login to my account. If you don’t currently have ssh, you can download putty if your on a windows machine. I am using a mac so ssh capability comes built-in. ssh is basically a secure way to communicate information to another computer. The ip number to use should be found in your account details. The command i type is “ssh username@ip-number”
- Once logged in, create a directory by typing ‘mkdir mephisto’. You can use whatever name you like.
- Now lets download the latest version of mephisto. You can find the latest version by going here As of now, the latest version is 0.7.3. Grab it by typing this:
“svn co http://svn.techno-weenie.net/projects/mephisto/tags/rel-0.7.3 mephisto” What this does is it downloads mephisto and places it in your mephisto directory that you just created in step 2.
Mephisto install
- Now you will make some configurations. type ‘cd mephisto’ and type ‘ls’. You will now see all the directories for mephisto. In there you will see a folder titled config. type ‘cd config’. Now remember when the Grunt said to take note of your database and database user? here is where we will use it. Open the file database.yml by using a terminal editor. In my case all i needed to do was type “pico database.yml”. In this file, you can delete everything except for the production and the lines of code underneath it. You can use ‘control k’ to cut the lines faster and when your finshed editing the file, just use control x and save.
production:
adapter: mysql
database: databasename
username: username
password: password
host: localhost
- Next open the environment.rb file and delete the pound symbol in front of ”#ENV[‘RAILS_ENV’] ||= ‘production’”
- Now that is done, go back up 1 directory by typing ‘cd ..’
- Option, if your host is not using the latest rails 1.2, you may need to freeze it by typing “rake rails:freeze:edge”.
- Once that is complete, go to your public directory by typing ‘cd public’. Type “whereis ruby” and take note where ruby is installed in your hosting service. In my case, ruby is installed at /usr/local/bin/ruby. Type “pico dispatch.cgi”. In the file you will see a #!/opt/local/bin/ruby…change this to where ruby is installed on your machine, in my case #!/usr/local/bin/ruby.
- Next open the .htaccess file and change this line of code “RewriteRule ^(.)$ dispatch.cgi [QSA,L]” to “RewriteRule ^(.)$ dispatch.fcgi [QSA,L]” and comment out the line of code that says ’# AddHandler fastcgi-script .fcgi’. save and exit
- Type this as well in the public folder to make sure the dispatch files have the correct permissions, ” chmod 755 disp*”
- Now go back up to your mephisto root directory(cd.. if you forgot how to move up) and type “rake RAILS_ENV=production db:bootstrap” . This now creates all the tables in your database that your mephisto blog will be using. If you run into any errors, most likely you entered the incorrect information in your database.yml file, or didn’t add the correct permissions to the user.
The home stretch
- Now, if you are installing mephisto on a subdomain, go to your public_html directory in your home folder. Delete the symlink that was created for your subdomain. If you choose mephisto as a subdomain, just type “del mephisto”.
- Now create the simlink to your mephisto blog by typing ‘ln -s ~/mephisto/public ~/public_html/mephisto’. What this does is that when someone visits mephisto.mypage.com, it will go to your mephisto blog page.
Now point your browser to your url like mephisto.myhotsuace.com and all should be well.
This may seem like alot of steps but really its not that much. As you get more comfortable working in a terminal, it becomes easy to configure things in rails. Hope this helps anyone and if there are mistakes here, please drop me a message so I can improve it. Thanks!
February 13th, 2007
When I first started working with rails, I could not understand why use migrations vs working with databases the plain old brute force way of manually mysql’ing everything. well lets just say the grunt is now happy to use them. What are migrations? migrations is a way to add, modify, delete, rename, reconfigure tables and field names within tables easy. cool thing about migrations is that you dont have to worry about ruining tables since you can move back and forth between versions of your database history. therefore, if later during the lifetime of your website you decide to add a new category field to your table of food types, you can add new columns or rename old ones easily. Also, if you created a new table and realize that that table or change to a field name was a mistake, all you would need to do is type a command and step back a version. really easy, so easy a grunt can do it!
February 10th, 2007
With the help of the helpful folks over on http://www.ruby-forum.com/forum/5 forum, the grunt learned how to search for data in a table if a certain grandparent field matches. in the previous post, i clipped a picture from a site that i developed of the searchbox. basically, the search field has a category parameter that i use to select the particular category a user wants to see. the main category has many sub categories which has many ‘whatever you want here’. here is what the grunt did.
.
in the model, i indexed the grandparent main_category.
acts_as_ferret :fields =>[“title”, “howto”, :main_category]
def main_category
subcategory.maincategory.name
end
in the view:
<= start_form_tag(:action=>‘search’)>
<= text_field_tag(:search)>
<= select(:searchbox, :category, %w{technology food music photography music })>
<= submit_tag “Search”>
<= end_form_tag>
in a controller or wherever you would like to store the search function
def search
@viewObj = paginate_collection Posts.find_by_contents(”#{params[:search].to_s } +main_category: #{params:searchbox}”)
end
now @viewObj will now contain all the Posts where its grandparent (main category) is selected.
February 10th, 2007
one of the first ruby on rails plugin that the grunt used was acts_as_ferret. acts as ferret is an awesome plugin that makes searching through tables gruntastically easy. Information about the plugin can be found at http://projects.jkraemer.net/acts_as_ferret/ . Installation is a breeze. I believe I used the latest software version.
