undefined method `featured' for Post - ruby-on-rails-5

I try to add a full-text search in my app. With gem 'sunspot_rails', '~> 2.3' and gem 'sunspot_solr', '~> 2.3' for my app. When i try save something in mysql db like:
#post = Post.new
#post.title = "Theorema"
#post.save
It gives me ROLLBACK and:
NoMethodError (undefined method `featured' for #<Post:0x00007f018ab005d0>):
I am beginer and will be grateful for any help!

Welcome to SO Oleg.
Have you got an attribute featured in your Post model?
There is one on the github page of the gem you used.
Maybe you copied it by mistake. Either remove that if you do not need it or add it to posts and migrate.
Can not really tell without seeing your Post model.

Related

How to write RefineryCMS controller tests without RoutingError

An Rspec test like this (actually taken from RefineryCMS' own test suite)
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
module Refinery
describe FastController do
it "should render the wymiframe template" do
get :wymiframe
response.should be_success
end
end
end
Results in the following error:
Failure/Error: get :wymiframe
ActionController::RoutingError:
No route matches {:controller=>"refinery/fast", :action=>"wymiframe"}
# ./spec/controllers/fast_controller_spec.rb:6:in `block (2 levels) in <module:Refinery>'
In this case, I'm using refinery 2.0.8 with Rspec 2.11, and the relevant section after running rake routes looks like:
wymiframe GET /wymiframe(/:id)(.:format) refinery/fast#wymiframe
I have tried a few other controller Rspecs which also fail with routing errors. I am of course trying to write tests for my own extra methods I am adding to vanilla Refinery controllers, but just thought I'd see if I could get a controller test working for a totally fresh refinery install.
This must be a simple mistake! Any suggestions?
I stumbled upon this by accident. Instead of:
get :wymiframe
I needed to use:
get :wymiframe, { use_route: :any_old_thing }
I don't know why this worked - especially since for "any_old_thing", I really used nothing meaninful or connected tomy project at all. But, it seems to have worked, and now I can test my controllers.

Document upload (doc, docx, odt, etc.) and display in Rails (as text)?

Does anybody know how to upload a document to later show in a Rails application (as text)? Is Paperclip the right gem to do this? If it is how? (I have uploaded images before with Paperclip).
I like Paperclip. It seems well documented, and has worked well for everything I have needed. (I don't personally know any of them, but the clever folks at Thoughbot have created some pretty useful stuff, for which I feel indebted to them).
Obviously, you need to add Paperclip to your Gemfile, and (if you are using bundler) do your bundle install
Add to your model
has_attached_file :aFile
Add to you controller something to catch whatever you name it in your view (probably in your create and update methods)
#profile.aFile = params[:profile][:aFile]
Probably should check for its existence, if it is a required param
if params[:profile][:aFile].blank?
redirect_to #profile
else
render :action => 'do_something_interesting_with_file'
end
And that's about it. Don't forget your config entries. For example, if you are using some kind of post-processing on the file
Paperclip.options[:command_path] = "/opt/local/bin/"
I found this to be extraordinarily helpful
RailsCast by Ryan Bates

how ActiveAdmin works with existing controllers

I'm finding it difficult to understand how ActiveAdmin(http://activeadmin.info/) works with existing controllers
I have the following controllers
app/controllers/projects_controller.rb
and I was successfully able to implement ActiveAdmin UI over my views in the above controller. But my question is I have added the following before_filter in my controller
class StaticContentsController < ApplicationController
before_filter :list_content_types
def index
#static_contents = StaticContent.all
end
end
But this filter seems to be not executing, in fact I changed the code inside the index method to
#static_contents = abc StaticContent.all
As it should give and error because of 'abc' section, but surprisingly my app works with out an error. My guess is 'ActiveAdmin' reads controllers my its own, not the existing ones
this is my index action path
http://localhost:3000/admin/static_contents
and this is in development mode
Can someone help me on understanding how controllers works with ActiveAdmin or am I missing something here
Following are my configs
rails (3.0.0)
ruby 1.8.7
activeadmin (0.3.2)
thanks in advance
sameera
Activeadmin controllers are not the same as your app's controllers, they are separate. The reason your code is not causing an exception from the activeadmin interface is because that code is never hit. The activeadmin controller documentation specifies how to modify the default activeadmin actions.

How to override inherited_resources with the rails scaffold command

I am using the active_admin gem in my Rails 3 application, which has as a dependency inherited_resources. I am somewhat of a newb and would rather avoid the black box qualities of inherited_resources for my own controllers, however, when I run the default rails g scaffold command, the controllers that are generated are inheriting from inherited_resources. I know that I can manually override this by inheriting from ApplicationController, however, I would like to be able to generate the default rails scaffolds if possible.
-c=scaffold_controller
or add this to config/application.rb
config.generators do |g|
g.scaffold_controller "scaffold_controller"
end
Also noted in an issue thread over at github: https://github.com/josevalim/inherited_resources/issues/195

Devise authenticates before user/<id> but I want to turn it off

I've got Devise working on my Ruby on Rails application but viewing the user requires authentication and I don't want that. I've tried setting authenticate_user like so:
class UsersController < ApplicationController
before_filter :authenticate_user!, :except => [:show, :index]
..
end
But it still redirects to the sign_in page. Can anyone point me in the right direction?
Cheers,
Rim
PS: Please excuse my n00b-ness
Doh!
I was getting confused and had the wrong path. I been scratching my head for ages on that.
I fixed it...
I always use to copy controller files from devise gem folder to my applications controller folder
The devise controller files can be found here /usr/lib/ruby/gems/1.8/gems/devise-1.1.2/app/controllers/ (may be at different location in your case)
Copy devise folder in there and paste it to app/controllers/ and then customize registrations_controller as per your need
But I believe there must be some good solution on this. By the time you can use this.. :)