How can you configure Rails to use blueprint-css instead of the default scaffolding css? - ruby-on-rails

What changes do you need to make to a Rails project to configure blueprintcss as the default stylesheet to be used when you generate scaffolding instead of scaffold.css?

I'd recommend writing your own generator, but if you want to alter the default you can:
1 - For a single app: Freeze rails and change the stylesheet the scaffold generator uses.
railsapp/vendor/rails/railties/lib/rails_generators/generators/components/scaffold/templates/style.css
2 - For all apps: Change the same style.css file in your systems rails installation.

Substitute your own scaffolding generation code. Instructions are here (with the caveat that they may be out of date).
An easier alternative may be to write a Rake action to do textual substitution in the (normally) generated source.

Look into Rails Templates.
You can write one to do much more than replace the css in a rails app. YOu can make it install gems, freeze rails, all kinds of things. Take a look at http://youvegotrails.com for an idea of what you can do.

Related

How to create a custom scaffold generator in Rails 3?

There are these railscasts.
http://railscasts.com/episodes/218-making-generators-in-rails-3 With this one you find out how
to create a stylesheets and scaffold generator.
http://railscasts.com/episodes/216-generators-in-rails-3 With this one you find out how to add some files to modify the scaffolding views.
I want to do a mix of the two. I would like to create a generator that also creates scaffolding views. Kinda like Ryan Bates nifty generators or web_app_theme gem (https://github.com/pilu/web-app-theme). I have been searching for a tutorial or some information to point me in the right direction but I can't find exactly what I'm looking for.
I know I'm close. I already know how to create a generator with Railcast 218 but now, how can I make it create view files too?
I would like to run a command like this...
rails g my_scaffold_generator Post title:string body:text
This may well be too late to help, but as I found this while Googling for the same info...
It seems to me that the best approach, at least for learning the ropes, is to duplicate and then alter the existing scaffold generator.
So the first thing that tripped me up is finding the default templates, which do not live in your rails-3.2.0 directory (or whatever version you are on), but in railties-3.2.0. So for my RVM-based installation they were at:
/Users/leo/.rvm/gems/ruby-1.9.3-p194#gemset/gems/railties-3.2.0/lib/rails/generators/
[Note: your gems directory could be somewhere else entirely, use $> gem environment to find your gem paths]
In here is erb/scaffold/templates/ which has the files you'd expect (new.html.erb, _form.html.erb etc).
You can copy these files to your app's root, into lib/templates/erb/scaffold/ and they will be used instead of the default ones.
If you want to use these in a custom generator, there are two approaches:
1) Use hook_for to call the regular ERB scaffold generator from your generator.
2) Move/process the templates inside your own custom generator, using copy_file and similar methods in Thor to move them into place.
There is a decent Rails Guide on this, although I found I didn't really get it until I started digging around in .../railties-3.2.0/lib/rails/generators/... and looking at how the defaults are structured.

Rails generate controller boilerplate for existing resource?

I used generate scaffold to setup the basic RESTful actions however I want to extend the actions to include something like 'purchase'. Is there a way to use the command line to generate the boilerplate (stub functions in controller file and updated route file?)?
As far as I can tell generate controller either wipes or leaves the existing file - there's no nice way to merge them.
Not by default. However, realize that in Rails 3, customizing generators isn't terribly difficult. See Creating and Customizing Rails Generators & Templates, and Bates' screencast on Generators in Rails 3.
Regarding your second "question," that's right -- the file is either replaced or overwritten.

Pdf generation with latex in rails 3

is there a way to generate pdf documents from latex in rails 3? We've been using rtex (http://rtex.rubyforge.org/) in a rails 2 application, however it doesen't seem to work with rails 3.
Our rails application generates invoices using a latex template which we also use to create invoices by hand. Hence we would have to maintain two templates if we had to find a different solution for the pdf generation in rails 3.
Best I found to do such things was to create the .tex files on the server, then call a rake task that ran a "pdflatex" system command.
It is pretty poor in performances I guess, but it's designed for a single admin and works fine for me, on my local machine, and I can use the same latex templates for my letters
Old question, but I'm sure this'll help anyone coming to this page now.
Take a look at the rails-latex (LatexToPdf) gem.
The LatexToPdf.generate_pdf method takes in two arguments:
tex content
a configuration hash
...and returns the pdf binary, which you'll have to write to a file.
I suggest reading through the source to if you need to add configuration.
Note that under the hood, the rails-latex gem still depends on a TeX extension (which you'll need to download) to generate the pdf. The default is pdflatex, and I've personally used xelatex.
As of the writing of this answer, this gem is described as a renderer for rails 3; though it now includes support for rails 4 and 5.

how to customize formastic style?

I use the great form builder plugin 'formastic' to build a form. It is rather ugly though. How can I set style to it? I find little information through the documentation. Note: I use the newest 1.2.3. with ruby 1.8.7 and rails 3.0.3.
If you used the formtastic generator (rails generate formtastic:install), you have two CSS files in the public/stylesheets subdirectory, called formtastic.css and formtastic_changes.css. Look into the first one to see how formtastic sets the default styles, and then override these in formtastic_changes.css.

Rails 3: What CSS styles are expected by Rails?

I am creating a custom CSS stylesheet for a Rails 3 application.
Is there a list anywhere of the CSS styles that Rails relies upon? So far I have found:
#notice
#error_explanation
.field_with_errors
Many thanks.
The css for the flash-messages you can choose yourself, as they are normally defined in application.html.erb (there is no default definition for flash-messages in rails 3).
For form-styling i would recommend using a gem like formtastic, which not only greatly simplifies making forms, but also provides a standard css file. So all needed tags are then known (and can be overwritten if needed).
If on the other hand you are looking at ways to get your complete layout started quickly, you might want to checkout web-app-theme or activo (which is even more complete).
A fresh Rails 3 app will not require any specific CSS class/id styles beyond the three you just mentioned, which is why no default stylesheet is generated until you start scaffolding.
If you run script/rails generate scaffold MyModel it will create a stylesheet called scaffold.css which the generated views will rely upon.

Resources