is there a way to customize Rails 3 generator in order not to create scaffoldings.css.scss when running
rails g scaffolding MyScaffold
?
I still want myScaffold.css.scss so adding the code below to application.rb doesn't solve my issue. `
config.generators do |g|
g.stylesheets false
end`
Thanks
There is a --no-stylesheets flag you can use:
rails g scaffold MyModel --no-stylesheets
Related
I have added 'nifty-generators' to my gem file.
then executed following :
rails g nifty:layout
case -1
rails g nifty:scaffold Post title:string content:text
case -2
rails g scaffold Blog title:string content:text
rake db:migrate
When we genrate a scaffold with "nifty:" ; it does not provide "set_post" & "post_params" methods. but the later case provides those "set_post" & "post_params" methods.
Do we have any specific reason/difference between these two commands ?
https://github.com/ryanb/nifty-generators
Go to the Troubleshooting and FAQs section in the above page. !
I have both ActiveRecord (MySQL) and Mongoid in my Rails 3.1 application. Everything is fine, excepts all generators uses mongoid to generate models. This way, when i:
rails g model user
i receive mongoid-like model, but i need ActiveRecord structure and migrations.
How can i switch back to AR?
Mongoid overrides the model generator, but you can switch it back.
In config/application.rb you can either add a line if you've already got a block similar to this:
config.generators do |g|
g.template_engine :haml
...
g.orm :active_record
end
Or just simply add the entire config line directly to the file
config.generators.orm :active_record
You can also pass :migrations => false if you want to turn off migrations
e.g. I have a model Student:
class Student < ActiveRecord::Base
def self.do_something
ss=Student.find_by_sex "m"
ss.each do |s|
s.blah
s.save
end
end
end
I can do this:
$ rails c
Loading development environment (Rails 3.0.4)
ruby-1.9.2-p180 :001 > Student.do_something
Now, I want a cronjob for this, How do I run above command without (rails c), so I can:
$ ruby student.rb
And get the same result? (I have gems: "mechanize", "hpricot", "to_lang" used in this model)
Thanks!
Maybe you should take look at gem whenever. If you don't want to use it, you shoud try to use rails runner:
/great/path/to/my/application/script/rails runner "Student.do_something"
I have several controllers already set up. Now I want to start writing spec tests for them. Is there a command that generates the spec files automatically? I know rails does this for new resources, but I don't know if it does it for existing controllers/models too.
rails g rspec:controller ControllerName
When it asks you to override the existing controller, type n.
There are two options. If you want an empty spec file, you could try with:
rails g rspec:controller ControllerName
Now, if you want a spec file with initial specs for a basic REST controller, try with:
rails g rspec:scaffold ControllerName
If you've configured rspec in application.rb:
config.generators do |g|
g.test_framework :rspec
end
then rails g controller things will work. Opt not to overwrite files as they're generated.
All a spec looks like when it's generated is the following:
require 'spec_helper'
describe ThingsController do
it "should be successful" do
get :index
response.should be_successful
end
end
I often create the specs manually, as it's rather trivial.
Have looked for a solution for 2 days now and am beating my head against the wall. I have tried both the normal authlogic build and the fork
authlogic or 'authlogic', :git => 'git://github.com/odorcicd/authlogic.git', :branch => 'rails3'
I have everything working except for when I create a UserSession it will not take the current_account details, so I"m left with every login will allow you to log into any of the subdomains. I can't seem to find a solution for this issue
def new
#user_session = #current_account.user_sessions.new
end
I think this is what you are looking for (from Not able to set a current_user using Authlogic on Rails 3.0.1)
class UserSession < Authlogic::Session::Base
allow_http_basic_auth false
end