ruby-on-rails-3

Permanent variable in Rails

ぃ、小莉子 提交于 2020-01-14 13:28:06
问题 Lets say that on top of my Rails app there is a bar with piece of text displayed - latest hot deal, scheduled downtime notfication, something like that. It's a single, on of a kind information that needs to be accessed on basically every request, and may be updated from time to time. What is the best way to achieve this? What I'd like to do is some kind of permanent global variable (accessible from controllers). It will be updated very rarely, so there's no problem if for some time after

Rails3 dynamic_form plugin not recognized?

痴心易碎 提交于 2020-01-14 13:14:27
问题 Using Ruby 1.9.2 and Rails 3 - When attempting to use <%= error_messages_for 'story' %> I get this error: DEPRECATION WARNING: error_messages_for was removed from Rails and is now available as a plugin. Please install it with `rails plugin install git://github.com/rails/dynamic_form.git`. (called from _app_views_stories_new_html_erb__1042605186_33967248__100840187 at C:/Ruby192/shovell/app/views/stories/new.html.erb:1) So I did what it said and ran the plugin install. However now I have an

Auto-removing all newlines from Haml output

对着背影说爱祢 提交于 2020-01-14 13:09:30
问题 I'm using Haml in a Rails 3 app, and its newlines drive me nuts! For example, %span foo renders as <span> foo </span> But I'd much rather want <span>foo</foo> The reason (apart from being cleaner XML) is that extra newlines are a problem for my Selenium tests because they mess up the ability to do XPath queries like "//span[.='foo']" . So I'd have to write '\nfoo\n' instead (ew!), or use //span[contains(text(), 'foo')] , which matches too broadly. I know I could use the alligator operators ("

Capistrano 3 runs every command twice (new install) - Configuration issue

空扰寡人 提交于 2020-01-14 12:16:08
问题 I just completed my capistrano installation for the first time. Most of everything is left to default settings, I configured my server, its authentification, and the remote folder, as well as the access to my git repository. I use capistrano to deploy php code to my server. cap staging deploy and cap production deploy function, but they run every command twice . It sometimes causes problems when those tasks are executed too quickly on the server, returning error codes, which stops the

Devise: Suddenly cannot log in anymore

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-14 09:46:08
问题 I'm using Devise 1.3.4 for authentication for the backend in my app. For a couple of days now I cannot log in anymore. What happens is: I go to the login page /admin/sign_in Log in with good credentials See in the log that the login worked (last_sign_in_at, current_sign_in_at and current_sign_in_ip are set, sign_in_count is increased) Devise sessions controller tries to forward me to the after_sign_in_path_for I specified in my application controller (Admin::DashboardsController#show) Then

Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true

╄→гoц情女王★ 提交于 2020-01-14 09:42:50
问题 I'm reading through Rails 4 in Action. I'm getting the aforementioned error while testing with Rspec and Capybara. My viewing_projects_spec.rb looks like this: require 'spec_helper' feature "Viewing projects" do scenario "Listing all projectcs" do project = FactoryGirl.create(:project, name: "TextMate 2") visit '/' click_link 'TextMate 2' expect(page.current_url).to eql(project_url(project)) end end The rest of the error says Failure/Error: expect(page.current_url).to eql(project_url(project)

Rails 3: How to validate that A < B where A and B are both model attributes?

穿精又带淫゛_ 提交于 2020-01-14 08:01:06
问题 I would like to validate that customer_price >= my_price . I tried the following: class Product < ActiveRecord::Base attr_accessor :my_price validates_numericality_of :customer_price, :greater_than_or_equal_to => my_price ... end ( customer_price is a column in the Products table in the database, while my_price isn't.) Here is the result: NameError in ProductsController#index undefined local variable or method `my_price' for #<Class:0x313b648> What is the right way to do this in Rails 3 ? 回答1

Ruby - Exception occured: [Mysql2::Error] closed MySQL connection

喜欢而已 提交于 2020-01-14 07:27:30
问题 I have a Rails application now only runs internally, so there's not so much visits right now. And there're two resque worker running hardly to fetch data from the web and inserts into a mysql database, every insert will followed by sleep 10 second. We run it on a VPS. After like every 5 hours, I will encounter an Exception Exception occured: [Mysql2::Error] closed MySQL connection" . What could be the reason causing the exception? Now the pool size is 5. Will it help if I raise the pool size

best_in_place “:nil” function does not work in AJAX inserted partial

时光总嘲笑我的痴心妄想 提交于 2020-01-14 07:12:32
问题 I have a list of records on my page. I submit a form remotely via AJAX and the new record is appended to the list. All best_in_place features immediately work apart from the :nil option. This doesn't display the default value that I set. This makes it impossible to edit the value unless the user refreshes the page. Then the value is present and the user can click. Is this a known bug? Can anyone suggest a work around? Updated with my code: <%= best_in_place_if can?(:update, post), post, :post

How to profile a rails controller that returns a json response with rack-mini-profiler?

本小妞迷上赌 提交于 2020-01-14 07:03:48
问题 I am using rack-mini-profiler in my rails 3.2 project. In gemfile: gem 'rack-mini-profiler' Everything works great. But my application is mostly a set of json endpoints. So while it is very useful to be to able to inspect the performance of html pages, I would like to also be able to see the performance of controllers that return json. Example of my controller: class UsersController < BaseController def json_method # you don't see the mini profiler ui for this controller render json: { users: