I try to design the check box for the donation_interest but I don't know why I get this error? I will appreciate if you can help me.
module DonorProfilesHelper
def checked(area)
@donor_profiles.donation_interests.nil? ? false: @donor_profiles.donation_interests.match(area)
end
end
class DonorProfilesController < ApplicationController
def donor_profile_params
params.require(:donor_profile).permit(:first_name, :last_name, :description,
:date_created, :address, :phone_number,
:email,:sort_type,
donations_attributes: [:amount, :created_at],donation_interests:[])
end
routes.rb
Rails.application.routes.draw do
resources :donor_profiles
get 'password_resets/new'
get 'password_resets/edit'
get 'sessions/new'
root 'static_pages#home'
get 'donors' => 'donor_profiles#index'
donor_profile.rb
class DonorProfile < ActiveRecord::Base
attr_accessor :donations_attributes
has_many :donations
accepts_nested_attributes_for :donations
scope :donation_interests, -> donation_interests { where donation_interests: donation_interests }
def fullname
"#{first_name} #{last_name}"
end
before_save do
self.donation_interests.gsub!(/[\[\]\"]/,"") if attribute_present?("donation_interests")
end
end
Aucun commentaire:
Enregistrer un commentaire