ruby-on-rails-3.1

Rails 3.2.3: How to mass assign associated models?

可紊 提交于 2019-12-10 11:58:10
问题 I have a rails 3.2.3, I have a form with two nested models, when I try to submit the form, I get this error: ActiveModel::MassAssignmentSecurity::Error in ExperimentsController#create Can't mass-assign protected attributes: descriptions_attributes, circuits_attributes Here is my models: class Experiment < ActiveRecord::Base attr_accessible :title, :intro_text has_many :circuits, :dependent => :destroy has_many :descriptions, :dependent => :destroy accepts_nested_attributes_for :descriptions,

jQuery Datepicker doesn't work on Heroku/Rails 3.1

旧城冷巷雨未停 提交于 2019-12-10 11:31:50
问题 Hello everybody out there, I'm very frustrated with the jQuery Datepicker and Rails 3.1. It runs perfectly in my develoment environment, but it doesn't work in the production environment on Heroku/Cedar. It simply doesn't pop-up when I select my date field. So here's what I did so far: I put the jquery files into \apps\assets\javascript : jquery-1.7.1.min.js jquery-ui-1.8.17.custom.min.js jquery.ui.datepicker-de.js and I added them among other files to my production.rb : # Precompile

Rails 3.1 and Twitter Bootstrap modal don't play nice?

元气小坏坏 提交于 2019-12-10 11:09:24
问题 I'm tearing my hair out over this one: I'm trying to use the Twitter Bootstrap modal (v.1, not 2) to post comments via AJAX, using the standard TB modal attributes for the div: <div class="modal hide fade" id="commentModal"> <div class="modal-header"> <a href="#" class="close">×</a> <h3>Say Something</h3> </div> <div class="modal-body"> <%= render 'common/error_messages', :target => @comment %> <%= form_for [@commentable, Comment.new], :remote => true do |f| %> <%= f.hidden_field :user_id,

Ruby on Rails 3: How can I sort ActiveRecords by an attribute of another table?

ⅰ亾dé卋堺 提交于 2019-12-10 10:46:32
问题 I need to query a database table and get the rows ordered by a count of an association. Is there a Rails (like Active Record Query) way to do this? My models and their associations are as follows: class User < ActiveRecord::Base has_one :business end class Business < ActiveRecord::Base has_many :postulations end class Postulation < ActiveRecord::Base belongs_to :business end I need to get a number of Users ordered by the amount of Postulations that their Business has. Is there a clean way to

Gmaps4Rails : How to open the Infowindow of the single marker by default when the Google maps is loaded (without clicking on the marker)

最后都变了- 提交于 2019-12-10 10:08:03
问题 I am using Gmaps4Rails in my rails application for loading google maps. Everything works fine. I have a single marker and I want to keep the infowindow open by default when the google map is loaded (without clicking on the marker). Please help me how to achieve this using Gmaps4Rails gem? I have tried the following snippet of code but it doesn't work. <% content_for :scripts do %> <script type="text/javascript" charset="utf-8"> Gmaps.map.callback = function() { if (Gmaps.map.markers.length ==

“Can't mass-assign protected attributes” with nested attributes

爷,独闯天下 提交于 2019-12-10 09:25:16
问题 I've seen other questions with this problem, but so far the answers haven't worked for me. I'm trying to have a form that registers a User, and creates an Organization at the same time. The User and Organization are associated via an assignment table. Here is my form: = form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| = devise_error_messages! = f.fields_for :organizations do |f| = f.label :name = f.text_field :name = f.label :email = f.email_field

Why does rake assets:precompile in development cause problems but not in my production environement

亡梦爱人 提交于 2019-12-10 09:25:15
问题 I have upgraded my app on heroku to a cedar stack so that the asset pipeline works. I have followed the instructions given in heroku's docs by choosing to compile assets locally. This has created a directory public/assets. Everything in production works perfectly(css, js, with no problems). Going back to my development environment seems to cause the js to not function properly. In environments/production.rb config.serve_static_assets = false config.assets.compress = true config.assets.compile

Helper “fields_for” not working

懵懂的女人 提交于 2019-12-10 04:35:42
问题 I'm using nested attributes, but the fields aren't loaded in my view. Someone know what I missing? Rails 3.1, Ruby 1.9.2 Model 1: class Traditions::Material < ActiveRecord::Base has_one :material_asset, :dependent => :destroy validates_presence_of :title accepts_nested_attributes_for :material_asset end Model 2: class Traditions::MaterialAsset < ActiveRecord::Base belongs_to :material has_attached_file :asset validates_attachment_presence :asset end View (HAML): = form_for @material, :html =>

Select tag with multiple values pre-selected - Values inserted manually in database

∥☆過路亽.° 提交于 2019-12-10 04:24:40
问题 I have a problem, I don't planned my database correctly, so always I need to use 'alternatives'. I want pre-selected multiple values in select_tag. But I'm adding the vacancies 'manually' in table vacancy. My controller: def create @hr_curriculum_generic = HrCurriculumGeneric.new(params[:hr_curriculum_generic]) # Tabela CandidatosxVagas unless params[:vacancy_ids].nil? @vacancies_ids = params[:vacancy_ids] -- my form: @vacancies_ids.each do |vacancy_id| # Armazena os id do curriculum, vaga e

ActiveRecord::UnknownAttributeError?

喜夏-厌秋 提交于 2019-12-10 01:34:32
问题 I just pushed an app to a production Heroku environment. Basically there is a Bus model and it has a seats attribute class Bus < ActiveRecord::Base attr_accessible :seats, # other attributes end Now I have a JavaScript frontend which POST's JSON for new buses to the buses#create action. ActiveRecord keeps encountering an error when I try to create a bus: : POST www.busables.com/buses dyno=web.1 queue=0 wait=5ms service=65ms status=500 bytes=728 : : ActiveRecord::UnknownAttributeError (unknown