update-attributes

ArgumentError: wrong number of arguments (given 1, expected 2) for Update_Attribute Method

南楼画角 提交于 2020-01-06 06:43:26
问题 I am creating a recurring event app where certain users (streamers) can schedule recurring weekly events (streams) and other users (viewers) can follow them. The result is a personalized weekly calendar detailing when all followed streamers' events begin and end. However, because viewers can follow an infinite number of streamers and therefore the resulting calendar would look like a hot mess. So I added a boolean attribute to the relationships table that indicates whether the relationship

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

戏子无情 提交于 2020-01-02 05:32:26
问题 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

Rails - How to manage nested attributes without using accepts_nested_attributes_for?

放肆的年华 提交于 2020-01-01 03:15:15
问题 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

How to update/rename a carrierwave uploaded file?

余生长醉 提交于 2020-01-01 00:21:05
问题 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

Rails Nested Forms Not Updating

浪尽此生 提交于 2019-12-24 08:17:16
问题 I'm having a problem getting update_attributes to update nested models in my form. I don't have any errors but the nested attributes aren't saving. Here's the relevant code: Users model: class User < ActiveRecord::Base has_many :orders has_many :achievements accepts_nested_attributes_for :achievements Achievements model: class Achievement < ActiveRecord::Base belongs_to :user Edit User form: <%= form_for @user, :html => { :multipart => true } do |f| %> ... <%= f.fields_for :achievements do |

Update_all or update_attribute doesn't update the column

扶醉桌前 提交于 2019-12-23 03:12: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

Rails: update_attribute vs update_attributes

和自甴很熟 提交于 2019-12-17 02:52:34
问题 Object.update_attribute(:only_one_field, "Some Value") Object.update_attributes(:field1 => "value", :field2 => "value2", :field3 => "value3") Both of these will update an object without having to explicitly tell AR to update. Rails API says: for update_attribute Updates a single attribute and saves the record without going through the normal validation procedure. This is especially useful for boolean flags on existing records. The regular update_attribute method in Base is replaced with this

update_attributes isn't saving to the database

余生颓废 提交于 2019-12-14 01:34:58
问题 The correct custom params are being displayed in my debug function after the form is submitted but the default params are displayed when I enter console. Controller def update current_user.update_attributes(params[:user]) flash[:success] = "Your settings have been saved!" render new_status_update_path end Model attr_accessible :deficit_pct, :target_bf_pct, :activity_factor Notes: The closest question I could find to this on SO is a question that changes the attributes of an object that exists

undefined method update_attributes in Rails 4

谁说胖子不能爱 提交于 2019-12-13 13:02:20
问题 i'm now using Rails 4 now i want to update my user record i'm trying to use this command @user=User.update_attributes(:name=> params[:name], :user=> params[:username], :pass=> params[:password]) OR @user=User.update_attributes(name: params[:name], user: params[:username], pass: params[:password]) but always got the error undefined method `update_attributes' so how i can update my user also i want to ask is it will update all the users in my DB ?? i think i must add some condition such as

Trying to set a variable in before_validation but it isn't working

谁说胖子不能爱 提交于 2019-12-13 07:41:28
问题 So in my view I'm using a calendar to select a day and drop downs to select time. Therefore I'm using a before_validation method to put it together: proposed_time.rb before_validation :construct_starting_at def construct_starting_at d = Time.parse(date) puts "************** construct_starting_at BEGIN *****************" puts "DATE: #{d}" puts "Time: #{time}" puts "Timezone: #{timezone}" puts "construct_starting_at :: #{d.year}-#{d.month}-#{d.day} #{time.hour}:#{time.min}:00 #{timezone}" if