Rails 4 WYSIWYG Bootsy image upload option not showing - ruby-on-rails

Hi i am using Bootsy and it is work fine, unfortunatly image upload option is not working I have already installed CarrierWave which is also working fine.
My form
<%= f.bootsy_area(:description) %>
My Model
class Page < ActiveRecord::Base
belongs_to :user
include Bootsy::Container
require 'carrierwave/orm/activerecord'
mount_uploader :attachment, AttachmentUploader
extend FriendlyId
friendly_id :title, use: :slugged
validates :title, :presence => true
validates :slug, :presence => true
validates :user_id, :presence => true
def should_generate_new_friendly_id?
new_record? || !self.slug.present? && self.title.present?
end
end
My controller
def pages_params
params.require(:page).permit(:title, :description, :status, :slug, :user_id, :password, :attachment, :bootsy_image_gallery_id)
end
def create
#page = Page.new(pages_params)
if #page.save
redirect_to(:action => "index")
else
render("new")
end
end
any any advice and suggestions will be greatly appreciated. thanks

Not sure if you have found the answer yet, here is what I found with the similar problem and its solution.
After upload images, how to insert the image?

Related

strong parameters Can't mass-assign protected attributes

I am using Rails 3.2.14, inherited_resource and strong_parameter gem.I just followed Strong Parameters in Rails 3.2.8 steps but i am getting error like below,
Can't mass-assign protected attributes:content, title, nature_bien_id, nature_transaction_id, nbr_chambres, nbr_pieces, section_id, city, zip, surface_habitable, surface_terrain
My code in controller is like that
def create
#mandat = current_user.mandats.new(mandats_params)
end
private
def annonce_params
params.require(:annonce).permit(:created_at, :description, :image, :dpe, :nature_bien_id, :nature_transaction_id,:nbr_chambres, :nbr_pieces, :prix_net_acquereur, :section_id, :surface_habitable,:surface_terrain, :titre, :annonce_images_attributes, :user_id, :ville, :zip, :reference,:available_time, :is_valid, :close, :reasonclosing, :annonce_support_ids, :equipement_ids)
end
Thanks for in advance
You have to turn off attributes protection in your config/application.rb:
config.active_record.whitelist_attributes = false
Please check that all attributes that you want to updated are listed in the attr_accessible definition in your Mandat model:
attr_accessible :created_at, :description, :image, :dpe, :nature_bien_id,
:nature_transaction_id,:nbr_chambres, :nbr_pieces, :prix_net_acquereur,
:section_id, :surface_habitable,:surface_terrain, :titre,
:annonce_images_attributes, :user_id, :ville, :zip, :reference,
:available_time, :is_valid, :close, :reasonclosing, :annonce_support_ids,
:equipement_ids
In my rails project,I use audited Gem.Refer Audited gem using strong Parameter.So in my model
Change
class Mandat < ActiveRecord::Base
audited on: [:update]
to
class Mandat < ActiveRecord::Base
audited :allow_mass_assignment => true,on: [:update]
then it will works perfectly.

Rails Update method doesn't work

I want to update a prediction_config, but something is going wrong. Here are the relevant methods in my controller:
def edit
#prediction_config = PredictionConfigs.find(params[:id])
end
def update
#prediction_config = PredictionConfigs.find(params[:id])
if #prediction_config.update_attributes(params[:prediction_config])
redirect_to #prediction_config
else
render 'edit'
end
end
Here is my Model:
class PredictionConfigs < ActiveRecord::Base
attr_accessible :name, :value
validates :name, presence: true
validates :value, :inclusion => {:in => [0,100]},
presence: true
end
What could be the problem? Any help is appreciated!
EDIT: It is simply not updating the value, but everything loads properly.

Upgrading attr_accessible from Rails 3 to Rails 4

I'm trying to systematically upgrade from rails 3 to rails 4 and all of my 25 models are based on attr_accessor! So before getting into that can anyone provide me a simple example on how to do this. I've read the documentation and other topics but it's not clear on how to do it since this is my first upgrade Rodeo.
class Settings < ActiveRecord::Base
image_accessor :favicon
attr_accessible :company_name, :show_hot_jobs, :show_students, :subheading, :show_testimonials, :show_on_boarding, :max_concurrent_applications
attr_accessible :image_uid, :max_concurrent_application_groups
attr_accessible :primary_color, :white_color, :gray_color, :opacity, :locale, :lang_nl, :lang_fr, :lang_de, :lang_en, :privacy_page
attr_accessible :show_evp, :show_contact_person, :show_jobs_for_you
attr_accessible :favicon, :favicon_uid, :remove_favicon, :retained_favicon
attr_accessible :home_url, :show_correspondence, :show_appointment
attr_accessible :sliderone_uid, :slidertwo_uid, :sliderthree_uid, :sliderfour_uid, :sliderfive_uid
attr_accessible :sliderone_link, :slidertwo_link, :sliderthree_link, :sliderfour_link, :sliderfive_link
attr_accessible :sliderone_testoverview, :slidertwo_testoverview, :sliderthree_testoverview, :sliderfour_testoverview, :sliderfive_testoverview
attr_accessible :sliderone_page, :slidertwo_page, :sliderthree_page, :sliderfour_page, :sliderfive_page
validate :any_lang_present?
validates :max_concurrent_applications, :numericality => { :greater_than_equal_to => 1 }
validates :max_concurrent_application_groups, :numericality => { :greater_than_equal_to => 1 }
# Fav Icon Validation
validates_property :ext, of: :favicon, :in => ['ico', 'png', 'gif']
has_paper_trail
has_many :setting_translations, :foreign_key => :setting_id
accepts_nested_attributes_for :setting_translations, :allow_destroy => true, :reject_if => :all_blank
attr_accessible :setting_translations_attributes, :allow_destroy => true
translates :subheading, :company_name, :image_uid, :home_url, :sliderone_uid, :slidertwo_uid, :sliderthree_uid, :sliderfour_uid, :sliderfive_uid
translates :sliderone_link, :slidertwo_link, :sliderthree_link, :sliderfour_link, :sliderfive_link
translates :sliderone_testoverview, :slidertwo_testoverview, :sliderthree_testoverview, :sliderfour_testoverview, :sliderfive_testoverview
translates :sliderone_page, :slidertwo_page, :sliderthree_page, :sliderfour_page, :sliderfive_page
attr_accessible can be converted like so:
From
class Settings
attr_accessible :home_url
accepts_nested_attributes_for :setting_translations
end
class SettingTranslation
attr_accessible :etc
end
To
class SettingsController
def create
#settings = Settings.new(settings_params)
# ...
end
private
def settings_params
params.require(:settings).permit(
:home_url,
:setting_translations_attributes => [:id, :_destroy, :etc]
)
end
end
Note, you have to include :_destroy if you want to allow destroy on that model (:allow_destroy => true), and you have to include all attributes that should be accessible from any nested attributes. Though you remove attr_accessible when you've permitted, you do not remove accepts_nested_attributes_for.
Just remove attr_accessible from model. and add permit params according to need in controller.
like below :
class SupportTicketsController < ApplicationController
def create
#support_ticket = SupportTicket.create(house_params)
......
end
private
def house_params
params.require(:support_ticket).permit(:subject, :message, ....)
end
end
and if you don't want to make this much changes then add "protected_attributes" gem https://github.com/rails/protected_attributes in your gemfile And everything would work as before.

Strong parameters in Ruby

I'm getting the error message about strong parameters. I think it's just that rails 4 doesn't use attributes anymore. the code for my toy.rb is:
class Toy < ActiveRecord::Base
attr_accessible :name, :price, :vendor
validates :name, :presence => true
validates :price, :presence => true
validates :price, :numericality => true
validates :vendor, :presence => true
end
how can I change this to strong parameters?
EDIT: I used a different rb i changed it to employees and this is what I have:
class Employee < ActiveRecord::Base
params.require(:employee).permit(:first, :last, :salary, :salary, :ssn)
validates :first, :presence => true
validates :last, :presence => true
validates :salary, :presence => true
validates :salary, :numericality => true
validates :ssn, :presence => true
end
It's still telling me "ndefined local variable or method `params' for #"
The code you need is
params.require(:toy).permit(:name, :price, :vendor)
You will put this in your controller. Typically, you create a private method:
def create
Toy.create(toy_params)
end
private
def toy_params
params.require(:toy).permit(:name, :price, :vendor)
end
See http://guides.rubyonrails.org/getting_started.html#saving-data-in-the-controller for more information.
Edit
I think I might have misled you with my original answer. The code goes in the controller, not the model.
Strong params are designed to help your controller send specific data to your model. It's meant to protect your app against unauthorized data being passed:
#app/controllers/toys_controller.rb
Class ToysController < ActiveRecord::Base
def new
#toy = Toy.new #-> creates a blank AR object
end
def create
#toy = Toy.new(toys_params) #->creates new AR object (populating with strong params)
#toy.save
end
private
def toys_params
params.require(:toys).permit(:your, :params, :here)
end
end

How to add data in refinerycms engine

Has anyone else run into a mass assignment error when trying to create a new piano?
ActiveModel::MassAssignmentSecurity::Error in Refinery::Pianos::Admin::PianosController#create
Can't mass-assign protected attributes: name, dimensions, manufactured_on(1i), manufactured_on(2i), manufactured_on(3i), upright, photo_id, description, position
If you open up your model file and put this in there you will have more success:
attr_accessible :dimensions, :manufactured_on, :upright, :photo_id, :description, :position
The model file should look like this:
module Refinery
module Pianos
class Piano < Refinery::Core::BaseModel
self.table_name = 'refinery_pianos'
attr_accessible :dimensions, :manufactured_on, :upright, :photo_id, :description, :position
acts_as_indexed :fields => [:dimensions, :description]
validates :dimensions, :presence => true, :uniqueness => true
belongs_to :photo, :class_name => '::Refinery::Image'
end
end
end
Hope that helps. I guess it's a bug in the version you're using but it's fixed in the Refinery CMS 2-0-stable branch.

Resources