Hi team, I''m a very newbie RoR user from Spain and I''m
developing a
blog''s CMS. Why RoR?, coz I think it''s an amazing framework
with many
posibilities, portable and really powerful, with a young and optimist
community, and taking my project I''ve prefered his structure in front
of
LAMP. Another thing is that I''ve liked to surprise my masters with this
novel framework. I wish come here to contribute when my application is
finished and when my knowledge in RoR grows.
By now I need some basic help (some directives) about blog creation.
I''ve developed account administration with auth_generator plugin and
touching some code, but I don''t know how can I make every user will
create and configure only one blog at a time (it''s 1 user = 1 blog, 1:1
relation).
CONSIDERATIONS:
1 user has 1 blog
1 blog has 1 style and belongs to 1 category
1 blog has many articles
1 blog has many links
1 article has many comments
MySQL database script:
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
`id` int(11) NOT NULL auto_increment,
`login` varchar(80) character set latin1 default NULL,
`cryptpassword` varchar(40) character set latin1 default NULL,
`validkey` varchar(40) character set latin1 default NULL,
`email` varchar(100) character set latin1 NOT NULL default
'''',
`newemail` varchar(100) character set latin1 default NULL,
`ipaddr` varchar(15) character set latin1 NOT NULL default
'''',
`created_at` datetime NOT NULL default ''0000-00-00
00:00:00'',
`updated_at` datetime NOT NULL default ''0000-00-00
00:00:00'',
`confirmed` tinyint(1) NOT NULL default ''0'',
`domains` text character set latin1 collate latin1_bin NOT NULL,
`image` text character set latin1,
`firstname` varchar(40) character set latin1 NOT NULL default
'''',
`lastname` varchar(40) character set latin1 NOT NULL default
'''',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_spanish_ci;
DROP TABLE IF EXISTS `blogs`;
CREATE TABLE `blogs` (
`id` int(11) NOT NULL auto_increment,
`category_id` int(11) NOT NULL,
`style_id` int(11) NOT NULL,
`title` varchar(255) character set latin1 default NULL,
`url` varchar(255) character set latin1 default NULL,
`created_at` datetime default NULL,
`updated_at` datetime default NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_spanish_ci;
DROP TABLE IF EXISTS `articles`;
CREATE TABLE `articles` (
`id` int(11) NOT NULL auto_increment,
`title` varchar(255) character set latin1 default NULL,
`excerpt` text character set latin1,
`body` text character set latin1,
`allow_comments` tinyint(1) NOT NULL default ''1'',
`published` tinyint(1) NOT NULL default ''1'',
`created_at` datetime default NULL,
`updated_at` datetime default NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_spanish_ci;
DROP TABLE IF EXISTS `comments`;
CREATE TABLE `comments` (
`id` int(11) NOT NULL auto_increment,
`blog_id` int(11) NOT NULL,
`email` varchar(150) character set latin1 default NULL,
`author` varchar(255) character set latin1 default NULL,
`body` text character set latin1,
`created_at` datetime default NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_spanish_ci;
DROP TABLE IF EXISTS `categories`;
CREATE TABLE `categories` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(255) character set latin1 default NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_spanish_ci;
DROP TABLE IF EXISTS `styles`;
CREATE TABLE `styles` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(255) character set latin1 default NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_spanish_ci;
DROP TABLE IF EXISTS `links`;
CREATE TABLE `barbatos`.`links` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(255) character set latin1 default NULL,
`url` varchar(150) character set latin1 default NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_spanish_ci;
After creating scaffold with script generator I''ve touched models like
this:
/app/models/blog.rb
class Blog < ActiveRecord::Base
belongs_to :category
belongs_to :user
...
end
/app/models/user.rb
class User < ActiveRecord::Base
has_one :blog
...
end
And at the end I''ve touched auth_generator account menu (from layout)
adding a link to new blog:
<div class="menu">
...
<%= if @user and @user.ident == true
link_to(image_tag("#{@app[''controller_name'']}/letsblog",
:border => 0), {:controller => "admin/blog", :action =>
"new" } )
end %>
</div>
But any user can create infinite blogs from his link on menu and can
list and edit other user''s blogs using navigator''s bar. List
option
problem is easy to resolve by erasing this action on blog'' controller,
but not so about edit and create options.
Thanks to all, and I wish my newbie problems and my english won''t
suppose an annoyance to you :)
______________________________________________
LLama Gratis a cualquier PC del Mundo.
Llamadas a fijos y m?viles desde 1 c?ntimo por minuto.
http://es.voice.yahoo.com