RailsFan R. wrote:
Hassan S. wrote:
On Sat, Jun 26, 2010 at 11:56 AM, RailsFan R. [email protected]
wrote:
given this scenario, if this is an existing db, how could we create the
CRUD pages for this without doing migration.
There’s an active_scaffold plugin that (I believe) replicates the old
1.x Rails dynamic scaffolding. I’ve never used it, but it might work.
Otherwise, you’ll just have to write your views, tests, etc. yourself.
HTH,
Hassan S. ------------------------ [email protected]
twitter: @hassan
i’ll check active scaffold plugin. as i googled, a few had specified
that it isn’t working as specified. i am yet to delve into it. will keep
it posted as i delve into it.
apart from that… today, the very first page in the CRUD pages started
working.
Created a “list” page to list all categories and it listed all.
used the steps from:
Ruby on Rails - Views
in the similar approach , will try to create the other CRUD pages too.
here are the pages:
################### model ###########################
##################category.rb########################
…/app/models# more category.rb
class Category < ActiveRecord::Base
set_table_name ‘category’
set_primary_key “category_id”
def self.find_all_categories
find(:all)
end
end
#####################################################
##################controller#####################
##############category_controller.rb#############
app/controllers# more category_controller.rb
class CategoryController < ApplicationController
def index
“List all categories”
list
render:action=>‘list’
end
#— List–
def list
@categories=Category.find_all_categories
end
end
##################################################
###################### views######################
######################list.erb####################
…/app/views/category# more list.erb
list template for category
<% if @categories.blank? %>
There are not any categories currently in the system.
<% else %>
These are the current categories in our system
<% @categories.each do |c| %>
- <%= link_to c.category_title, {:action => 'show', :id =>
c.category_id} -%><
/li>
<% end %>
<% end %>
####################################################
Summary:
For one controller and one action, these three files were
created/modified:
Currenlty, these three flles does only one action, which is “listing”
all categories from the “category table”. I think atleast one part of
the CRUD is done. can we say so? I guess so.
Files modified:
model/category.rb
controller/category_controller.rb
views/list.erb
the next step is to prep for the “edit” action for category.
please let me know if i’m missing any.
thanks again,
radha.
Update to this post:
“show” action for this category has been done. I think this is one among
the CRUD pages. (create, read, update, delete)
I guess, show => read
The following pages are created/modified for this “show” action for
“category” controller:
app/controller/category_controller.rb ( added show def to this file)
app/views/category/show.erb (new template created. this is a new file)
################## app/controller/category_controller.rb ###########
def show
@category=Category.find(params[:category_id])
end
#######################################################################
################### view ##########################################
/app/views/category# more show.erb
<%= @category.category_title %>
Title: $<%= @category.category_title %>
Short_Description : <%= @category.category_short_desc
%>
Long_Description : <%= @category.category_long_desc
%>
Status : <%= @category.status%>
Created Date: <%= @category.dt_created %>
Modified Date: <%= @category.dt_modified %>
Created User: <%= @category.user_created %>
Modified User: <%= @category.user_modified %>
<%= @category.category_title %>
<%= link_to 'Back', {:action => 'list'} %>
################.#################################
Summary:
To create the “show” action, controller file was modified and a new view
template was created.
Model remains inchanged.
So, this works!
The link created in the abover list.erb, shows this show.erb page when
clicked.
The link works and that means the “show” action is working.
Please let me know if I’m missing any in this route.
Just thought of updating this here, as this inspires me to move forward,
thinking i have people here to discuss with.
that makes all the big difference.
I will keep you all posted.