Aaron Dufall
Aaron Dufall

Reputation: 1177

Rails: database not being updated after save is called

I trying to create an association between two objects and save the changes to the database. I have included in the notice a call on the object, to test if it saves after it passes true to the if stament. When I check to see if the update has actually occurred in the data base nothing has changed.

requests_controller.rb

class RequestsController < ApplicationController
   before_filter :load_requestable


   def accept
     @request = Request.find(params[:id])
     @request.profile.send("#{@belongs_to}=",@requestable)

     if @request.save
        redirect_to [@requestable, :requests], notice: "Request Accepted #{@request.profile.send("#{@belongs_to}").name}"
     else
       render :new
     end
   end

private

  def load_requestable
    klass = [Company, Profile].detect { |c| params["#{c.name.underscore}_id"]}
    @requestable = klass.find(params["#{klass.name.underscore}_id"])
    @belongs_to = klass.to_s.downcase
  end

end

Upvotes: 0

Views: 127

Answers (1)

Sergio Tulentsev
Sergio Tulentsev

Reputation: 230286

Try saving profile directly (since you're modifying it, not the request object)

if @request.profile.save
  # redirect

Upvotes: 1

Related Questions