ruby-on-rails-3.2

How to create another object when creating a Devise User from their registration form in Rails?

徘徊边缘 提交于 2019-12-04 13:44:35
问题 There are different kinds of users in my system. One kind is, let's say, a designer: class Designer < ActiveRecord::Base attr_accessible :user_id, :portfolio_id, :some_designer_specific_field belongs_to :user belongs_to :portfolio end That is created immediately when the user signs up. So when a user fills out the sign_up form, a Devise User is created along with this Designer object with its user_id set to the new User that was created. It's easy enough if I have access to the code of the

Easiest way to store images in database on Heroku?

♀尐吖头ヾ 提交于 2019-12-04 13:44:28
问题 We have a RoR 3.2 site on Heroku using their production tier PostgreSQL database. Our site users occasionally upload images of 0.5 - 2MB in size. For different reasons we want to store those images in the database, rather than as files on S3 or similar. If our site was image heavy, i.e. a Facebook clone, surely storing images in the db would not be a good thing. Anyway, it is not, so here are some of the reasons for wanting to store a users images in the database: Control over everything: S3

Nested Model Forms - Railscast #196 revised - Adding fields via jQuery not working

放肆的年华 提交于 2019-12-04 13:42:30
I was following the Railscast #196 revised and everything went basically fine, but I am not able to add new fields to the nested form. The "remove fields" function works nicely, but after click on "link_to_add_fields", the browser jumps to the top of the page, and no new field appears. There are already a ton of questions to this railscast, like here or here , and I tried to read all of them, but most of them are referring to the original casts from 2010. I am stuck for hours now, and I can't figure out, where my problem is. Sorry, if its a rookie mistake, I am quite new to rails. Any help

How can I make a custom environment in rails a default environment?

房东的猫 提交于 2019-12-04 13:33:12
问题 i created a custom staging environment in my rails app by adding new file config/environments/staging.rb , same as config/environments/development.rb and then added database config config/database.yml staging: adapter: sqlite3 database: db/staging.sqlite3 pool: 5 timeout: 5000 now, i want to make staging the default environment of my rails application instead of development.How to achieve it? 回答1: Ideally you have to set environment variable in .bashrc like export RAILS_ENV=staging because

Rails Render Partial in Helper

五迷三道 提交于 2019-12-04 13:32:38
问题 I have been trying to render one of my partials in a helper function located within my controller. The first issue I encountered was that the helper was returning the each loop instead of the result of the loop. To remedy this I attempted to have it return a string containing the results of the loop. def display_replies(comment) if comment.replies.count > 0 string = "" comment.replies.each do |reply, index| string = string + (render partial: "comment", locals: {index: index}).to_s.html_safe

How to upgrade Rails app from 2.3.5 to 3.2.x?

给你一囗甜甜゛ 提交于 2019-12-04 12:50:59
I have Rails 2.3.5 app, I want to upgrade to 3.2.x. How do I upgrade to Rails 3.2.x? Thanks juliehache I definitely recommend installing the Rails upgrade gem ( rails upgrade gem ). It's proven for me to be incredibly useful as a starting point for listing and verifying all the required upgrades to get to Rails 3.0. I would also recommend this ebook http://www.railsupgradehandbook.com/ Once you're at Rails 3.0, you'll need to migrate to the asset pipeline, this is another good starting point: http://railscasts.com/episodes/282-upgrading-to-rails-3-1 This won't be a simple task and you'll need

Pass Authenticity token through http header

怎甘沉沦 提交于 2019-12-04 12:50:42
I have a rails application that uses a token to authenticate the user. Currently I am passing the token as params. I would like to change this. I believe it is possible to pass it through html header. I dont understand how to use authenticate_or_request_with_http_token do |token, options| . My rails app is actually a server for my iphone client. I things I dont understand are: I know options is nonce but how will that work out between my client and server? How do I actually use this in my server code. I can use authenticate_or_request_with_http_token do |token, options| to check for token in

Passing a local variable to a partial that is rendered after the view has already loaded

徘徊边缘 提交于 2019-12-04 12:49:11
Update: I just found this other thread that explains why I am having this issue ( Pass local rails variable to javascript to partial ), but it did not list out the steps to fix it (or at least it skipped too many steps that I don't yet know how to do.) The issue seems to be that the local variable being passed to the partial is no longer the same local variable that existed when new.html.erb was loaded since the partial is not loaded until the click event. Is it possible to get around that? Thanks. Original: I have a click event tied to a link that only works some of the time and I am not sure

ActiveRecord :includes - how to use map with loaded associations?

孤街浪徒 提交于 2019-12-04 11:48:47
I have a small rails app, and I'm trying to get some order statistics. So I have an Admin model, and an Order model, with one-to-many association. class Admin < ActiveRecord::Base attr_accessible :name has_many :orders class Order < ActiveRecord::Base attr_accessible :operation belongs_to :admin And I'm trying to get specifical orders using this query: admins = Admin.where(...).includes(:orders).where('orders.operation = ?', 'new gifts!') That works just as expected. But when I try to make json using map like that admins.map {|a| [a.name, a.orders.pluck(:operation)]} Rails loads orders again

Ruby on Rails route for wildcard subdomains to a controller/action

拜拜、爱过 提交于 2019-12-04 11:19:38
问题 I dynamically create URLs of the form username.users.example.com : bob.users.example.com tim.users.example.com scott.users.example.com All of *.users.example.com requests should go to a particular controller/action. How do I specify this in routes.rb ? All other requests to www.example.com go to the normal list of routes in my routes.rb file. UPDATE : I watch the railscast about subdomains and it showed the following bit of code which would seem to be exactly what I need (changed the