ruby-on-rails-3.2

Why is ActiveRecord destroy_all taking so long?

大兔子大兔子 提交于 2019-12-11 04:48:53
问题 I have a simple rails app with articles and comments running on MySQL 5.5, Ruby 1.9.3 and rails 3.2.12: class Article < ActiveRecord::Base attr_accessible :body, :title has_many :comments end class Comment < ActiveRecord::Base attr_accessible :content belongs_to :article end I have generated lots of comments for an article, and am now trying to delete them all in the rails console: $ rails c Loading development environment (Rails 3.2.12) [1] pry(main)> a = Article.find(1) (2.0ms) SET SQL_AUTO

Looking for a good idea and a good Ruby structure

寵の児 提交于 2019-12-11 04:41:50
问题 I am writing a Rake task to populate a database for development purposes to have some data to work with. ( but In test I am using FactoryGirl, so not talking about that. ) So let's say I have two sample Organizations in my demo database, so I have defined them like this: sample_organizations = [ '37 Signals', 'Fog Creek'] and then a small method to populate the DB like this: def create_organizations sample_organization.each { |item| Organization.first_or_create( name: item, time_zone:

Datamapper & connection pool logic

独自空忆成欢 提交于 2019-12-11 04:02:13
问题 So I am trying to use datamapper inside my Rails 3.2.8 app. I have a config/initializers/dm.rb where I load the database.yml hash = YAML.load(File.new("database.yml")) DataMapper.setup(:default, hash[Rails.env]) I have a pool property set in the database.yml file, but I noticed that datamapper does not use that. It has this magic number 8 which it uses, where is this number coming from? And how can I configure pool settings for datamapper. 回答1: just after DataMapper.finalize I add this for my

Fullcalendar Rails- Event does not appear on the calendar

醉酒当歌 提交于 2019-12-11 03:13:28
问题 i have git clone fullcalendar_assets and it's running smoothly and event showing. my application rails 3.2.6 using postgresql for dbms. I try to apply fullcalendar in my application. but event not appear. to the point. on routes.rb namespace admin do resources :events end on admin/events_conttroler.rb class Admin::EventsController < ApplicationController include Tenantable::Schema::Controller before_filter :authenticate_admin! def index @events = Event.scoped @events = Event.between(params[

Rails ajax form not submitting from within another

青春壹個敷衍的年華 提交于 2019-12-11 03:08:31
问题 I have a Rails 3.2 ajax form that creates a new Room for a Hotel. The new Room ajax form works correctly on the Room index page, but once I embed the new Room ajax form on a Hotel edit page, the form is submitted normally without using Ajax. To create the new Room form, I use the following link on the Hotel edit.html.erb page: <%#= link_to 'Add a Room', new_room_path(:hotel_id => @hotel.id), :remote => true, :class => 'new_room' %> This loads the following form partial on to that same page: <

How do I create a single page application in Rails?

非 Y 不嫁゛ 提交于 2019-12-11 02:36:03
问题 I'm creating my first Rails 3.2 application after completing the excellent Rails Tutorial. I would like my application to do this: Pull a random recipe from the database (I have finished this bit using the 'index' action and this bit of code: @recipe = Recipe.find(:first, :order => 'Random()')) If the user clicks the 'something similar' button, the app fetches a related recipe from the db If the user clicks 'something different', the app fetches an unrelated recipe From what I understand,

Why to use _form.html.erb in rails

大憨熊 提交于 2019-12-11 02:15:22
问题 I am new to Ruby on Rails.I was using scaffold to create models views and controllers for admin Now one of my seniors has told me to make changes in _form.html.erb for admin.I have no idea how to implement it.Also what is the advantage or disadvantage of using/making changes in _form.html.erb as compared to normal method(make changes in index,new,show and edit) My _form.html.erb is as follows:- <%= form_for(@admin) do |f| %> <% if @admin.errors.any? %> <div id="error_explanation"> <h2><%=

How to filter results with Ransack

不问归期 提交于 2019-12-11 02:03:40
问题 I am trying to implement Ransack for a search feature on my website. I tried watching the Railscasts on Ransack and got a pretty good idea of how to implement it. But I am running into an issue that I can't seem to figure out. In the Index action of my Users controller, I have the following code: def index @users = User.same_city_as(current_user) end @users is an ActiveRecord::Relation object. @users is essentially capturing all the users who belong to the same city as the current_user . In

URL rewriting fails because of url encoding

戏子无情 提交于 2019-12-11 00:55:06
问题 I recently implemented versioning on my API project. Now URLs of my api will have to be prefixed by the sequence /v1/ (As I'm currently on v1) I don't want to break old calls, so to ensure transparent compatibility, I want to rewrite the old urls. Url like /events/9999/attendees should be redirected to /v1/events/9999/attendees I set this up with my rails routes config file routes.rb with the following code : match "*path", :to => redirect("/#{API_CONFIG['current_version']}/%{path}"),

How to integration test two Rails apps

喜夏-厌秋 提交于 2019-12-11 00:38:01
问题 We have two separate Ruby on Rails apps, one that accepts uploaded files, the other that produces files from the uploads the other app received. We're trying to put together end-to-end blackbox regression and integration tests that demonstrate that when you upload a certain file to the first app, you can count on getting a certain file out of the other app. The question is how to script this, so that the two separate databases are reset with seeded values, the two servers are fired up and