Is there any way to find out if a module present on https://apidock.com/ is part of the public API? Some of them, like ActionDispatch::Http::URL, have no description but many of their methods do. Is there a rule or something?
Related
Just now I started to using Concerns in rails, but i have doubt why we go for concerns, because we can achieve same thing on module & mixing concept. So please any one tell about shat is the use of concerns instead of using module.
It's well described here: http://api.rubyonrails.org/classes/ActiveSupport/Concern.html
In short:
Concerns allow you to use #included and #class_methods instead of self.included hook with additional module ClassMethods creation;
Concerns give you a better dependency resolution for modules included in each other;
ActiveSupport::Concern adds some convenient features (i.e class_methods) to your module. You can use "pure" ruby modules without extending it. Essentially you create a module which you mix-in to a class. Doesn't matter if this module extends AS::Concern, the mechanism is the same.
when you write in concern that mean you are making one module. My opinion is concern and module be similar together. Concern can appear somewhere as model, controller and at here you can write module for yourself. And with general module is write in lib folder. Both can be used by way include or extend into a class.
should a non-database data class I need be created as a Rails 3 "model", or just a basic class in the /lib area?
I want to build some classes to represent calculated domain objects. So the fields won't reference a database table/column. There will be also methods in the class that with the data.
Question - When generating these classes should these be just normal Ruby classes I put in the /lib area? Or should I/can I use rails models for this (and generate with "rails g model ...")?
Tableless models should probably be kept in app/models. I have several that access APIs. ActiveModel in Rails can help bring in some of the useful functionality of Active Record.
Interesting question..I had the same question a few weeks back.
I put those class under model directory. This is how I came up with that decision. The class that I wrote was completely related to a particular app no common features to share with anyone at-least at the moment. I also needed to use some of my existing models to query some data in that class. So I made it a class under model directory. I might be wrong but thats what I have done now.
In another case where I am using a certain api sets for a web and mobile app I am thinking of making the code which interfaces with the api into a gem. The thing to note here is that the api set is also part my system and it will only be used by my apps.
Classes that don't map to database tables can still reside inside of app/models. Instead of extending your class from ActiveRecord::Base, you can simply declare your class without any extensions (or your own extensions).
The CanCan ability model is a good example of this. It resides in app/models/, however does not extend ActiveRecord::Base. More information on CanCan's ability model can be found here: https://github.com/ryanb/cancan/wiki/Defining-Abilities
Also consider that code under lib/ will not reload in the development environment by default.
I am using Ruby on Rails 3.0.7 and I have multiple resources that almost have the same behavior. That is, those almost have same model, controller and view codes and same database table columns definition.
So I would like to find a way to DRY those resources. I already implemented modules and mixins for those in order to share part of the code (as validation methods, callbacks, view files but not controller files that, anyway, have very similar code).
Now, how can I do to handle this common behavior? Should I use something that Ruby on Rails developers named as acts_as_something? What do you advice about?
I think you already did that, just name a method in your modules act_as_your_module_name and make sure your module extends from your Base Class, e.g. ActiveRecord::Base.extend act_as_your_module_name
http://www.cowboycoded.com/tag/acts_as/
I am new to Ruby on Rails and my questions are about the application design, based on Rails 3. There are many data on the internet on the creation of standard websites (such as blogs) on Rails, but my application requires more than just "post and read" and I am not sure how to implement that.
The idea:
The model "Route" includes a number of airlines modules: "Ryanair", "easyJet", etc.
The "Route.Update" method calls the "UpdateRoutes" on each airline module (for example, "Ryanair.UpdateRoutes", "easyJet.UpdateRoutes")
It should work the same way with more models (such as "Flight.find") and more airlines ("Delta.FindFlights")
The questions:
Where should I store all the modules? I don't see any app/modules folder in Rails.
If my modules require gems, should I include them in the modules or in the models (where they are actually used)?
I want to make my application scalable. For example, I want to add a new working airline (module) without changing any code in "Route", "Flight" or any other model. I imagine something like the method "IncludeAirlines" which would go through modules/airlines/name.rb, include every module and call the needed method of it (such as name.UpdateRoutes). Is there any better way to implement that in Ruby on Rails?
As you might know, modules are generally used either as namespaces or as mixins.
Where you place a module depends on how tightly coupled a module is with the app directory . A few patterns in storing modules :
The /lib directory, if the module does not particularly 'interact' or concern the app/ and you treat the module as an internal plug-in.
The app/models directory, would be an appropriate place if your module is central to your business logic. A popular use case here, is where you use a module as a mixin to DRY your models/controllers.
37 Signals introduced a pattern of treating them as 'concerns' and storing them in app/concerns.
If your module uses a gem, you may need to require the gem in the module (sometimes a require is not at all necessary).
Your 3rd question is not clear. Sorry about that. Not quite sure what you're trying to do.
in a controller i can use request and params methods.
i know each controller is inheriting from ActionController::Base.
however, i cannot find these 2 methods in the api documentation for ActionController::Base http://api.rubyonrails.org
where are these methods defined? it would be great to know ALL methods that i can use in a controller.
thanks
request and params in ActionController:Base are shortcuts to the ActionController::Request object and its parameters method. It isn't well-documented, but you can see that by looking at the code for ActionController::Base.
Knowing that, you can find the documentation for these methods here:
http://api.rubyonrails.org/classes/ActionController/Request.html
Are you looking at the Rails 3 docs or the Rails 2 docs? I like to read the docs through this site: http://railsapi.com/doc/rails-v3.0.0.beta.3_ruby-v1.9/
If you go to the root, it lets you set your version of rails and ruby, so you have the right doc stack, with a good search feature etc. Maybe that will help :)