ruby-on-rails-3

newbie: append serialized integers into database column and retrieve them back

安稳与你 提交于 2019-12-30 11:53:41
问题 How Could I store integers (user id's ranging from 1 to 9999) serialized in a database column and retrieve them back? In my User model I have invites column, User model serialize: invites invites = text field Now I'm trying to do 2 things: Append the user_id integer (from 1 to 9999) serialized in a column "invites" Retrieve all the user id's back from the User.invited column ( deserialize it ? ) 回答1: From the fine manual: serialize(attr_name, class_name = Object) If you have an attribute that

Rails 3.1 Asset Pipeline - Why should I use the Asset Helpers in a SCSS file?

为君一笑 提交于 2019-12-30 11:38:31
问题 I'm just getting into the Asset Pipeline; I'm using SASS/SCSS, but I'm not understanding why I should be using the Asset Helpers. For example, if I have some CSS/SCSS without using an Asset Helper: background-image: url('rails.png'); This will work fine because both my .SCSS file and image are in and accessible through the assets directory. What's the point of doing this?: background-image: asset-url("rails.png", image); I understand it will add "/assets/" to the url, but why should I be

Initialize the Delayed Jobs gem by starting the workers on application start

眉间皱痕 提交于 2019-12-30 11:35:43
问题 I am using Ruby on Rails 3.0.9 and I am trying to setup the delay_job gem. All works if, after rebooting the Apache2 server, I run in the Terminal\Console following commands: RAILS_ENV=development script/delayed_job stop RAILS_ENV=development script/delayed_job -n 2 start However, since I always want to start the workers on application start, in my config/initializers/delayed_job.rb I add the following code (that handles both development and production mode): if Rails.env.development? system

Building Ruby on Rails App with an existing Mysql db

為{幸葍}努か 提交于 2019-12-30 11:15:09
问题 I have a Mysql database with a large amount of data and tables. But i need to know how to use this Mysql data in the my new rails application. I've been learning Rails from a little time now. i know the basics of creating a scaffold which in turn creates models and controllers, but i'm unclear how to import a DB and use it. Can anyone explain or provide me with a link on how to get over this. This is my migration after running a simple scaffold and i ran rake db:migrate after adding an email

Resque Mysql2::Error: User has exceeded the 'max_user_connections' resource (current value: 10)

和自甴很熟 提交于 2019-12-30 10:59:07
问题 I am running Resque on Heroku, and my database is ClearDB. I am getting this error: "Mysql2::Error: User 'bdb2aedbee2c38' has exceeded the 'max_user_connections' resource (current value: 10): SHOW FULL FIELDS FROM projects " That error is coming from my Resque admin of my Heroku app. How can I figure out how many connections Resque is making to ClearDB? How can I tell ClearDB to either allow more connections, or tell Resque to create less? Does "current value: 10" refer to how many

How to put a login form in the header for Devise and Rails

烈酒焚心 提交于 2019-12-30 10:39:50
问题 I want to put a login form in the header of my website. I use Rails 3.2.8 and the latest Devise. In the app/views/devise/sessions/new.html.erb file a login form is created with: <%= form_for(resource, :as => resource_name, :url => session_path(resource_name), :html => {:class => 'main'}) do |f| %> <div><%= f.label :login %> <%= f.text_field :login, :placeholder => 'Enter username' %></div> <div><%= f.label :password %> <%= f.password_field :password, :placeholder => 'Enter password' %></div>

How to put a login form in the header for Devise and Rails

╄→гoц情女王★ 提交于 2019-12-30 10:39:28
问题 I want to put a login form in the header of my website. I use Rails 3.2.8 and the latest Devise. In the app/views/devise/sessions/new.html.erb file a login form is created with: <%= form_for(resource, :as => resource_name, :url => session_path(resource_name), :html => {:class => 'main'}) do |f| %> <div><%= f.label :login %> <%= f.text_field :login, :placeholder => 'Enter username' %></div> <div><%= f.label :password %> <%= f.password_field :password, :placeholder => 'Enter password' %></div>

Rails - how to store large numbers like 100000076685963

前提是你 提交于 2019-12-30 10:38:49
问题 I need to store large numbers like :100000076685963 Which are to big for a db field type of integer. In my db migration I use: t.integer :fb_uid what field type should I use for large numbers like this? Thanks 回答1: You can use a fixed-point datatype such as decimal with a large precision. Based on the number you've given, a precision of 15 will work but you should figure out exactly what range you are expecting. t.decimal :fb_fluid, :precision => 15 回答2: Try float t.float :fb_uid And seems

How can I make rake tasks run in an environment other than dev?

强颜欢笑 提交于 2019-12-30 10:29:30
问题 I have a staging machine with a special "staging" environment. I always forget to run rake tasks on that machine like: rake jobs:work RAILS_ENV=staging So instead I end up doing: rake jobs:work And then I'm mystified why nothing has changed in my database. Doh! It's because I didn't remember to supply RAILS_ENV=staging. But I will never, ever need to run anything as the development environment on that server. How can I make rake tasks run in the "staging" environment by default? 回答1: You can

Rails 3 Sending errors to email

末鹿安然 提交于 2019-12-30 10:16:14
问题 How do I hijack Rails (3) error handling to email errors with full trace to me? 回答1: Have your considered HopToad? UPDATE: HopToad is now known as Airbrake 回答2: Exception Notifier Plugin for Rails https://github.com/smartinez87/exception_notification 回答3: Haven't done it myself yet, but you should be able to use the log4r gem and substitute that for the stock rails logger. This can be done in environment.rb , see for example this blog post. Then you would instruct log4r to send emails on