How to Rename or Move Rails's Readme_For_App

How to Rename or Move Rails's README_FOR_APP

Rails rdoc task is in <rails gem folder>/lib/tasks/documentation.rake

to do what you want, take the :app task and alter it, putting it in a .rake file in your app's /lib/tasks

#clear the doc:app task et al
Rake::Task["doc:app"].clear
Rake::Task["doc/app"].clear
Rake::Task["doc/app/index.html"].clear

namespace :doc do
desc "Generate documentation for the application. Set custom template with TEMPLATE=/path/to/rdoc/template.rb or title with TITLE=\"Custom Title\""
Rake::RDocTask.new("app") { |rdoc|
rdoc.rdoc_dir = 'doc/app'
rdoc.template = ENV['template'] if ENV['template']
rdoc.title = ENV['title'] || "Rails Application Documentation"
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.options << '--charset' << 'utf-8'
rdoc.rdoc_files.include('app/**/*.rb')
rdoc.rdoc_files.include('lib/**/*.rb')
rdoc.rdoc_files.include('README')
rdoc.main = 'README'
}
end

I'm not sure if that is exactly it, but play around with it and look at the rdoc task docs for more info.

Rails API design

I used both techniques: writing API logic in the same controllers and making separate controllers for the API request.

If it's only an API, a small app used only by you, go with the default controller-model relation that rails offers. The code will be quite clean. Your routes file will be also clean.

If you have a website and you want to build an API along, do it separately. I've build one alongside the existing controllers and the code was too messy. I refactored the code several times, but I still didn't like it (it's also a matter of personal taste).

Another solution is to make controllers with a prefix. Ex: ApiUsersController. This would make your routes.rb file look ugly because you would have to manually specify the route to match the corresponding controller method.

The working solution for me was to move all the API logic in separate controllers under an API namespace. Namespaces also let you do API versioning. So, for example, your routes will be:

GET /api/v1/users.json
POST /api/v1/users.json

And then, in the future you can create another API version, let's say v2, without breaking existing applications that use the older version of the API.

You can find more about namespaces here: http://guides.rubyonrails.org/routing.html#controller-namespaces-and-routing

An awesome tutorial about REST-full API with versioning: http://railscasts.com/episodes/350-rest-api-versioning?view=asciicast

Rails 4: how I use the contents of a markdown file in a view?

You can load the contents of a file using File.read(). Knowing this, you simply need the path to the file: Rails.root/CHANGELOG.md

One way of achieving your desired result would be to place the following code in your page's controller, then rendering the markdown in the view:

@changelog = File.read("#{Rails.root}/CHANGELOG.md")

Then just use @changelog with the markdown method in the view:

<%= markdown @changelog %>

How to launch and edit a file from Git using Notepad++?

C:/Program Files/Notepad++/notepad++.exe README.markdown

And since you'll probably want to use notepad++ a lot from the command line, you may want to alter your PATH to include its root directory, so you don't need to write the full path each time.

How could we separate grape api resources into multiple files?

Ruby has open classes, so you should be able to simply move those to separate files.

# foo.rb
class API_v1 < Grape::API
resource :foo do
end
end

# bar.rb
class API_v1 < Grape::API
resource :bar do
end
end

Consuming REST API from Rails Application

ActiveResource is no longer being included in Rails 4.0. Word is that it is barely maintained these days, and is difficult to customize for REST API endpoints that are not formulated according to the "Rails way".

After some research, I am heavily favoring using Faraday. It includes support for utilizing different HTTP request adapters. It can use EventMachine directly, or libraries like Typhoeus for when you decide to get concurrent. It also supports Rack-like middleware for seamlessly including, say, authentication.

For a REST ORM in Rails that is easily configurable, the relatively new (about a year old) Her looks very promising, and utilizes Faraday.

Update

I completely <3 RestClient. So simple. If you need ORM-style functionality, then you'll need a higher-level abstraction, but for simply consuming an API, you can't beat its simplicity. It just does exactly what it's supposed to do without fuss, has sensible defaults, and has the ability to set advanced options such as auth headers.

Error in rake db:create in new rails project

I simply reinstalled ruby+rails and things were alright.

I deleted the ~/.rbenv folder and ran sudo apt-get purge ruby

Then installed ruby and rails using Official Page.

Importantly, once I created a new project I was prompted to install another gem to resolve some dependency gem install rdoc-data

Transfer JSON data to Heroku Rails application

Changing the pattern of the AngularJs controller resolved the issue:

myApp.controller("BlogController", ['$scope', '$http', function($scope, $http){
$http.get('/assets/blogs.json').success(function(data){
$scope.blogs = data;

String.prototype.trunc = String.prototype.trunc ||
function(n){
// this will return a substring and
// if its larger than 'n' then truncate and append '...' to the string and return it.
// if its less than 'n' then return the 'string'
return this.length>n ? this.substr(0,n-1)+'...' : this;
};

});
}]);


Related Topics



Leave a reply



Submit