Reputation: 7862
I have problem with public_activity gem under Rails 4. I've installed this gem correctly next i type rails g public_activity:migration and rake db:migrate. In the next step i add
include PublicActivity::Model
tracked
to my post model and generate controller activities with index action. My Activities controller:
class ActivitiesController < ApplicationController
def index
@activities = PublicActivity::Activity.order("created_at desc")
end
end
View for it:
<h1>Friend's Activities</h1>
<% @activities.each do |activity| %>
<%= activity.inspect %>
<% end %>
And the route is:
resources :activities
And when i gone to http://localhost:3000/activities
i have error:
`attr_accessible` is extracted out of Rails into a gem. Please use new recommended protection model for params(strong_parameters) or add `protected_attributes` to your Gemfile to use old one.
Can anybody help me?
Upvotes: 1
Views: 1555
Reputation: 549
The problem is that public_activity gem only check for rails version when its setting attr_accessible. If you are using earlier version then Rails 4, it will include it. I've submitted issue to github/public_activity/128. I believe in future release they will resolve it.
For now my workaround is to create config/initializers/public_activity.rb
PublicActivity::Activity.class_eval do
attr_accessible :key, :owner, :parameters, :recipient, :trackable
end
Upvotes: 0
Reputation: 555
The latest version of the public_activity gem has a check for the active record version to support rails 4, but it seems that is not yet on rubygems. I was able to get past this error by using the github version
In my gemfile:
gem 'public_activity', github: 'pokonski/public_activity'
I then restarted the server and the error was gone.
Upvotes: 3
Reputation: 6786
I guess your problem is your model has attr_accessible which is extracted as a gem after rails 4. If you love to see attr_accessible in models then add
gem 'protected_attributes'
to your Gemfile.
https://github.com/rails/protected_attributes more more documentation
If you want to follow rails4 way then here is the article to read: http://rubyjunction.us/no-more-attr-accessible-in-ruby-on-rails-4
Upvotes: 4