ruby-on-rails-3

Rails scaffolding pluralisation is incorrect for “cafe”

天大地大妈咪最大 提交于 2020-01-12 02:26:13
问题 I want to create a cafe and a cave controller. When I try to create my cafe using rails scaffolding, via the command rails g scaffold cafe name:string It is deriving the plural form of "cafe" as "caves", which means I can't make my caves controller since the name is already used. How can I make rails use the correct pluralisation? 回答1: You can create your own inflections. Add this to your config/initializers/inflections.rb ActiveSupport::Inflector.inflections do |inflect| inflect.plural "cafe

Rails3 get current layout name inside view

五迷三道 提交于 2020-01-12 01:47:27
问题 I have the answer for the Rails 2.X but not for Rails 3. How can I read the name of a current layout rendered inside a view. My Rails2 question: Rails Layout name inside view Thx. 回答1: Getting this to work in Rails 3.2 is a little more complicated than previously outlined. If your controller explicitly declares a layout, then the result of controller.send(:_layout) is a String, but otherwise it's an ActionView::Template. Try this: module ApplicationHelper def current_layout layout =

Rails 3 - link_to with image_tag + text

大城市里の小女人 提交于 2020-01-11 22:51:29
问题 <%= link_to ((image_tag 'image.png'), url_for({:controller => 'controller_name', :action => 'action_name'}), :class => 'quick', :remote => true) %> This part of code will generate me image.png as a link. I would need to this image append some text (image + text), I tried something like a: <%= link_to ((image_tag 'image.png', 'text'), url_for({:controller => 'controller_name', :action => 'action_name'}), :class => 'quick', :remote => true) %> And similar ways, but each of these attempts ended

How to install Rails 3 master from GitHub

淺唱寂寞╮ 提交于 2020-01-11 20:01:29
问题 I'm using rvm (Ruby Version Manager) and running Rails 3 RC. I need to test an app to see if a bug has been resolved with a recent commit to Rails 3 master on GitHub. How do I install Rails 3 master from GitHub and then generate a new app? I can't use gem install rails --pre because I want the edge version, not the release candidate. Can you suggest a helpful gist or blog post? All I could find was this: http://weblog.rubyonrails.org/2010/1/1/getting-a-new-app-running-on-edge and it is out-of

How to install Rails 3 master from GitHub

帅比萌擦擦* 提交于 2020-01-11 20:01:00
问题 I'm using rvm (Ruby Version Manager) and running Rails 3 RC. I need to test an app to see if a bug has been resolved with a recent commit to Rails 3 master on GitHub. How do I install Rails 3 master from GitHub and then generate a new app? I can't use gem install rails --pre because I want the edge version, not the release candidate. Can you suggest a helpful gist or blog post? All I could find was this: http://weblog.rubyonrails.org/2010/1/1/getting-a-new-app-running-on-edge and it is out-of

How can I tell Rails to use RSpec instead of test-unit when creating a new Rails app?

我是研究僧i 提交于 2020-01-11 14:50:09
问题 I have test-unit installed and rspec installed (along with -core , -expectations , -mocks and -rails version 2.6.x). When I run the command rails new foo , it uses test-unit to generate the test stub files instead of rspec . Is there an option where I can tell rails to use rspec to generate the tests instead? 回答1: The following should work: at command line: rails new MYAPP -T # The -T option tells rails not to include Test::Unit in Gemfile: gem 'rspec-rails' at command line: bundle install

Jquery not working in rails 3.2 app?

别等时光非礼了梦想. 提交于 2020-01-11 14:26:10
问题 Trying to get a simple show/hide going.. Its working in js fiddle just not in my app.. In my views/user_steps/interests.html.erb <label class="checkbox"> <input id="user_holiday_ids_" name="user[holiday_ids][]" type="checkbox" value="2" /> Valentine Day </label> <div style="display:none;"> Whatever you have to capture here<input type="text" id="foo" /> </div> </br> <label class="checkbox"> <input id="user_holiday_ids_" name="user[holiday_ids][]" type="checkbox" value="3" /> Easter </label>

Rails not serving assets in production or staging environments

萝らか妹 提交于 2020-01-11 09:27:11
问题 In the process of debugging this problem, I have tried to run my application in production mode locally and it doesn't serve up any assets. Additionally, I have a staging environment in a Heroku application (separate from my production Heroku application) which is also now displaying the HTML without any assets. To debug, I: Kill the server Clear out tmp/cache/assets Delete public/assets Run rake assets:precompile Start up the server rails s -e production Visit the page and open up web

Add space after commas only if it doesn't already?

泪湿孤枕 提交于 2020-01-11 07:11:41
问题 Is there a way to add a space after commas in a string only if it doesn't exist. Example: word word,word,word, Would end up as word word, word, word, Is there a function in ruby or rails to do this? This will be used on hundreds of thousands of sentences, so it needs to be fast (performance would matter). 回答1: Using negative lookahead to check no space after comma, then replace with comma and space. print 'word word,word,word,'.gsub(/,(?![ ])/, ', ') 回答2: Just use a regular expression to

Can the merit gem recalculate reputation and re-evaluate badges and ranks?

故事扮演 提交于 2020-01-11 05:44:09
问题 I would like to add a system of points, ranks and badges in my rails app. The merit gem looks cool, but I want to make sure how it works before using it. The way you define badges # app/models/merit/badge_rules.rb grant_on 'comments#vote', :badge => 'relevant-commenter', :to => :user do |comment| comment.votes.count == 5 end and points # app/models/merit/point_rules.rb score 10, :to => :post_creator, :on => 'comments#create' do |comment| comment.title.present? end suggest that the action is