Topic: Tutorial needed

Can anybody forward me to a tutorial which will help me build a basic directory system

models {

classifieds, user, category

basic fields (two or free just for example)


Im using Sqlite3 with lighttd server on a mac I have no database management program for Sqlite3 so im just using the command line (i Term).


Im able to create an rails app :-

rails railslist -d sqlite3


create controllers:-

ruby script/generate model Classified


edit the migrate file:-

class CreateClassifieds < ActiveRecord::Migration
  def self.up
    create_table :classifieds do |t|
      t.column :title, :string
      t.column :price, :float
      t.column :location, :string
      t.column :description, :text
      t.column :email, :string
      t.column :created_at, :timestamp
      t.column :updated_at, :timestamp
    end
  end
  def self.down
    drop_table :classifieds
  end
end


then:-

rake db:migrate

etc

but then Im lost I can seem to write anything back to the database my form dose not work I've been trying for days

the tutorial im working off is call Rails Solutions - Ruby on rails made easy (2007)

this is the promblem area :-



class ClassifiedController < ApplicationController
  def list
    @classified = Classified.find(:all)
  end
   
  def show
    @classified = Classified.find(params[:id])
  end
 
  def new
    @classified = Classified.new
  end
 
  def create
      @classified = Classified.new(params[:classified]) 
      if @classified.save
          redirect_to :action => 'list'
      else
          render :action => 'new'
      end 
  end
   
  def edit
    @classified = Classified.find(params[:id])
  end
 
  def update
    @classified = Classified.find(params[:id])
    flash[:notice] = "Update Ads."
    if @classified.update_attributes(params[:classified])
      redirect_to :action => 'show', :id => @classified
    else
      render :action => 'edit'
    end 
  end
  def delete
  end
end



and this is my form:-

<!--new ads form page-->

<h1>Post new classified</h1>

   
<% form_tag :action => 'create' do %>
    <p><label for="classified_title">Title</label><br/>
    <%= text_field 'classified', 'title'  %></p>
    
    <p><label for="classified_price">Price</label><br/>
    <%= text_field 'classified', 'price'  %></p>
   
    <p><label for="classified_location">Location</label><br/>
    <%= text_field 'classified', 'location'  %></p>
    
    <p><label for="classified_description">Description</label><br/>
    <%= text_area 'classified', 'description'  %></p>
    
    <p><label for="classified_email">Email</label><br/>
    <%= text_field 'classified', 'email'  %></p>
    
    <%= submit_tag "Create" %>
    <% end %>
   
<%= link_to 'Back', {:action => 'list'} %>


please help, at the very less just point me to a work tutorial!


Regards

Re: Tutorial needed

What version of Rails are you using?

rails -v

Last edited by Delameko (2008-06-19 13:43:43)

Re: Tutorial needed

Delameko wrote:

What version of Rails are you using?

rails -v

Hi Delameko

Im running version 2.1.0

Re: Tutorial needed

Yeah, that tutorial you're running is quite out of date for Rails 2.1.  Some decent books for learning Rails 2 would be something like Agile Web Development with Rails (3rd Edition) or Simply Rails 2 from Sitepoint.

As for the code try running the following in a new project:

ruby script/generate scaffold Classified title:string price:float location:string description:text email:string

And have a look at what it generates.  Run your rake db:migrate and then load the server,  and then navigate your web browser to http://localhost:3000/classifieds and create a new classified.  That should get you started at least.

Re: Tutorial needed

You can search through this nice tutorial easily:

http://rapidshare.com/files/128050995/r … -2.1.0.rar