update-attributes

Undefined method update_attributes?

醉酒当歌 提交于 2019-12-13 06:07:05
问题 Im trying to allow the user to update the attributes for a single column for multiple elements based on a drop down (with name="status ) but i keep getting back the error: undefined method 'update_attributes' . Any suggestions? def supdate @input_messages = InputMessage.find(params[:message_ids]) respond_to do |format| if @input_messages.update_attributes(:status => params[:status]) format/html { redirect_to :action => "show" } end end end 回答1: Assuming that your params[:message_ids] value is

How to make text fields for nested_attributes in rails for selected records?

我与影子孤独终老i 提交于 2019-12-12 00:34:44
问题 I have a three models Report , Question , Answer Answer belong_to :question Question belong_to :reports has_many :answers, :dependent => :destroy accepts_nested_attributes_for :answers, :allow_destroy => true Reports has_many :questions, :dependent => :destroy accepts_nested_attributes_for :questions, :allow_destroy => true While creating a new report some questions are randomly picked to be added to the report and show form in this way : Report Form <%= form_for @report do |f| %> <div class=

Rails Nested Forms Not Updating Nested Model

删除回忆录丶 提交于 2019-12-07 22:58:05
问题 I am having trouble trying to update nested models in my form. I don't get any errors and but the attributes don't get updated. I have the following model: class Trip < ActiveRecord::Base has_many :segments accepts_nested_attributes_for :segments, allow_destroy: true end class Segment < ActiveRecord::Base belongs_to :start_location, class_name: 'Location' belongs_to :end_location, class_name: 'Location' belongs_to :trip validates_presence_of :date, :start_location, :end_location end class

Update_all or update_attribute doesn't update the column

五迷三道 提交于 2019-12-06 15:28:13
I have a status report a user can send by email and I want to update a column :sent_mail to true, after the deliver action is completed. def send_status date = Date.today reports = current_user.reports.for_date(date) ReportMailer.status_email(current_user, reports, date).deliver reports.update_all(sent_mail: true) end and the table class AddSentMailToReports < ActiveRecord::Migration def change add_column :reports, :sent_mail, :boolean, default: false end end However, in console, sent_mail is still set to false.Any ideas why this doesn't work? Thanks! This is because update_all sends an update

Rails Nested Forms Not Updating Nested Model

这一生的挚爱 提交于 2019-12-06 07:07:17
I am having trouble trying to update nested models in my form. I don't get any errors and but the attributes don't get updated. I have the following model: class Trip < ActiveRecord::Base has_many :segments accepts_nested_attributes_for :segments, allow_destroy: true end class Segment < ActiveRecord::Base belongs_to :start_location, class_name: 'Location' belongs_to :end_location, class_name: 'Location' belongs_to :trip validates_presence_of :date, :start_location, :end_location end class Location < ActiveRecord::Base has_many :segments end And have this code in the _form.html.erb: <%= form

Rails update_attribute

╄→гoц情女王★ 提交于 2019-12-06 03:27:47
问题 Ive got the following problem. I have a model called user which has a column named activated. Im trying to update that value whith the method activated?, but it gives me the error: Validation failed: Password can't be blank, Password is too short (minimum is 6 characters) Which doesnt make sense to me, because im not touching the password field! I just want to update the activated column. Im putting here the code I think its relevant, but if you think you need more just ask :) Thank you very

Ruby on Rails Tutorial: How to edit user information without confirming the password

删除回忆录丶 提交于 2019-12-05 15:26:17
I've been working through the Ruby on Rails Tutorial by Michael Hartl. Currently, in order to edit any of the User attributes, the user must confirm their password. Is there any way to update the user attributes without having to do this? My form looks like this: <%= form_for @user do |f| %> <div class="field"> <%= f.label :course1 %><br /> <%= f.text_field :course1 %> </div> <div class="actions"> <%= f.submit "Update" %> </div> <% end %>" and my update definition in users_controller.rb looks like this: def update if @user.update_attributes(params[:user]) flash[:success] = "Edit Successful."

Rails - How to manage nested attributes without using accepts_nested_attributes_for?

浪尽此生 提交于 2019-12-03 08:33:30
My problem is I've run into limitations of accepts_nested_attributes_for, so I need to figure out how to replicate that functionality on my own in order to have more flexibility. (See below for exactly what's hanging me up.) So my question is: What should my form, controller and models look like if I want to mimmic and augment accepts_nested_attributes_for? The real trick is I need to be able to update both existing AND new models with existing associations/attributes. I'm building an app that uses nested forms. I initially used this RailsCast as a blueprint (leveraging accepts_nested

Rails 3 - how to save (un)checked checkboxes?

左心房为你撑大大i 提交于 2019-12-03 07:30:03
问题 I have in a form ( form_tag ) several checkboxes like this: <%=check_box_tag 'model_name[column_name]', 1, (@data.model_name.column_name == 1 ? true : false)%> And updating them like: variable = ModelName.find(params[:id]) variable.update_attributes(params[:model_name]) This works only in a moment, when I check some checkboxes - send them and they will be saved. That's fine. But when I uncheck all checkboxes - send form - so nothing happend, in the DB table will not set the value 0 in the

How to update/rename a carrierwave uploaded file?

喜欢而已 提交于 2019-12-03 03:48:39
I cant figure out how to update/rename a file uploaded/managed with Carrierwave-mongoid in rails 3.2.6. I want to rename the file in the db as well as on the filesystem. Something like this maybe... def rename( id , new_name ) f = UploadedFile.find(id) if f.update_attributes({ f.file.original_filename: new_name }) # this is WRONG, what is right??? new_path = File.join( File.dirname( f.file.current_path ) , new_name )) FileUtils.mv( f.file.current_path , new_path ) end return f end Let me add this is after it has been uploaded already. I was able to get the following working, although I'm sure