McGivrer's Home

life of french web developer

  • Hobo: Step 4 - adding a cover image

    • 16 Mar 2010
    • 0 Responses
    •  views
    • development hobo image rad rails tutorial web
    • Edit
    • Delete
    • Tags
    • Autopost
    As we've now get a running web application to manage our library, I propose you to add an image field management to our Book model.
    To manage this part, we are going to need 3 things:
    • an imaging tool like mini_magick or image_magick,
    • the paperclip plugin for rail
    • and the paper_clip_with_hobo to be used with Hobo framework.
    1. The image tool
    My choice go to imagemagick, but i know that this is working well with others tools like

    2. Paperclip plugin
    You will find very interesting infoirmation about this plugin usage at this page: http://jimneath.org/2008/04/17/paperclip-attaching-files-in-rails/
    And you  will be able to download it from http://github.com/thoughtbot/paperclip

    To install this small plugin, just go to your hobo application root path and run the following command:

    script/plugin install git://github.com/thoughtbot/paperclip.git
    Now you have downloaded it, you are ready to use it.

    3. Get the paperclip_with_hobo
    Just fololowing the same process, you have to download/install this rails plugin from git:

    script/plugin install git:http://github.com/tablatom/paperclip_with_hobo.git ok. let's apply some model modification to our Book modelisation.Book.rbwe need to add some new field to our app/model/book.rb class Book < ActiveRecord::Base hobo_model # Don't put anything above this  fields do title :string  author :string year :integer  resume :text note :integer  timestamps end   has_attached_file :cover, :styles => {                   :full=>"600x600>",                  :medium => "300x300>",                   :thumb => "100x100>",                  :mini => "60x60>" },                  :path => " :rails_root/public/media/books/covers/:id/:style.:extension",                 :url => "media/books/covers/:id/;style.:extension"  ...end Adding such "has_attached_file" field to our Book model add in reality 4 fields to our database model after running the rake db:migrate standard rails operation : see db/migrate/20100221172242_add_attachements_cover_to_book.rb migration fileclass AddAttachmentsCoverToBook < ActiveRecord::Migration  def self.up add_column :books, :cover_file_name, :string  add_column :books, :cover_content_type, :string add_column :books, :cover_file_size, :integer  add_column :books, :cover_updated_at, :datetime end  def self.down remove_column :books, :cover_file_name  remove_column :books, :cover_content_type remove_column :books, :cover_file_size  remove_column :books, :cover_updated_at end endOk, now our model is updated, database too. we are ready to modify some dryml file to show this image. Go to app/views/taglibs/application.dryml and add the following declaration:At file beginning in existing "include" lines:<include src="paperclip" plugin="paperclip_with_hobo"/> And at end of file :<extend tag="form" for="Book">        <old-form merge multipart>                 <field-list fields="title, author, year, resume, note, cover, category" param/>         <div param="actions">  <submit label="#{ht 'books.actions.save', :default=>['Save']}" param/><or-cancel param="cancel"/>  </div>        </old-form> </extend>This is a view modifier for a Book, adding the cover field and removing the 4 database fields. Then, modify the card dryml for Book model, in the same previous file (application.dryml) :<extend tag="card" for="Book">   <card>    <h5>     

       

                <view:resume />     </p>    <p>       <%= I18n.t :uploaded_label %><br />      <view:created_at format="%B %d, %Y" /> by <you:user />.     </p>    <delete-button class="actions" />      </card> </extend>Let's test our new cover field !

    • Tweet
  • RedCar, it's not a red car !

    • 7 Mar 2010
    • 0 Responses
    •  views
    • code editor hobo java linux multiplatform rails tools windows
    • Edit
    • Delete
    • Tags
    • Autopost
    RedCar is a brand new programmer's editor ruby oriented, and ruby developed.
    And on of the main feature of this new text editor, it's to be JRuby compatible natively !  A good news for the multiplatform world.

    Screenshot-redcar

    to be tested to help dev team to improve this cool programmer's tool.

    Is it possible to optimize such editor for Rails and Hobo ?

    McG.
    • Tweet
  • Hobo: step2 and 3, add categories and some relation

    • 15 Feb 2010
    • 1 Response
    •  views
    • hints hobo rad rails relation tutorial web
    • Edit
    • Delete
    • Tags
    • Autopost
    Ok, we have just created the first step of our library.
    Now we have hundreds of books, maybe we can dispatch all these books in some categories ?
    Ok, l'est add categories to our web app "My Library"
     script/generate hobo_model_resource category name:string sorder:integer
    And we hjev to update the databse with our new model:
     script/generate hobo_migration
    don't forget the 'm' option to run the migration right now !
    ok, just for fun, run the application with a 
     script/server
    browse to http://localhost:3000/ and go to the "Categories" tab..  
    1.View the Category tab
    Hobo_07_add_categories
    2.and add a new "Novel" category
    Hobo_08_add_a_category
    yes ok, nothing really new here.  It's working just like Books.
    Let's dye into the code:
    We are going to add the link between Book and Category, knwoing that a category can have many book, and one book belong to one category.
    Open the file book.rb and just after fields declaration, add the following "belongs_to": 
     class Book < ActiveRecord::Base

      hobo_model # Don't put anything above this

      fields do
        title  :string
        author :string
        year   :integer
        resume :text
        note   :integer
        timestamps
      end

      belongs_to :category
      ...
     end
    Open now the category.rb and add the small "has_many" property:
     class Category < ActiveRecord::Base

      hobo_model # Don't put anything above this

      fields do
        name   :string
        sorder :integer
        timestamps
      end

      has_many :books
      ...
     end
    we have to generate a small migration to add this field into the Book data model.
     script/generate hobo_migration
    note: choose the 'm' option to apply modifications.
    and start the server to test !
     script/server
    let's browse the Books page
    Hobo_09_add_links_category_boo
    And choose one of the created book, you can see the new "Category" field at end of page.
    Click the "edit book" link and you will be invited to change the value for category wich is currently set with the default "(No category)".
    Hobo_10_link_book_to_category
    ok, back to your code editor and open the file category_hints.rb. and replace all the commented lines by the following single line. 
     class CategoryHints < Hobo::ViewHints

       children :books

     end
    Telling that Category has Books has children will modify automatically the Category page, showing the number of book attached to a category.
    1. What's new in the "Categories" page
    Hobo_11_add_category_hints_boo
    2. Let's see the detail of a Category
    Hobo_12_showing_category_detai
    3. And on the Book side, a new top/left link appear "<<Novel"
    Hobo_13_book_details_about_cat
    you can see that with  very small add to the generated code, you considerably inflect the default behaviour of the application and the links in the model.
    Even if model link declaration and manipulation already exists in Rails, Hobo brings the corresponding mechanisms for the UI side.
    Next, more to be discover in the dryml taglib and tags personalization.
    Hobo man.
    Note: please find attached bellow the project in each step state, from step 1 to step 3.

    Click here to download:
    MyLibrary-step-1.tar.gz (120 KB)

    Click here to download:
    MyLibrary-step-2-categories.tar.gz (122 KB)

    Click here to download:
    MyLibrary-step-3-hints.tar.gz (128 KB)

    • Tweet
  • My first Hobo application: My Library

    • 15 Feb 2010
    • 1 Response
    •  views
    • firstapp framework hobo installation rails
    • Edit
    • Delete
    • Tags
    • Autopost

    Hello, just as I have published the previous article about Hobo, discovering the full featured rails over layer framework, I can't wait to publish my first test: creating a very simple Web Application to manage a library.

    The first step is just to provide an interface to list all my books
    So please, follow the guide !
    Installation of the framework
    Just run the following command in your prefered terminal (gnome-terminal for example in Ubuntu):
     sudo gem install rails
     sudo gem install hobo
     sudo gem install sqlite3-ruby -v=1.2.3
     sudo apt-get install sqlite3
    First App
    Now we are going to create our first Hobo application
     hobo MyLibrary
    focus in the just create app directory
     cd MyLibrary
    And now create our first datamodel :  a book modelisation
     script/generate hobo_model_resource book title:string author:string year:integer resume:text note:integer
    now, we are going to create this model persistence into the default sqlite3  database
     script/generate hobo_migration 
    (choose the 'm' option)
    Ok, done.  now run the rails server (WebBrick):
     script/server
    browser on http://localhost:3000/
    Look at the title of the application :"My Library" !  Just because we call our project "MyLibrary" (without any space), Hobo kindly titled our welcome page with a beautiful "My Library" in a plain old good english. 
    Identify yourself by creating the first user account which will act as administrator for this new application.
    And now start playing with your books collection !
    1. your first connection to "My Library"
    Hobo_01_first_start
    2. The welcome page (also modifiable 
    Hobo_02_default_welcome_page
    3. Let see our books collection
    Hobo_03_books_page
    4. Go and create our first book in our collection
    Hobo_04_book_default_creation_
    5. Fill all the fields, and "Create Book"
    Hobo_05_first_book
    6. and it's done, the first book is ready to be parsed
    Hobo_06_book_just_created
    Yes I am impressed to discover how the Hobo dev team has been very careful with all details.
    The new Hobo player.
    • Tweet
  • How to install rmagick extension to ruby on Ubuntu ?

    • 26 Jan 2009
    • 0 Responses
    •  views
    • file_column imagemagick rails rmagick ruby ubuntu
    • Edit
    • Delete
    • Tags
    • Autopost
    That's a very good question as the rubygems embedded in the debian package is a limited edition where you are not able to make an "update --system".

    So first thing to do:

     sudo apt-get remove rubygems

    Then, from www.rubyonrails.com, follow the rubygems installation tutorial:
    - download the archive delivered from rubyforge,
    - tar -zxvf rubygems-1.3.1.tgz

    and:
     cd /rubygems-1.3.1
     sudo ruby setup.rb

    and follow with a :
     sudo gem update --system

    OK, rubygems is now up to date.

    Go on installation of rmagick:

     sudo apt-get install ruby1.8-dev
     sudo apt-get install g++ automake autoconf
     sudo apt-get install libmagick++10
     sudo apt-get install libmagick++9-dev
     sudo gem install rmagick

    and then you will get the following console output:

    frederic@nostromo2:~/Logiciels/development/ruby/rubygems-1.3.1$ sudo gem install rmagick
    Building native extensions.  This could take a while...
    Successfully installed rmagick-2.9.0
    1 gem installed

    And now, you will be able to use the Rails plugin named file_column; cd into your rails project:
     cd myprojectsrails

     script/plugin install http://opensvn.csie.org/rails_file_column/plugins/file_column/trunk

    And enjoy !

    • Tweet
  • About

    Java/J2EE Expert
    Technical Manager
    Web Standard evangelizer

    114907 Views
  • Archive

    • 2012 (4)
      • January (4)
    • 2011 (53)
      • December (5)
      • November (1)
      • September (4)
      • August (4)
      • July (5)
      • June (2)
      • May (11)
      • April (11)
      • March (5)
      • February (3)
      • January (2)
    • 2010 (51)
      • December (2)
      • November (2)
      • October (1)
      • September (3)
      • August (8)
      • July (4)
      • June (15)
      • May (3)
      • April (2)
      • March (5)
      • February (5)
      • January (1)
    • 2009 (29)
      • December (1)
      • November (5)
      • October (6)
      • August (1)
      • July (4)
      • June (2)
      • May (1)
      • April (4)
      • March (2)
      • February (1)
      • January (2)
    • 2008 (39)
      • December (1)
      • November (5)
      • October (8)
      • September (8)
      • August (8)
      • July (9)

    Get Updates

    Follow this Space »
    You're following this Space (Edit)
    You're a contributor here (Edit)
    This is your Space (Edit)
    Follow by email »
    Get the latest updates in your email box automatically.
    Loading...
    Subscribe via RSS
    FacebookFlickrPicasametaweblog