ruby-on-rails-3.1

Why using merge method with scopes isn't working anymore on Rails 3.1?

早过忘川 提交于 2019-12-05 01:09:08
I stumbled upon a wonderful article about scopes on Rails 3+ : http://edgerails.info/articles/what-s-new-in-edge-rails/2010/02/23/the-skinny-on-scopes-formerly-named-scope/index.html You can read there (in 'Crazy Town' section) that it's possible to merge scopes from different models like this : class User < ActiveRecord::Base scope :published, lambda { joins(:posts).group("users.id") & Post.published } end which works just as expected, and allows you to do : User.published.to_sql #=> SELECT users.* FROM "users" # INNER JOIN "posts" ON "posts"."author_id" = "users"."id" # WHERE (posts

ActiveRecord::UnknownAttributeError?

白昼怎懂夜的黑 提交于 2019-12-05 00:11:43
I just pushed an app to a production Heroku environment. Basically there is a Bus model and it has a seats attribute class Bus < ActiveRecord::Base attr_accessible :seats, # other attributes end Now I have a JavaScript frontend which POST's JSON for new buses to the buses#create action. ActiveRecord keeps encountering an error when I try to create a bus: : POST www.busables.com/buses dyno=web.1 queue=0 wait=5ms service=65ms status=500 bytes=728 : : ActiveRecord::UnknownAttributeError (unknown attribute: seats): : app/controllers/buses_controller.rb:31:in `new' : app/controllers/buses

security safe to disable csrf tokens for json rails calls?

。_饼干妹妹 提交于 2019-12-05 00:00:29
问题 I have an existing rails backend website which makes json calls to server. Now,I am developing a mobile iOS app to use the same backend and send calls in json. However, mobile requests are failing with: WARNING: Can't verify CSRF token authenticity Searching around stackoverflow, many suggested to disable csrf checks for json calls by using something like this: # Or this in your application_controller.rb def verified_request? if request.content_type == "application/json" true else super() end

Rails 3.1: javascripts not served correctly from vendor/assets directory?

放肆的年华 提交于 2019-12-04 23:38:37
I have organized my javascript files in a couple of directories and I have found the following strange behavior. Given the following tree: + app + assets + javascripts + common + public + common + home - home.js home.js looks like this: //= require jquery //= require jquery_ujs //= require jquery-ui //= require_directory ../../jquery_plugins //= require_directory ../../common //= require_directory ../common //= require_self Now the trick lies in the jquery_plugins directory. I placed this inside vendor/assets/javascripts (which is included in the asset load path, when I check Rails.application

How to make a respond_to by AJAX in Rails 3?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 23:08:56
I have a form, that I send with using AJAX. The form is in the FirstsController . I need the form send to SecondsController . The form is sent and data saved. Then I wanna change the form by a text, I try to do by this way: def create ...saving... respond_to do |format| format.js { render :update do |page|; page << "$('#id_element').html('hellllloooooo');" end } format.html {} end end And I ma getting this error: ActionView::MissingTemplate (Missing template seconds/update, application/update with {:handlers=>[:erb, :builder, :coffee], :formats=>[:js, :html], :locale=>[:en, :en]}.): How should

Precompiled CSS not found in Rails 3.1 production mode

梦想与她 提交于 2019-12-04 22:43:06
When I start up rails in production mode, it precompiles all the assets but is unable to serve the application.css asset. I looked in public/assets and the precompiled application.css exists. However, I get a 404 whenever I try to access it from the page. These are the instructions I use to launch the server, if that may help at all. RAILS_ENV=production bundle exec rake assets:clean RAILS_ENV=production bundle exec rake assets:precompile rails -e production If you want Rails to serve the static assets you have add the following line to your production.rb: config.serve_static_assets = true I

How do I change the default gemfile created with 'rails new' command?

牧云@^-^@ 提交于 2019-12-04 22:31:56
问题 I have recently experienced an issue where I must add the following to my gemfile: gem 'execjs' gem 'therubyracer' I must do this to avoid a javascript runtime error that occurs when starting the rails server. I would like to have this modification added to all new gemfiles created with the rails new command. 回答1: You're looking for application templates. 回答2: Rails documentation on Application Templates If you want the option to customize each app individually instead of having a rigid

when to put images to app/asssets and when to /public/images in rails 3.1?

二次信任 提交于 2019-12-04 22:25:59
问题 I still don't quite get it, where to put images in rails 3.1, in these situation: Images are processed (f.e. by paperclip or by dragonfly ) and stored in folder (not with external service like s3, ..f.e. in develompent) when I have just images, that I'll use in stylesheet (f.e. backrounds) Icons (AppStore, Facebook ...) thanx 回答1: Stylesheet images should be placed in app/assets, while files uploaded by paperclip in public/system. In case of assets , fingerprints will be created for every

Capistrano - can't deploy my database.yml

别等时光非礼了梦想. 提交于 2019-12-04 22:00:17
问题 When I try to deploy my app with capistrano, I'll get this error: failed: "sh -c 'cp /var/www/my_app/releases/20120313115055/config/database.staging.yml /var/www/my_app/releases/20120313115055/config/database.yml'" on IP_ADDR My database.yml ie empty, database.staging.yml : production: adapter: mysql2 encoding: utf8 reconnect: false database: my_db pool: 15 username: my_user_name password: my_pass host: localhost in the /confing/deploy are files "production" "staging" What am I missing here

remote select, controller needs more form data

偶尔善良 提交于 2019-12-04 21:53:42
I have two select fields in a form. Every time one of these select fields change value, the rest of the form should be changed. I used the following code for the select fields: <%= f.collection_select :model1, Model1.all, :id, :name, "data-remote" => true, "data-url" => "/model3/get_rest_form" %> <%= f.collection_select :model2, Model2.all, :id, :name, "data-remote" => true, "data-url" => "/model3/get_rest_form" %> The problem now is that the model3 controller needs the values of both select fields in order to formulate a response to the Ajax request sent to it, but it only gets the value of