ruby-on-rails-3

Rake error: Stack level too deep

扶醉桌前 提交于 2019-12-24 17:24:56
问题 I know this is a common question, but I just started a project with the new Rails 3.1.0 and Ruby 1.9.2 p290 On my first migrations I had already this error and I am not sure why. Aurelien$ rake db:migrate --trace /Users/Aurelien/.rvm/gems/ruby-1.9.2-p290@rails3/gems/rake-0.9.2/lib/rake/version.rb:4: warning: already initialized constant MAJOR /Users/Aurelien/.rvm/gems/ruby-1.9.2-p290@rails3/gems/rake-0.9.2/lib/rake/version.rb:5: warning: already initialized constant MINOR /Users/Aurelien/.rvm

Rails association with models and migration

 ̄綄美尐妖づ 提交于 2019-12-24 17:12:43
问题 Can't understand how Rails association with models works. Here is simple question: There are two tables products id| name | status 1 | Tube | 0 2 | Pillar | 1 3 | Book | 0 4 | Gum | 1 5 | Tumbler | 2 statuses status | name 0 | Unavailable 1 | In stock 2 | Discounted With ~ same names for models and controllers. I don't what to create new row in statuses table on every new product. And i want to show status name in erb. What should i write in models and in migration file (for example for which

Add SQL 2014 support to activerecord-sqlserver-adapter

烂漫一生 提交于 2019-12-24 17:07:32
问题 We've be using the activerecord-sqlserver-adapter gem with sqlserver 2008 and everything works great. We just tried to deploy our Rails 3 app against a new sqlserver 2014 db and I get an error that says: Currently, only 2005, 2008, 2010, 2011, and 2012 are supported. We got back Microsoft SQL Server 2014 - 12.0.2000.8 (X64) A quick look at github shows that a small update was recently made to the sqlserver_adapter.rd to resolve this issue. I tried to update the gem and it turned into a bit of

Rails 3 - Find condition to filter broken Reference integrity associations

a 夏天 提交于 2019-12-24 16:41:30
问题 I have two models: TimeLog and Task . TimeLog belongs to Task and Task has many TimeLog s. In the past some Task s were deleted but the corresponding TimeLog s were not deleted (the cascade delete wasn't working). So we have some broken TimeLog s. They do have a task_id but that task_id does not exist anymore. I have two questions: 1) I want to get all the TimeLog s from a user but filtering the broken ones. i.e TimeLog.find(:all, :conditions => ['time_log.user_id = ? and <time_log.task_id

Pass local rails variable to javascript to partial

本秂侑毒 提交于 2019-12-24 16:39:00
问题 I'm giving up my search, I normally try to figure these things out on my own but I'm struggling hard and I just want this to work I have the link_to seen below where @puser is the user of the profile I'm currently viewing. <%= link_to 'Request', new_or_edit_relationship_path(nil), :remote => true, :locals => { :puser => @puser} %> This in turn calls new_relationship_path which is a .js.erb file seen below alert("<%= escape_javascript(puser.id) %>") Why won't this work!? It's saying the puser

uninitialized constant ApplicationController (NameError) - application works fine locally

流过昼夜 提交于 2019-12-24 16:32:58
问题 I've set up a simple application online on a rackspace cloud server but I'm getting the following error message from phusion passenger: uninitialized constant ApplicationController (NameError) /var/www/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-3.2.12/lib/active_support/inflector/methods.rb:230:in `block in constantize' /var/www/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-3.2.12/lib/active_support/inflector/methods.rb:229:in `each' /var/www/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-3.2

Rails HABTM fields_for – check if record with same name already exists

大兔子大兔子 提交于 2019-12-24 16:29:52
问题 I have a HABTM-relation between the models "Snippets" and "Tags". Currently, when i save a snippet with a few tags, every tag is saved as a new record. Now i want to check if a tag with the same name already exists and if that´s the case, i don´t want a new record, only an entry in snippets_tags to the existing record. How can i do this? snippet.rb: class Snippet < ActiveRecord::Base accepts_nested_attributes_for :tags, :allow_destroy => true, :reject_if => lambda { |a| a.values.all?(&:blank?

Rails Model: How to make a attribute protected or private that is not visible outside model?

谁说胖子不能爱 提交于 2019-12-24 16:27:14
问题 There are some fields present in table which i don't want to be visible outside? Like created_on, is_first etc. I want to set value of these fields by using callbacks with in model but not accessible for some one to set it. 回答1: The standard way to prevent mass-assignment on certain fields is attr_protected and attr_accessible : http://api.rubyonrails.org/classes/ActiveModel/MassAssignmentSecurity/ClassMethods.html In your case, you would have to add this line in your model: attr_protected

How does Rails import existing rows when you “Edit” in scaffolding?

时光毁灭记忆、已成空白 提交于 2019-12-24 16:15:29
问题 That was probably a very badly worded question, but I'm curious how Rails knows to bring in the form data when you click edit. For example, if I scaffolded a model called Post, and typed in a title and content for that Post, later when I edit it, the form is automatically filled in. I looked at the controller and the form partial, but it doesn't seem like it contains anything to tell it to fill it up with the existing data. The reason I am asking this is because I want to allow users to

Issue with “:prompt” in select_year with start/end_year

假装没事ソ 提交于 2019-12-24 16:11:17
问题 Using this answer as a guide, I set out to create a select_year that started with today's year and ends 100 years ago. But I wanted to add a :prompt so that the drop down starts with "Year" instead of the current year. So I used the following: <%= select_year(Date.today, {:prompt => "Year", :start_year => DateTime.now.year, :end_year => DateTime.now.year - 115}, {:field_name => 'Year', :id => 'Date.year'}) %> This renders a drop down for year, but the prompt shows current year instead of