ruby-on-rails-3.1

Ruby on Rails 3.1 and jQuery UI images

六月ゝ 毕业季﹏ 提交于 2019-11-28 15:19:27
I'm using Ruby on Rails (Edge, the development version), and Ruby rvm 1.9.2. application.js is as follows. //= require jquery //= require jquery-ui //= require jquery_ujs //= require_tree Where is the right place in Ruby on Rails 3.1 to put the jQuery UI theme? According to Autocomplete fields in Ruby on Rails 3.1 with jQuery UI I should put a jQuery UI theme in vendor/assets/stylesheets folder. That sounds like a smart place to have it, but I don't get it to work :-(. I managed to get the CSS loaded by putting it in the assets/stylesheets folder, but the images I havn't managed to get loaded.

Rails 3.1+ Nested Forms Issue: Can't mass-assign protected attributes

半世苍凉 提交于 2019-11-28 14:24:28
I have a basketball app, where a Roster has many Players, and a Player can be on multiple Rosters.(Reason for many-to-many is for a Player-Roster archive) Roster.rb class Roster < ActiveRecord::Base belongs_to :team has_many :rosterizes has_many :players, :through => :rosterizes accepts_nested_attributes_for :players attr_accessible :jersey_number, :team_id, :class_year, :players end Rosterizes.rb (poorly named I know...) class Rosterize < ActiveRecord::Base belongs_to :player belongs_to :roster attr_accessible :player_id, :roster_id end Player.rb class Player < ActiveRecord::Base has_many

Ruby on Rails: How can I revert a migration with rake db:migrate?

元气小坏坏 提交于 2019-11-28 14:24:00
问题 After installing devise MODEL User i got this. class DeviseCreateUsers < ActiveRecord::Migration def self.up create_table(:users) do |t| t.database_authenticatable :null => false t.recoverable t.rememberable t.trackable # t.encryptable # t.confirmable # t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both # t.token_authenticatable t.timestamps end add_index :users, :email, :unique => true add_index :users, :reset_password_token, :unique => true # add_index :users,

bundle exec rake assets:precompile fails with `unexpected token`

若如初见. 提交于 2019-11-28 11:10:10
I'm ready to deploy my Rails 3.1 app into production, and since I'm using the asset pipeline, I need to precompile my assets . However, when I try this, I get an error apparently related to compiling jQuery: $ bundle exec rake --trace assets:precompile ** Invoke assets:precompile (first_time) ** Execute assets:precompile /home/adam/.rvm/rubies/ruby-1.9.3-p0/bin/ruby /home/adam/.rvm/gems/ruby-1.9.3-p0@rails-3.1/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace ** Invoke assets:precompile:all (first_time) ** Execute assets:precompile:all ** Invoke assets:precompile

How can I check a word is already all uppercase in Ruby?

旧时模样 提交于 2019-11-28 10:43:40
I want to be able to check if a word is ALREADY all uppercase. And it might also include numbers. Example: GO234 => yes Go234 => no You can compare the string with the same string but in uppercase: 'go234' == 'go234'.upcase #=> false 'GO234' == 'GO234'.upcase #=> true Hope this helps a = "Go234" a.match(/\p{Lower}/) # => #<MatchData "o"> b = "GO234" b.match(/\p{Lower}/) # => nil c = "123" c.match(/\p{Lower}/) # => nil d = "µ" d.match(/\p{Lower}/) # => #<MatchData "µ"> So when the match result is nil, it is in uppercase already, else something is in lowercase. Thank you @mu is too short

What is the purpose of config.assets.precompile?

让人想犯罪 __ 提交于 2019-11-28 08:56:48
In Rails 3.1, you must whitelist files that you want included in asset precompilation. You must open up config/environments/production.rb and explicitly include assets you want precompiled: config.assets.precompile += ['somestylesheet.css'] If you don't do this this and you run rake assets:precompile , your asset will not be copied to public/assets, and your app with raise an exception(therefore causing a 500 error in production) when an asset is not found. Why is this necessary? Why aren't all assets automatically precompiled? This current approach creates extra code and stress when deploying

Cucumber Rails 3.1 uninitialized constant ActionController::Dispatcher (NameError)

强颜欢笑 提交于 2019-11-28 07:59:25
问题 I am using a Rails 3.1 application and I was integrating cucumber to my app but when i try to run it I get this strange error, can someone help me please? Using the default profile... uninitialized constant ActionController::Dispatcher (NameError) /Users/chinog9/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-rails-0.3.2/lib/cucumber/rails/action_controller.rb:51:in `rescue in <top (required)>' /Users/chinog9/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-rails-0.3.2/lib/cucumber/rails/action_controller.rb

Redirect user after log in only if it's on root_path

本秂侑毒 提交于 2019-11-28 07:44:10
I have a root_path on my Rails application that is not user-protected i.e. it's a simple portal homepage, with a login form. After the users log in, I'd like it to go to dashboard_path . I've done this: def signed_in_root_path(scope_or_resource) dashboard_path end This apparently should be used when an user signs in, and I don't want it to go to the root_path , while still keeping the user going back to a previous page if it tries to hit a restricted area and it's either timed out or not logged in. i.e.: restricted_page -> login -> restricted_page_but_logged_in I don't want to change this

How does one reference compiled assets from the controller in Rails 3.1?

会有一股神秘感。 提交于 2019-11-28 07:29:23
I'm using the PDFkit in my controller to build out a series of PDFs, zip them up, and then send them to the user. In order to control the output styles, I tell PDFKit which stylesheets to use during content generation. I need to pass along the file reference of the CSS file. Since Rails is now compiling and renaming my stylesheets, I'm not sure how to reference the compiled CSS asset inside my controller. Here's what I used to do: InvoicesController < ApplicationController def download kit = PDFKit.new(render_to_string(:show, :layout => false)) kit.stylesheets << "#{Sass::Plugin.options[:css

what is the difference between link_to, redirect_to, and render?

旧城冷巷雨未停 提交于 2019-11-28 07:16:29
I am confused about the main difference(s) among link_to , redirect_to and render in Rails. anyone can please explain. link_to is used in your view, and generates html code for a link <%= link_to "Google", "http://google.com" %> This will generate in your view the following html <a href="http://google.com">Google</a> redirect_to and render are used in your controller to reply to a request. redirect_to will simply redirect the request to a new URL, if in your controller you add redirect_to "http://google.com" anyone accessing your page will effectively be redirected to Google render can be used