ruby-on-rails-3

Creating a Blog in an Existing Ruby on Rails app

僤鯓⒐⒋嵵緔 提交于 2020-01-01 02:34:06
问题 I am interested in adding a blog to my Ruby on Rails app. I do not want to waste my time coding up a bloggin app in rails - I can do it but I just prefer something more robust. I have investigated Wordpress and it seems like one of the best bloggin platforms out there. My question is how would I get Wordpress integrated into my site? I would preferably like to use my existing rails layouts and CSS. Is this type of thing even possible. My site is http://www.arenpatel.com/ and as an end result

rake aborted! ERROR: must be owner of database

萝らか妹 提交于 2020-01-01 02:29:08
问题 I am working through Michael Hartl's excellent tutorial but when trying to prepare the test database with the command: bundle exec rake db:test:prepare I get this error message: ERROR: must be owner of database sample_app_test... which I never got when using the development database, because I had created the following database role for my Rails app: CREATE ROLE demo_app WITH CREATEDB LOGIN (this is using Postgresql) Does anyone understand why this is failing in the test environment? TIA...

Displaying simple_form error messages in top <div>

萝らか妹 提交于 2020-01-01 02:25:06
问题 I have the following two _forms: user form <%= simple_form_for(@user, :url => @target) do |f| %> <% if @user.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2> <ul> <% @user.errors.full_messages.each do |msg| %> <li><%= msg %></li> <% end %> </ul> </div> <% end %> <%= f.input :email, :label => "User Email" %> <%= f.input :password, :label => "User Password" %> <%= f.input :first_name %> <%= f.input :last

Race conditions in Rails first_or_create

扶醉桌前 提交于 2020-01-01 02:16:09
问题 I'm trying to enforce uniqueness of values in one of my table fields. Changing the table isn't an option. I need to use ActiveRecord to conditionally insert a row into the table but I'm concerned about synchronization. Does first_or_create in Rails ActiveRecord prevent race conditions? This is the source code for first_or_create from GitHub: def first_or_create(attributes = nil, options = {}, &block) first || create(attributes, options, &block) end Is it possible that a duplicate entry will

What are factory_girl transient attributes? Why would I use one?

我与影子孤独终老i 提交于 2020-01-01 02:00:46
问题 I read this from Thoughtbot but it's still confusing to me. This is their example: factory :user do transient do rockstar true upcased false end name { "John Doe#{" - Rockstar" if rockstar}" } email { "#{name.downcase}@example.com" } after(:create) do |user, evaluator| user.name.upcase! if evaluator.upcased end end create(:user, upcased: true).name #=> "JOHN DOE - ROCKSTAR" So, Is .upcased a real attribute on the model? What is the transient block really doing? Setting variables that can then

How can I make routes from a Rails 3 engine available to the host application?

谁说胖子不能爱 提交于 2020-01-01 01:53:08
问题 I have a Rails 3 application with several engines containing additional functionality. Each engine is a separate service that customers can purchase access to. I am, however, having a problem with routes from the engines that aren't readily available to the controllers and views. controller: class ClassroomsController < ApplicationController .. respond_to :html def index respond_with(@classrooms = @company.classrooms.all) end def new respond_with(@classroom = @company.classrooms.build) end ..

How can I make routes from a Rails 3 engine available to the host application?

浪子不回头ぞ 提交于 2020-01-01 01:53:07
问题 I have a Rails 3 application with several engines containing additional functionality. Each engine is a separate service that customers can purchase access to. I am, however, having a problem with routes from the engines that aren't readily available to the controllers and views. controller: class ClassroomsController < ApplicationController .. respond_to :html def index respond_with(@classrooms = @company.classrooms.all) end def new respond_with(@classroom = @company.classrooms.build) end ..

Problem with Factory_girl, association and after_initialize

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-01 01:14:10
问题 I have a Family class so defined: class Family < ActiveRecord::Base after_initialize :initialize_family belongs_to :user validates :user, :presence => true validates :name, :presence => true, :length => { :maximum => 30 }, :format => { :with => /\A[a-zA-Z0-9\-_\s\']+\z/i} def initialize_family if self.name.blank? && self.user self.name = "#{self.user.profile_full_name}'s Family" end end end In my factories.rb I have: Factory.define :family do |f| f.association :user, :factory => :user end In

Using public_activity with acts_as_follower and devise, how can I show only the user's activities and those of the people he follows?

╄→гoц情女王★ 提交于 2020-01-01 00:46:12
问题 I am trying to get my notifications controller, which is based around the public_activity gem, to show the user's activities in addition to the activities of those he follows. I have it working to show the activities of those the user follows, but I can't seem to get the user's own activities to be included. In other words, this works: class NotificationsController < CooperativeController before_filter :authenticate_user! def index @activities = PublicActivity::Activity.where(:owner_id =>

Sorting by a virtual attribute in Rails 3

我怕爱的太早我们不能终老 提交于 2020-01-01 00:43:11
问题 BACKGROUND: I have a set of Posts that can be voted on. I'd like to sort Posts according to their "vote score" which is determined by the following equation: ( (@post.votes.count) / ( (Time.now - @post.created_at) ** 1 ) ) I am currently defining the vote score as such: def vote_score(x) ( (x.votes.count) / ( (Time.now - x.created_at) ** 1 ) ) end And sorting them as such: @posts = @posts.sort! { |a,b| vote_score((b) <=> vote_score((a) } OBJECTIVE: This method takes a tremendous toll on my