ruby-on-rails-3.1

Rails 3 initializers that run only on `rails server` and not `rails generate`, etc

◇◆丶佛笑我妖孽 提交于 2019-11-29 06:38:26
I have a relatively small piece of initializer code that I want to run whenever rails server runs, but not when I run rails generate , rails console or any other rails command (including rake tasks that require the environment task). This piece of code pre-fills some caches and is relatively expensive so I really don't want it to run on anything but rails s Solutions that are unsatisfactory: Foreman et al. will mean it'll run on a different process which is (a) over the top for that small piece of code, (b) requires interprocess communication instead of the simple in-memory approach afforded

How to create schema in sql

女生的网名这么多〃 提交于 2019-11-29 04:59:57
问题 As per http://edgeguides.rubyonrails.org/configuring.html and this post I have this in application.rb config.active_record.schema_format = :sql However, it's still creating db/schema.rb (even after I delete it) and more importantly it's not creating the schema in sql when I run "rake db:migrate". Anyone know what I'm doing wrong? I'm on Rails 3.1 pre. 回答1: Well, this could be a rails bug, but you can always generate your db structure with this: rake db:structure:dump This is going to generate

Rails 3.1 assets pipeline in production

三世轮回 提交于 2019-11-29 04:34:26
I am using the assets pipeline (in Rails 3.1.3) and am kind of struggling to make it work in production. Situation In my /app/assets/stylesheets directory I have the following files: application.css --> this is the default rails one stylesheet.css --> This is my custom stylesheet I spent a lot of time getting my stylesheet.css included in the /public/assets/ directory in production (by running rake assets:precompile ) and I finally made it by adding the following line into in my application.rb file: config.assets.precompile += ['stylesheet.css'] I know have the right precompiled stylesheet.css

How to increase Heroku log drain verbosity to include all Rails app details?

China☆狼群 提交于 2019-11-29 04:25:53
Presently I'm running a Rails 3.1.x app atop Heroku Celadon Cedar and it seems that log verbosity is very much lacking. I have set the log level to DEBUG a la heroku config:add LOG_LEVEL=DEBUG --app app_name , which matched up to their recommendation, however beyond that I cannot seem to pull in the log/* file contents. Changing from Thin to Unicorn did increase verbosity slightly, but only in web worker requests. I still cannot pull down the db requests and so forth. What is the best way to maximize log verbosity via the heroku "drain" mechanism so that one can pull all instance logs into one

overriding devise after_sign_up_path_for not working

China☆狼群 提交于 2019-11-29 03:02:38
In routes i have the root-path pointing "home#index" but when i try to override that with after_sign_up_path_for keeps redirecting me to the root path when I sign in or sign up. I have tried to put it in both in devise subclassed controller and application_controller, but it didn't work. What do I need to do here? Application controller class ApplicationController < ActionController::Base protect_from_forgery def after_sign_up_path_for(resource) show_cities_path(resource) end end registration controller class RegistrationsController < ApplicationController def after_sign_up_path_for(resource)

Rails 3.1 Deployment to Heroku Error

给你一囗甜甜゛ 提交于 2019-11-29 02:45:53
问题 I'm trying to deploy my app to Heroku, I've done this before on my Windows machine, and now I am currently using a mac. I'm trying to use Postgresql for the first time. I have the following in my Gemfile: gem 'pg' EDIT: AndrewDavis-OSX:lunchbox ardavis$ rvm list rvm rubies => ruby-1.9.2-p180 [ x86_64 ] AndrewDavis-OSX:lunchbox ardavis$ heroku rake db:migrate rake aborted! /app/config/initializers/session_store.rb:3: syntax error, unexpected ':', expecting $end App::Application.config.session

Rails 3.1 Asset pipeline - Why my images do not precompile for production?

房东的猫 提交于 2019-11-29 02:45:25
问题 When running: rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets Everything precompiles but not my /app/assets/images/* I even tried adding this to my environment/production.rb config.assets.paths << "#{Rails.root}/app/assets/images" What's wrong? thanks! 回答1: Found a solution: Add to environment/production.rb config.assets.precompile += %w[*.png *.jpg *.jpeg *.gif] Why isn't this default ;ike this line says: (application.js, application.css, and all non-JS/CSS are already

Calling coffeescript functions from console

。_饼干妹妹 提交于 2019-11-29 02:26:24
问题 Playing a little with coffeescript and Rails 3.1.0.rc4. Have this code: yourMom = (location) -> console.log location yourMom "wuz hur" When the page loads, this outputs "wuz hur" properly. But when I try to call yourMom("wuz hur") from the chrome js console (as I do sometimes to test normal JS functions), I get a "ReferenceError: yourMom is not defined" Are functions generated by coffeescript available in this way? 回答1: an easier way to share global methods/variables is to use @ which means

Rails before_filter for specific actions in controller

旧巷老猫 提交于 2019-11-29 02:15:01
问题 def new before_filter do redirect_to "/" unless current_admin || current_company flash[:notice] = 'You dont have enough permissions to be here' unless current_admin || current_company end CODE CODE CODE end def edit before_filter do redirect_to "/" unless current_admin.id = 5 flash[:notice] = 'You dont have enough permissions to be here' unless current_admin || current_company end CODE CODE CODE end This is the code that I want to do, but I cant figure out how to do it right. What I want to

Curl on Ruby on Rails

霸气de小男生 提交于 2019-11-29 02:02:01
how to use curl on ruby on rails? Like this one curl -d 'params1[name]=name&params2[email]' 'http://mydomain.com/file.json' Just in case you don't know, it requires 'net/http' require 'net/http' uri = URI.parse("http://example.org") # Shortcut #response = Net::HTTP.post_form(uri, {"user[name]" => "testusername", "user[email]" => "testemail@yahoo.com"}) # Full control http = Net::HTTP.new(uri.host, uri.port) request = Net::HTTP::Post.new(uri.request_uri) request.set_form_data({"user[name]" => "testusername", "user[email]" => "testemail@yahoo.com"}) response = http.request(request) render :json