ruby-on-rails-3

Rails 3 ActiveRecord where clause where id is set or null

风流意气都作罢 提交于 2020-01-04 10:42:01
问题 I have an ActiveRecord, Annotation, with two columns: user_id and post_id, which can be null. An annotation with null user_id and post_id are "global" annotations that are applicable to all posts across all users. I would like to retrieve all annotations associated with a particular user's post AND all global annotations. In MySQL, the SQL command would be select * from annotations where (user_id = 123 and post_id = 456) or (user_id is null and post_id is null) In Rails 3, what is best way to

Rails Engage! Error (Can't mass-assign protected attributes: user)

瘦欲@ 提交于 2020-01-04 09:39:06
问题 I'm working on installing Engage! I followed the installation instructions found here: http://engagecsm.com/readme Installation steps I did: Add Engage! to the application's Gemfile: gem 'engagecsm'. Install it: bundle install. Run the generator: rails generate engage User. Run the migrations: rake db:migrate. Now, I can go to localhost:3000/engage This is what shows up: Now, when I hit "Create Topic", nothing happens on the site. I look at my rails server console and I see this: (Easier to

Rails redirect_to another controller method throwing “Template missing”

痴心易碎 提交于 2020-01-04 09:25:27
问题 I gotta be missing something. I have a controller action for short urls: def shorturl redirect_to :action => show, :id => Base58.decode(params[:id]) and return end My intention is have this either redirect or load the regular show method of the same controller. At this point, I don't care which way, just want to get it working first. The problem is it throws a missing template error like its not exiting the shorturl method. Missing template controller/shorturl with {:locale=>[:en, :en],

How to call app Model in initializers with Ruby on Rails

狂风中的少年 提交于 2020-01-04 09:14:00
问题 I am new in Ruby on Rails and i am using Ruby version 2.1.0 and Rails 4.0.2 My Query is:- I want to call Model in initializers . my Model file is setting.rb and Model name Setting . its location is app/model directory. I want to call Setting Model in initializers file paypal.rb . paypal.rb location is config/initializers/paypal.rb . Please help how to call Model in initializers in Ruby on Rails . 回答1: Do you want to make sure all other initializers have run before running this one? If so you

How to call app Model in initializers with Ruby on Rails

依然范特西╮ 提交于 2020-01-04 09:13:03
问题 I am new in Ruby on Rails and i am using Ruby version 2.1.0 and Rails 4.0.2 My Query is:- I want to call Model in initializers . my Model file is setting.rb and Model name Setting . its location is app/model directory. I want to call Setting Model in initializers file paypal.rb . paypal.rb location is config/initializers/paypal.rb . Please help how to call Model in initializers in Ruby on Rails . 回答1: Do you want to make sure all other initializers have run before running this one? If so you

Conditional in Rails partial depending on the context page?

送分小仙女□ 提交于 2020-01-04 08:23:27
问题 I was wondering if I could execute / display some stuff differently in partials depending on the context in which it appears. For example, I have a _user_info partial that appears in a sidebar, and also in the user page, and I want to display some extra info in the second case. How can I express that kind of conditions? 回答1: What you're asking for is something this: if params[:controller].eql?('users') view code However I would split the partial into two separate partials and display the

SQLException on db:test:load with Rails

有些话、适合烂在心里 提交于 2020-01-04 06:55:09
问题 I've been working on a small but somewhat complex Rails application with multiple has_and_belongs_to_many relationships. It's open source, and the code is here. Everything was working fine, but recently I added a new HABTM relationship migration, and an rspec test started to fail. Rake:db:migrate was working (and the issue was working locally), just not in testing. Upon running db:test:load --trace , I get the following error: :fermi og$ rake db:test:load --trace /Users/og/.rvm/rubies/ruby-1

Rails character encoding issue while using cache

纵饮孤独 提交于 2020-01-04 06:15:50
问题 I am using rails fragemnet cache to cache some html. Below is my code <% if @link.social_tags.present? %> <% cache(:action =>'pageui', :action_suffix => "#{@link.id}_tags") do %> <% @link.social_tags.each_with_index do |tag, index| %> <%= ", " if index > 0 %> <%= link_to tag.name, some_path(:tag => tag.id), :title => tag.name, :target => "_blank" %> <% end %> <% end %> <% else %> Still no tag for this Page. <% end %> I am getting some weird issue. First time when it doesn't have the fragement

Checking if the Faye server exists before running it for my Rails app

≡放荡痞女 提交于 2020-01-04 06:15:31
问题 In relation to a previous question of mine found here: Autorun the Faye server when I start the Rails server I am now running the Faye server whenever I start Rails. However, this means it is trying to run the Faye server when I run the Rails server, the Rails console, or anything else Rails related. Is there a way to check if the Faye server is already running? And if it is, not attempt to run a new one? Or maybe this isn't the best approach, I welcome all ideas and tips. 回答1: You can use

Checking if the Faye server exists before running it for my Rails app

一个人想着一个人 提交于 2020-01-04 06:14:35
问题 In relation to a previous question of mine found here: Autorun the Faye server when I start the Rails server I am now running the Faye server whenever I start Rails. However, this means it is trying to run the Faye server when I run the Rails server, the Rails console, or anything else Rails related. Is there a way to check if the Faye server is already running? And if it is, not attempt to run a new one? Or maybe this isn't the best approach, I welcome all ideas and tips. 回答1: You can use