ruby-on-rails-3

Rails include javascripts assets folder recursively

谁说胖子不能爱 提交于 2020-01-01 03:58:08
问题 I understand how to add one javascript file to rails assets pipeline. Just add //= require filename to application.js But how can I include many javscripts files under one folder vendor/assets/javascripts/<js_library> Or I have to list them all explicitly ? 回答1: //= require_tree . will require everything in the current directory of your application.js //= require_tree ./js_library will require everything in the js_library subdirectory if it is under app/assets/javascripts If you are are

JQuery + thumbs_up gem render vote count?

旧街凉风 提交于 2020-01-01 03:44:07
问题 Plugins: Thumbs Up & JQuery 1.5.2 (needed for another old gem) I'm trying to render an updated vote count w/o a full HTTP request when a user votes on a post. Currently, it refreshes the page on every vote. Posts Controller def vote_up post = Post.find(params[:id]) current_user.vote_exclusively_for(post) respond_to do |format| format.js format.html {rRedirect_to :back} end end def vote_down post = Post.find(params[:id]) current_user.vote_exclusively_against(post) respond_to do |format| format

Rails How to use FactoryGirl in Seeds.rb?

与世无争的帅哥 提交于 2020-01-01 03:44:05
问题 I want to have the Seeds.rb file run a method in a file from the Rails.root.join('spec') directory which will fill the database with data generated by FactoryGirl. Lets call this file "helpers.rb" with the method "seed_data" Edit: require Rails.root.join('spec','helpers.rb') links the file. source This method I want to use in a before(:all) do seed_data end to seed the test database and rake db:seed for development/production databases with the same effect. 回答1: Seeds.rb require Rails.root

How to upgrade the :update=>'div_id' option of remote_form_for from Rails 2 to Rails 3?

北战南征 提交于 2020-01-01 03:38:06
问题 I can't figure out how to upgrade this code from Rails 2 to Rails 3: <% remote_form_for(item, :update => 'div_id') do |f| %> ... I tried this: <%= form_for :item, :remote => true, :url => { :controller => "items", :action => "create" }, :update => 'div_id' do |f| %> ... It creates the new item but it fails in updating the content within <div id="div_id"></div> tags. It seems Rails 3 no longer supports the " :update " option for a remote form_for . Any suggestion? 回答1: You could use RJS, but

How to copy rails app using git and deployed to heroku

青春壹個敷衍的年華 提交于 2020-01-01 03:36:06
问题 I'm new to programing and rails and I'd like to create a copy of a rails app I'm working with to harmlessly try out some things. Is there an easy way to make that happen? 回答1: Yes you can. These commands weren't obvious to a newbie like me and may help someone else... First, depending on what you plan on calling your new deployed app, find a name that is currently available on heroku. From root of old and to be created new rails app: $ cp -R old_directory new_directory $ cd new_directory $ rm

Does anybody have any tips for managing polymorphic nested resources in Rails 3?

此生再无相见时 提交于 2020-01-01 03:10:52
问题 In config/routes.rb: resources :posts do resources :comments end resources :pictures do resources :comments end I would like to allow for more things to be commented on as well. I'm currently using mongoid (mongomapper isn't as compatible with Rails 3 yet as I would like), and comments are an embedded resource (mongoid can't yet handle polymorphic relational resources), which means that I do need the parent resource in order to find the comment. Are there any elegant ways to handle some of

Devise not working well with multiple subdomains on RoR3 application

徘徊边缘 提交于 2020-01-01 02:46:08
问题 I have seen a lot of questions about this topic, but a lot of them have contradictory information, and for some reason it didnt work for me. I have: a top level domain: i.e. lvh.me (development). each user has subdomains: i.e. userdomain.lvh.me The login form is in the top level domain: lvh.me I want: If an user logs in, the session needs to be shared between all the subdomains. I mean, the session needs to be active in lvh.me:3000/something and userdomain.lvh.me:3000 If an user logs out from

Howto: Model scope for todays records

妖精的绣舞 提交于 2020-01-01 02:46:07
问题 Hey, how do I set a scope in rails 3 to todays records? This doent work, yet. I get no data. class MyModel < ActiveRecord::Base scope :today, :conditions => { :created_at => Date.today } end 回答1: Since "created_at" column contains date and time, but you need compare only date, you have two ways (I assume you use MySQL) : use BETWEEN : scope :today, lambda { WHERE("created_at BETWEEN '#{DateTime.now.beginning_of_day}' AND '#{DateTime.now.end_of_day}'") } use DATE() function: scope :today,

Why I am getting Could not find multi_json-1.3.1 in any of the sources?

荒凉一梦 提交于 2020-01-01 02:45:09
问题 I have a simple Rails application I want to deploy to Heroku. When I run the below command git push heroku master The below error message is displayed. Could not find multi_json-1.3.1 in any of the sources ! ! Failed to install gems via Bundler. ! ! Heroku push rejected, failed to compile Ruby/rails app Here is my Gemfile gem 'rails', '3.2.3' gem 'pg' group :assets do gem 'sass-rails', '~> 3.2.3' gem 'coffee-rails', '~> 3.2.1' gem 'therubyracer', :platform => :ruby gem 'uglifier', '>= 1.0.3'

Rails: Options for build bundler gemfile

此生再无相见时 提交于 2020-01-01 02:44:09
问题 I have a gem, that must be build with some options. gem install pg --with-pg-include=/Library/PostgreSQL/9.0/include/ --with-pg-lib=/Library/PostgreSQL/9.0/lib/ Can I include this options in the Gemfile? In my Gemfile the pg command is gem "pg", "0.12.2" I want to provide some options after the version number. thx, tux 回答1: Here is the relevant text from the link posted in comments already: BUILD OPTIONS You can use bundle config to give bundler the flags to pass to the gem installer every