Cucumber first scenario for blog - ruby-on-rails

So for cucumber, I have a blank application. I'm thinking about for my first BDD it should be:
Feature: Blog
As an Owner
In order to retain customers
I want to create a blog
Scenario: Add blog posts
Given I am logged in as owner
When I go to the blog
And I create a post
Then it should appear on the blog page
I feel like this isn't right. I feel like the first scenario is the hardest, because after that adding a feature should be easier.
So what should the first scenario/Feature be?

If you think of the blog application in terms of the capabilities it delivers, here's what you're currently addressing:
Logging in
Writing blog posts
Reading blog posts
That's a lot to deliver for just one scenario.
If this is just standard blogging software, then you could always start with the purpose of the software - presumably to attract users to your site. What if you just wrote posts by hacking the database with SQL? What if you didn't have any login? What if all you did was display blog posts?
Now you can start with a very much simpler scenario:
Given my most recent blog post is titled "Unicorns are real"
When Ursula the unicorn collector sees my blog
Then the post should be visible on the first page.
Try to make it specific, rather than generic, as this will help you remember what you've already delivered as well as helping your imagination to come up with other scenarios.
The benefit of starting with this post is that you'll only record the things in the database that are actually needed to display a post (and you may decide to use a filesystem instead of a database, etc.)
After that, publishing posts and then logging in to do it will be much easier still.
If you're intending to display adverts, and link keywords to them, etc., then the purpose of your site is to make money, and I would write a scenario around that before you even worry about users coming to read the posts.
This is the advice I give if there's nothing unusual about your blog. However, if you're doing anything differently to the standard blogging software out there, I recommend focusing on that first, as it's where all the risk will be.

Related

rails user notifications for several models

I'm still learning rails but want to be sure I'm heading in the right direction. For several of my models I want to let a list of users know that updates have been made when a new record is created for example. I'd like to tie this to an email and in-app notification(doesn't need to be AJAX), next page refresh is fine.
I've been reading up on observers some and I think that's what I want but they seem somewhat controversial based on the blogs I've read. Services like Pusher seem to be overkill for my needs.
Would this be a good solution for this scenario? Also, can anyone point me to some example code that I could emulate?
Thanks!
Check out Rails Cast if you are trying to learn. Best free code base I have seen. Also check out this book another great learning tool. Agile Web Development with Rails (2nd edition).There might be some newer ones out but I have not checked.

What is the best conceptual approach, in Rails, to managing content areas in what is otherwise a web application?

(A while back I read this great post: http://aaronlongwell.com/2009/06/the-ruby-on-rails-cms-dilemma.html, discussing the "Rails CMS Dilemma". It describes conceptual approaches to managing content in websites vs web apps. I'm still a beginner with Rails, but had a bit of a PHP background, and I still have trouble wrapping my brain around this.
A lot of what I run into is customers who want a website that is not 100% website, and not 100% web app... That is, perhaps there are several pages of business-to-public facing content, but then there are application elements, and the whole overall look is supposed to be cohesive. This was always fairly simple in PHP, as you just kind of dropped your app code into the PHP "script", etc (though I know there are plenty of cons to this platform and approach).
So I am wondering, what is the best approach in Rails for doing this?
Say you have an application with user authentication and some sort of CRUD stuff going on, where users collaborate on projects or something. Well, what is the optimal approach for managing the text/images of the "How This Site Works" and "Our Company" pages, which people may also want to view? Is it just simply having a pages controller and several text fields, with an admin panel on the back end that lets you edit those fields? Or is it perhaps a common approach to start off with something like Refinery, and then build on top of it for the non-content-driven areas of a site?
Sorry if this is a dumb question. It's just that I've read Hartl's book and others, and they never address this practical low-level stuff for a beginner... Sure, I can build a Twitter feed now, but what Twitter's "About" page (http://twitter.com/about)? I can't just throw text into a view and give that to a client... They want a super easy way to see the site tree, edit content areas, AND administrate/run their Twitter feed or whatever.
Thanks for your help.
I think you're looking for a CMS that runs as a plugin in your Rails application. If that's the case, I'd suggest that you try http://github.com/twg/comfortable-mexican-sofa

Create my own commenting/Q&A system on Ruby on Rails, or just use Disqus or Intense Debate?

My site requires authentication, so it has membership. I wonder if I should create my own comment system for user to discuss/comment on an article, or should just use third-party comment system like Disqus or Intense Debate, which requires seperate account (Twitter, Facebook, etc.).
In fact, it would be good if there is a guide to create my own comment system or Q&A system for users to discuss a particular article on my website. If you know of any, please lemme know.
Thanks.
I recently am working on a project where I had to weigh the same things. I eventually decided to roll my own comments.
Namely the advantage of rolling your own is that you have full control on how they work. I needed a moderation system/queue that I needed to work a specific way, for one. Second, someday I will be looking to integrate a 'community reputation' system, so that was another plus for rolling my own. Such things I don't want to leave to a third party solution outside of my control and the third parties don't always have such a flexible API to modify.
On the other hand, Disqus (or similar third party commenting systems) may be up your alley if your needs are more simple. For one, it's easy to get up and running and may be all you may really need. Accounts for it work across anything using Disqus, and that may win convenience points for your users who are sick and tired of having to sign up for a million accounts for a million websites. Disqus also has built in tools (for spam, trolls, etc) and that is also convenient.
If you go with rolling your own solution with user accounts, you can integrate things like Facebook/Twitter/etc login to make the registration process easier. But overall, like I said, depends on how fancy or complex you need the whole thing to be.
Should you roll your own, a good start is a recent Railscasts episode on the Ancestry gem http://railscasts.com/episodes/262-trees-with-ancestry, it should give you a good start on building threaded comments.
Something in the middle :) Use the acts_as_commentable plugin :
https://github.com/jinzhu/acts_as_commentable

Rails confusion with coding

I'm desperate. I've read and tried many things with rails. The problem isn't that "big", it is just that I'm still getting used to the convention over conf world. Lack of examples, too.
I just want to be able to have a site where you have roles (think admin, normal user, etc) and each of these can view,say, posts, articles. However, the admin obviously has access to update/delete posts,articles. Users only post, things like that.
I can create the authentications, sessions, and all. But I don't know how to present (or refactor) code. Where does the code for the admin go? views?, what about for users?
Would I need to create controllers specifically for admins, and users, others, in order to display the same model objects (articles, posts) that I'll be dealing with? including views?
Thanks
There's a free Railscast that may help you with this called "Authorization with CanCan".
If you feel like parting with some money, Rails 3 in Action also covers this sort of thing in Chapters 6 and 7.
First, watch this screencast: Where administration goes.
Second, watch this one: Restricting Access.
Then this one: Super Simple Authentication.
This should clear up your confusion and help you wrap your mind around "The Rails Way" of doing authentication and administration.
Once your immediate crisis is over, I would STRONGLY recommend you pick up a copy of "Beginning Rails 3". The kind of frustration you're experiencing is normal: when you come from the world of basic HTML plus scripting (javascript and php most likely) it's really hard to "get" the big idea that a framework imposes on your design.
Beginning Rails 3 takes about 2-3 days to work completely through, front to back. When you're done you'll TRULY understand Rails and your work will feel like FUN, not frustration. It's really, really, really, really worth it to take the time to read the book. 2-3 days with the book will save you 2-3 months of mediocre coding and learning by trial and error.
There are lots of examples available. One of the best sources of information is Railscasts. You will find many screencasts on authentication (including the most recent (#250), as chance would have it). You will also find them on authorization, which is the role-based mechanism you describe.
Here's a pretty thorough comparison of many authorization plugins: http://steffenbartsch.com/blog/2008/08/rails-authorization-plugins/
I would also look into cancan (railscast), which is newer than that list and highly regarded.

Need help setting up scaffolding for this situation

I asked a question earlier, and got an excellent response, but, being a newbie to Rails and still getting the basics down, I need someone to show me how to set up some scaffolding for the situation that Hates_ was nice enough to outline for me. I've set up my application and whatnot, but I basically want to have, for example purposes:
A "Stories" table, for a list of stories
A "Pages" table, for a list of pages that can be attached to stories
A "LinkedPages" table, to link one page to multiple other pages
The idea is that users can create Stories. Stories have Pages. Pages link to other Pages in a branching sort of way, and Hates_ suggested using a LinkedPages table to assist the process of determining which pages link to which other pages.
If someone could use the example models Hates_ provided on the link above (or give me better ones if needed), and just show me how to get this started, I'd be extremely grateful. Rails has had the highest initial learning curve of any programming or scripting language I've learned in the past, I'm just starting to understand many of the basics.
Thanks in advance!
Here is an updated fast paced video that quickly presents some of the wicked sweet features in Rails via a somewhat contrived Blog tutorial.
http://media.rubyonrails.org/video/rails_blog_2.mov
The presenter crams a lot of information into a very short time frame and does paste in some prepared code from time to time, but over all he hits on many of the key features.
He explains how to set up scaffolding as well in about probably the last 5 mins or so.

Resources