ruby-on-rails-3.1

when to put images to app/asssets and when to /public/images in rails 3.1?

大憨熊 提交于 2019-12-03 13:49:40
I still don't quite get it, where to put images in rails 3.1, in these situation: Images are processed (f.e. by paperclip or by dragonfly ) and stored in folder (not with external service like s3, ..f.e. in develompent) when I have just images, that I'll use in stylesheet (f.e. backrounds) Icons (AppStore, Facebook ...) thanx Stylesheet images should be placed in app/assets, while files uploaded by paperclip in public/system. In case of assets , fingerprints will be created for every file, so they can be properly cached. If cached file changes, fingerprint changes too and in such way cache is

instant messenger implementation for rails?

限于喜欢 提交于 2019-12-03 13:31:58
问题 I have searched for some time investigating several technologies to build an simple instant messaging system for a ruby on rails app. It seems very complicated as I haven't found any implementations that are cross browser or any 1-1 proof of concept at all. Looked into: xmpp clients ( there is Candy on github only supports group chat ) xmpp servers & Rails ( lot of hassle no good integration ) Juggernaut ( no 1-1 , not supported by Internet Explorer cause of web sockets used) Private Pub by

How do I change the default gemfile created with 'rails new' command?

只谈情不闲聊 提交于 2019-12-03 13:30:42
I have recently experienced an issue where I must add the following to my gemfile: gem 'execjs' gem 'therubyracer' I must do this to avoid a javascript runtime error that occurs when starting the rails server. I would like to have this modification added to all new gemfiles created with the rails new command. You're looking for application templates . Rails documentation on Application Templates If you want the option to customize each app individually instead of having a rigid template, a really good option is Rails Composer . It prompts you about common gems during setup, and it nails a lot

Ruby/Rails 3.1: Given a URL string, remove path

落花浮王杯 提交于 2019-12-03 13:00:07
Given any valid HTTP/HTTPS string, I would like to parse/transform it such that the end result is exactly the root of the string. So given URLs: http://foo.example.com:8080/whatsit/foo.bar?x=y https://example.net/ I would like the results: http://foo.example.com:8080/ https://example.net/ I found the documentation for URI::Parser not super approachable. My initial, naïve solution would be a simple regex like: /\A(https?:\/\/[^\/]+\/)/ (That is: Match up to the first slash after the protocol.) Thoughts & solutions welcome. And apologies if this is a duplicate, but my search results weren't

How to do joins on subqueries in AREL within Rails

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 12:58:13
I have a simple model class User has_many :logs class Logs related in the usual way through the foreign key logs.user_id. I'm trying to do the following using Arel and according to the Arel doc it should work. u_t = Arel::Table::new :users l_t = Arel::Table::new :logs counts = l_t. group(l_t[:user_id]). project( l_t[:user_id].as("user_id"), l_t[:user_id].count.as("count_all") ) l_t.joins(counts).on(l_t[:id].eq(counts[:user_id])) When I do that I get the error TypeError: Cannot visit Arel::SelectManager However the author of Arel explicitly suggests that Arel can do this kind of thing. Please

How to pass a parameter to controller action from view in rails through link_to helper

自闭症网瘾萝莉.ら 提交于 2019-12-03 12:47:36
问题 <%= link_to "Connect", {controller:"home", action:"connectTo"}, id: "btny" %> This is my link_to helper in view. I want to attach a parameter in this link_to tag so that I can get it in the action connectTo . I'm unable to find correct syntax or way to do it, and unable to understand some answers I found on stackoverflow. How can I achieve this? def connectTo #here i want to get the parameter i pass from link_to from view... end 回答1: Do not use camel case in variable names and method names in

Mocking file uploads in Rails 3.1 controller tests

放肆的年华 提交于 2019-12-03 12:40:14
My controller accesses the tempfile attribute of an uploaded file and passes it to another mocked component. My test code has @file = mock(Object) @file.stub_chain(:tempfile, :path).and_return('thefile.zip') # ... post :create, :file => @file and the controller code calls params[:file].tempfile.path . After upgrading from Rails 3.0 to 3.1, the above line started failing with undefined method `tempfile' for "#[RSpec::Mocks::Mock:0x2b0d9a0 @name=Object]":String That is, Rails 3.1 converted params[:file] to a string automatically. The code works properly when tested manually through a browser. I

Mongoid and has_secure_password

半世苍凉 提交于 2019-12-03 12:09:37
I am trying to use rails 3.1 authentication using mongoid instead of active model class User include Mongoid::Document include ActiveModel::SecurePassword has_secure_password validates_presence_of :password, :on => :create attr_accessor :email, :password, :password_confirmation field :email, :type => String field :password_digest, :type => String end the problem is password_digest is not recognized by the bycrypt as in active model example http://railscasts.com/episodes/270-authentication-in-rails-3-1 Thanks Put has_secure_password After field :password_digest, :type => String For anyone who

SASS, Rails 3.1: Loading stylesheets in vendor/assets

时光怂恿深爱的人放手 提交于 2019-12-03 12:08:32
问题 I'm using SASS to load stylesheets in a Rails 3.1(sass-rails 3.1) app. For example, sass partials in app/assets/stylesheets are loaded using @import in application.sass - @import "pages/common" @import "pages/**/*" @import "jquery-ui.css" Now, I also want to load vendor/assets/stylesheets . Note that I'm not using require vendor , as @import pages/* seems to be the sass recommended way of doing it. Files here will be css , and not sass or scss . I cannot use @import ../../../vendor/assets

Override Rails controller routing with capital letters in model name

…衆ロ難τιáo~ 提交于 2019-12-03 11:58:28
问题 I want to create a model in rails: rails generate model ABCThing So this will create a table, abc_things . Great. The problem comes with the controller and routing. I want my controller to be: class ABCThingsController < ApplicationController end However, after adding in the routes.rb resources :abc_things, :only => [:index] and creating the corresponding index view, i get the following error in the browser: Expected /app/controllers/abc_things_controller.rb to define AbcThingsController The