ruby-on-rails-4

Get Two Rails apps to share the same Redis data

亡梦爱人 提交于 2021-01-28 05:36:36
问题 I have two rails apps. The first app constantly calculates some data and stores it in Redis (This app is running on JRuby 1.7.4 and Rails 4). The second app reads this data from the same Redis server (This app is running on Ruby 2.0.0 and Rails 4). After trying to achieve this configuration in my local development environment, it's apparent that my Redis data is not being shared between the two apps. In both apps, my config/initializers/redis.rb file looks like this: uri = URI.parse(ENV[

Problems upgrading Rails 4.0.0 to 4.0.x (4.0.13) - private method `include' called for ActionDispatch::Assertions:Module (NoMethodError)

試著忘記壹切 提交于 2021-01-28 05:11:13
问题 I could not find a "direct" answer to this anywhere. Since I know there will be many other "Late Upgraders" to the party, I feel I need to get this out. I had a Rails 4.0.0 app running Ruby 2.0.0-p247. After upgrading to 4.0.13, I ran into this error: private method `include' called for ActionDispatch::Assertions:Module (NoMethodError) I received this through rspec and WEBrick. 回答1: I found a solution via another issue from layer-ruby: NoMethodError: private method `include' called for #

Monkey patching Rails

送分小仙女□ 提交于 2021-01-28 02:51:14
问题 I need to monkey-patch one of the Rails core classes, specifically ActionView::Helpers::UrlHelper::ClassMethods.link_to method. As far as I remember there are some events fired when parts of Rails are loaded, how to add handlers for them? Or should I just put the code into initializer? 回答1: link_to does not appear to be in ClassMethods. From here. In config/initializers/url_helper_extensions.rb module ActionView module Helpers module UrlHelper alias_method :_link_to, :link_to def link_to #

Monkey patching Rails

北城以北 提交于 2021-01-28 00:01:05
问题 I need to monkey-patch one of the Rails core classes, specifically ActionView::Helpers::UrlHelper::ClassMethods.link_to method. As far as I remember there are some events fired when parts of Rails are loaded, how to add handlers for them? Or should I just put the code into initializer? 回答1: link_to does not appear to be in ClassMethods. From here. In config/initializers/url_helper_extensions.rb module ActionView module Helpers module UrlHelper alias_method :_link_to, :link_to def link_to #

Hide ActionController::RoutingError in logs for assets

柔情痞子 提交于 2021-01-27 07:13:04
问题 I am working on a rails app that has a WP home page, and also some images that are being load from WP. On localhost we don't have access to WP content that leads to having a lot of routing errors in logs, in example: Started GET "/wp-content/uploads/2014/03/facebook-icon1.png" for 127.0.0.1 at 2015-11-20 15:10:48 +0200 ActionController::RoutingError (No route matches [GET] "/wp-content/uploads/2014/03/facebook-icon1.png"): actionpack (4.2.5) lib/action_dispatch/middleware/debug_exceptions.rb

ruby on rails: heroku: Missing `secret_key_base` for 'production' environment

大憨熊 提交于 2021-01-27 04:21:05
问题 I added the key into heroku config var, but I'm still getting the error. Is this the correct way? I ignored secrets.yml as I read from other sources that its not a good idea to push this to the public. in the heroku config var: [key] SECRET_KEY_BASE [value] 3280570382948240938 in secrets.yml production: secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> What am I still doing wrong? Furthermore, if I put my secret keys into heroku's config variable, don't other developers get to see this too? So,

ruby on rails: heroku: Missing `secret_key_base` for 'production' environment

旧街凉风 提交于 2021-01-27 04:19:31
问题 I added the key into heroku config var, but I'm still getting the error. Is this the correct way? I ignored secrets.yml as I read from other sources that its not a good idea to push this to the public. in the heroku config var: [key] SECRET_KEY_BASE [value] 3280570382948240938 in secrets.yml production: secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> What am I still doing wrong? Furthermore, if I put my secret keys into heroku's config variable, don't other developers get to see this too? So,

How should I use Rails to index and query a join table?

半世苍凉 提交于 2021-01-27 04:16:56
问题 I have a ruby on Rails 4 app, using devise and with a User model and a Deal model. I am creating a user_deals table for has_many/has_many relationship between User and Deal. Here is the migration class CreateUserDeals < ActiveRecord::Migration def change create_table :user_deals do |t| t.belongs_to :user t.belongs_to :deal t.integer :nb_views t.timestamps end end end When a user load a Deal (for example Deal id= 4), I use a method called show controllers/deal.rb #for the view of the Deal page

Rails 4: Save Checkbox Results to Serialized Array

十年热恋 提交于 2021-01-26 09:20:50
问题 I have a Campaign model with a channel column. This channel will store a serialized array of chosen results via checkboxes. Here's the model.. app/models/campaign.rb class Campaign < ActiveRecord::Base serialize :channels, Array end app/controllers/compaigns_controller.rb class CampaignsController < ApplicationController def index @campaigns = Campaign.all.order("created_at DESC") end def new @campaign = Campaign.new end def create @campaign = Campaign.new(campaign_params) if @campaign.save

Rails 4: Save Checkbox Results to Serialized Array

坚强是说给别人听的谎言 提交于 2021-01-26 09:17:09
问题 I have a Campaign model with a channel column. This channel will store a serialized array of chosen results via checkboxes. Here's the model.. app/models/campaign.rb class Campaign < ActiveRecord::Base serialize :channels, Array end app/controllers/compaigns_controller.rb class CampaignsController < ApplicationController def index @campaigns = Campaign.all.order("created_at DESC") end def new @campaign = Campaign.new end def create @campaign = Campaign.new(campaign_params) if @campaign.save