Will vote_fu work without a voter model? - ruby-on-rails

Just looking into vote_fu for a public page where people can vote on content. I am interested in implementing this, but there will be no model to act_as_voter, only a model to act_as_votable. Is this doable? Anyone have experience with this?
Many thanks as always.
Ben

I'd not recommend doing that. The gem/plugin is built around the idea of a voter model. You might be able to tweak your implementation by creating your own migrations and overriding included methods to be still able to use vote_fu, but IMO that would be hardly worth it.
Thinking about an anonymous voting process in its simplest form you should be a lot faster by rolling your own custom version.

Related

Rails generic controller and views

I've been looking at Administrate source code and would like to know if it's a good practice or not the use of a generic controller and what implications it would have, like code complexity, performance degradation, etc.
Sometime ago, there was a gem inherited_resources that provide this feature, but since Rails 3.0 or 3.1 has been said we no longer need them.
So, since I have some very simple models (with only two or three fields) I could create a generic view and controller to manipulate them and save a lot of lines of "duplicated" code. Although I'm afraid, by avoiding repetition I could be creating another monster.
I've been looking for a Rails way to do this, but failed, so I would thanks some advice.
Note: I'm not looking to implement or use an admin dashboard, but use in my application instead
All Rails admin-panel implementations will make you hurt when you will try to make something more complex than stupid simple CRUD-application. I recomend you not to use such solutions. I had experiece in usage three different Rails's admin-panels and all of them had bad design and a lot of limitations. They are hard to mantain and extend their functionality.

What is the easiest way to implement trivial forum in Umbraco?

I am building an Umbraco site, and there is a need for a really simple forum (e.g. one level of topics, a simple subject/body form for new entries and replies, that's about it)
What is the easiest way to implement this? I think nForum is an overkill. Should I go with Umbraco API for member management and content creation, of should I use my own prefixed db tables and custom backend implementation?
Thanks in advance
Themos
For small and limited requirements you can surely look at the UFORUM, it is time tested and pretty decent.
It supports membership out of the box...
http://our.umbraco.org/projects/collaboration/uforum-basics
Check it out Hope it helps.

Best practice in Rails when editing scaffold made pages

I have a best practice question. I have two classes, company and category. They have a many-to-many relationship. When clicking a category I shall go to a page showing all companies with the chosen category. Pretty straight forward.
My question is:
Should I list all the companies on the companies/index.html.erb after filtering the companies in the controller?
or
Should I list all the companies on the categories/show.html.erb page?
or
Should I do a completely new page, since it doesn't really fit into any of the two above?
Do you generally make a new page when your goal doesn't fit the scaffold made pages or do you use them quite freely?
I am working/learning alone with rails, so there are a lot of best practice questions popping up all the time.
Cheers Carl
A scaffold is a starting point, so you should always consider what you need in your web application.
In you case, I think all examples are fine, but again, it's really up to you.
If you are just learning Rails, stick to as many conventions as possible. Scaffolding is one of the ways Rails can help you get things started when you don't know how all of the pieces work together.
But like Oscar said, ultimately you must decide what your application will need.
The Ruby on Rails platform comes with many principles such as DRY etc.
The main part is the MVC architecture, the thing scaffolding does is let you see how this MVC is used correctly by a Model, View and Controller generation.
When you learn how this works you will be able to answer your own question, I could write my thoughts down but it is key for a Rails developer to understand the MVC structure so my suggestion is to read:
http://betterexplained.com/articles/intermediate-rails-understanding-models-views-and-controllers/
have fun

Ruby on Rails - Create Entity with Relationship

I'm new to rails, so be nice.
I'm building a "rolodex" type application, and this question is about the best way to handle creating an entity along with several relationship entities at the same time.
For (a contrived) example:
My application will have a Person model, which has_one Contact_Info model. On the create.html.erb page for Person it makes sense for the user of my appliction to create the person, and the contact_info at the same time.
It doesn't seem right to include details for creating a contact directly in the create view/controller for person. What's the rails way to handle this?
Using nested attributes is the most common way to do this.
The actual documentation is here.
You want to use "Nested Forms". There is a great example of them in this blog post.
I'm also noob, but I had a similar issue with an app. I was using a tutor at the time and he basically said it was a good example of rails being opinionated. It sounds like you want to take the create action for two different models at the same time, which may be possible but probably very hard. Id suggest considering whether your data model could be modified, or find a way to make an acceptable user flow while collecting the data in different forms.
Update: while writing this the technical answer came in. Keep in mind, its perfectly okay to take the easy route if doing so helps you get the app out the door, and especially while you're still new.

Has anyone written a plugin to add the final polish to ActiveResource?

I have been using ActiveResource in my Ruby on Rails applications for some time, and I am starting to really feel that it needs a final polish to make it go from "pretty nice" to "beautiful".
I would like to be able to use an ActiveResource as if it were an ActiveRecord. If I could use has\_many, belongs\_to and other niceties with ActiveResources, it would make my life easier.
So I looked around for a plugin to do just that, but haven't had any luck finding one. Has anyone written one? Does anyone know of an ongoing project?
Raison d'ĂȘtre
Let's say I have an application which manages Users, and another application which manages UserRequests. I would like to avoid any circular dependency between my applications, therefore I have decided that the Users application will be completely unaware of the notion of UserRequests. But of course, a UserRequest should belong to a User, and a User should have many UserRequests.
So, in the Users application, all I have is a User ActiveRecord, with all the necessary controller stuff to make it usable through ActiveResource.
The complicated stuff is in the UserRequests application. I have a UserRequest ActiveRecord, and a User ActiveResource. I would love to code the fact that a UserRequest belongs_to a User ActiveResource, and a User ActiveResource has_many UserRequests.
In another scenario where it could be the other way around (the ActiveRecord has_many ActiveResources, and the ActiveResource belongs_to the ActiveRecord).
Ryan Daigle proposed to do something similar with his Roxy gem. From his teaser section:
I hope to have an extension library up
soon that utilizes Roxy to provide
ActiveRecord-like association
definitions in ActiveResource.
The example he gives shows how it wouldn't be too difficult to implement with Roxy.
I just ran across the Hyperactive Resource plugin. I am looking at it right now... looks good.
The funny thing is that I had decided to write my own plugin, and I was looking for a good name for it. I wanted to find a name which would give the feeling that it was "ActiveResource++", an enhanced version of ActiveResource. I hesitated between "SexyResource" and "HyperactiveResource", and I decided that the former was not politically correct enough. So I started to write my HyperactiveResource plugin... until I wondered if someone else had already thought of that name. And it turns out someone did. And the plugin was there. Cool! But it's kind of scary how we developers think alike, isn't it? ;-)

Resources