I am working on multiple projects, which most of them have common controllers and views.
Is there a way to be able to copy all the common code in a script or something?
Any ideas on this
Thanks
You're looking for a rails engine, which is a gem you can use in other projects. The gem provides controllers, views, etc. Devise is maybe one of the best examples of this, providing an authentication framework.
First promising hit on Google for how to make one was this, but I'm sure you can find more.
Related
I have generated a few controllers and models to my app and now I want to add testing (I know it's a little backwards but at least I am starting fairly early in my project). Anyway, every time I generated a controller/model I did not include the --no-test-framework so now I have a bunch of specs related to controllers, helpers, models, and views. Do I need these? And, if not, is it okay to just delete them? I am noticing from some tutorials (Hartl, Bates) that they are using request specs, are these all I need?
Thanks!
I know that Rails has some tools on board to create a REST API. However, concepts like HATEOS aren't supported out of the box.
I googled around for Gems that are filling the gap. The most complete Gem I found is Restfulie (https://github.com/caelum/restfulie). But I am not complete convinced about Restfulie and the project looks abandoned. Hence, I am looking for good alternatives to Restfulie.
What's the best Gem to create a REST API for Rails?
Popular choices are RABL and Roar / roar-rails.
I personally like Roar better because it allows you to consume your representations which is a bit harder with RABL. On the other hand, it's concepts are still in flux so things still tend to change.
Grape is worth a try.
I'm looking for some gem/library able to generate administration interface for my RoR3 project.
I don't want to have some library/gem with its own logic and data in some gem repo, I want it to be not just integrated with my app, but be actual part of it, have ability to tweak and modify logic, views, etc...
ATM I've tried rails_admin and it seems to be the best imho, but during development lots of issues came out: i18n issues, additional pages, custom controls, lack of documentation on extending it, ... There's a lot actually. Maybe for something simple its a perfect match, but not for projects requiring complex administration interface.
So any ideas on gem/library I can use?
Thanks.
Active Admin:
Active Admin is a Ruby on Rails plugin for generating administration
style interfaces. It abstracts common business application patterns to
make it simple for developers to implement beautiful and elegant
interfaces with very little effort.
I am looking at a rails app and at the top of every controller there is a block of code that looks something like this
expose(:var) {Model.find params[:var_id]}
I understand what is inside the block just fine but...
I cannot find any documentation on what the expose function does where it comes from or anything I have tried searching the project and using the searchable rails docs.
I would love to know what it does, can someone please tell me or point me to the docs.
This is probably referencing the decent_exposure gem. You can learn more about it here: http://railscasts.com/episodes/259-decent-exposure
Source: https://github.com/voxdolo/decent_exposure
It's a method from the Decent Exposure gem. You can check out a screencast that Ryan Bates did on it over at Railscasts. It's a really great gem. I use it in my application. It cuts down on a lot of the redundancy in the controller layer.
expose is not a part of Rails, it comes from the decent_exposure gem.
It is not an answer to the question. I just want to make the Rails world a bit better and I hope that somebody will read this.
Please think twice before using expose. You should only use it if you 100% sure you are using it the right way and it really makes the code better. Read the documentation properly!
One of projects I worked on became unmaintainable because of tons of expose in controllers which replaced not only all #instance_variables passed to views, but also a lot of business logic and the most helper methods.
When you use expose it is not clear in which controller actions and in which views it is used. Unexperienced developers combine data and logic for multiple actions and multiple views in the same expose block.
That's a nightmare.
Believe me, expose really destroys projects if not used properly.
In Rails 2 I know of a few plugins for enumerations such as acts_as_enumeration and enumerate_by but they don't seem to be maintained or updated for Rails 3. Preferably, the solution would store the enum in memory rather than a database for performance reasons but really any method would be useful since it can always be cached.
I did find enumerated_attribute that claims to work with Rails 3 but quite honestly I don't like the API and was hoping for another good solution.
(Sorry for only linking to the one plugin but it won't let me post more than one link until I get a higher reputation)
I am currently using lwe's simple_enum which seems to be actively developed and stores values on memory or if you prefer on a table.
If you're using DataMapper as your ORM have a look at dm-types which includes an Enum type.
There is this gem, enumerate_it, it has good documentation and very well done!