ruby-on-rails-3.1

Where to put private documents to use in Rails applications?

被刻印的时光 ゝ 提交于 2019-12-09 13:11:07
问题 I have some template files I would like to use in my rails App. I was wondering where(under which directory) to put them given two scenarios: They are private to my application (Only webmaster can delete, change them) They are private to my application but also they can be managed by admins(deleted, modified) 回答1: Update after comments Since you want to serve the files locally, just put them outside of the /public/ folder and outside of any of the /assets/ folders and you should be good. You

Converting URL to JSON version?

筅森魡賤 提交于 2019-12-09 12:28:46
问题 On all the pages of my app, I want a link to the JSON version of current page. Any neat tricks to do this? Where it got complicated was when additional '&' parameters were included in the URL. So the urls would be transposed as: '/users' => '/users.json' '/users?page=1&per_page=5' => '/users.json?page=1&per_page=5' 回答1: try this : polymorphic_path( @user, :format => :json ) (as seen in this API doc) alternatively : user_path( :id => @user.id, :format => :json ) 回答2: Attribution for this

Ruby syntax: break out from 'each.. do..' block

笑着哭i 提交于 2019-12-09 07:23:16
问题 I am developing a Ruby on Rails app. My question is more about Ruby syntax. I have a model class with a class method self.check : class Cars < ActiveRecord::Base ... def self.check(name) self.all.each do |car| #if result is true, break out from the each block, and return the car how to... result = SOME_CONDITION_MEET?(car) #not related with database end puts "outside the each block." end end I would like to stop/break out from the each block once the result is true (that's break the each

Rails 3.1 assets not recognizing new images uploaded by rmagick until server restart

守給你的承諾、 提交于 2019-12-09 06:54:48
问题 I have my Rails 3.1.0 application running with passenger in production environment and I have a section where the application allows the user to change his profile picture so I upload the image using an ajax uploader and in my controller I upload the file and generate different sizes for the image with rmagick then I render the new image with an image_tag but the application won't show the image till I restart the server. What I get is No route matches [GET] "assets/path/to/image.png" If I

How can I run SOME initializers when doing a Rails assets:precompile?

给你一囗甜甜゛ 提交于 2019-12-09 04:21:40
问题 Background I have an app that I recently updated to Rails 3.2.1 (from Rails 3.0.x) and have refactored the JS and CSS assets to make use of the new asset pipeline. The app is hosted on Heroku with the Celadon Cedar stack. App Config I keep application specific configuration in a YAML file called app_config.yml and load it into a global APP_CONFIG variable using an initializer: # config/initializers/load_app_config.rb app_config_contents = YAML.load_file("#{Rails.root.to_s}/config/app_config

Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)

≡放荡痞女 提交于 2019-12-09 04:03:43
问题 My website has been broken since Dreamhost upgraded their servers a couple of weeks ago. I have been tearing my hair out trying to get it fixed and made some progress but am stuck on what is hopefully the final issue. I'm using Rails 3.1.1 on Ruby 1.8.7 and get presented with a 'Ruby (Rack) application could not be started error' from PhusionPassenger. It states that it 'Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS:

Routing errors when upgrading from rails 3.1 to rails 3.2 due to underscores in module namespaces

心已入冬 提交于 2019-12-09 03:44:33
问题 We have a rails application and we have a API namespace defined as Api::V1, Api::V1_2, Api::V1_3 etc. In routes.rb, we have set the following namespace :api do ["v1", "v1.2", "v1.3", "latest"].each do |name| namespace name, {:module => name.gsub(".","__"), :as => name.gsub(".","_") } do constraints :format => /json/ do # user scoped views resources :some_endpoint, :only => [:create, :index, :show, :update, :delete], :path => "scheduler" do member do put 'edit' post 'duplicate' end end end end

Rails 3.1: accepts_nested_attributes_for and has_one association - won't work?

陌路散爱 提交于 2019-12-09 03:06:18
问题 I'm trying to use accepts_nested_attributes_for on a has_one association model, and getting absolutely nowhere :-( I have two models, a user and a location. A user has one location: class User < ActiveRecord::Base # current location has_one :location, :dependent => :destroy accepts_nested_attributes_for :location end class Location < ActiveRecord::Base belongs_to :user end I can save changes to the model by using User.find(1).location.current_location_text = "blah" from the console, so I know

How to display controller specific javascript in rails 3.1?

╄→尐↘猪︶ㄣ 提交于 2019-12-08 23:32:16
问题 I have my assets folder structure like this assets javascripts products --product.js --productValidate.js store --store.js I want the project.js and projectValidate.js to be added in my application.js as a part of asset pipe-lining only when actions in product controller is called and store.js when actions in store controller is called. How can i achieve this in rails 3.1? 回答1: As Rahul already mentioned, application.js is precompiled and the same for every action. So it does not depend on a

Images desapears after deploy Rails 3.1.3 on Heroku Cedar

人盡茶涼 提交于 2019-12-08 19:52:32
After deploy on heroku cedar, images desapear. I've a CSS like : :css /* */ table.table thead .sorting { background: url('assets/datatables/sort_both.png') no-repeat center right; } table.table thead .sorting_asc { background: url('assets/datatables/sort_asc.png') no-repeat center right; } table.table thead .sorting_desc { background: url('assets/datatables/sort_desc.png') no-repeat center right; } /* */ table.table thead .sorting_asc_disabled { background: url('assets/datatables/sort_asc_disabled.png') no-repeat center right; } table.table thead .sorting_desc_disabled { background: url(