When I try to insert an image into my blog I select the Upload tag and select my file and Send it to Server. Then at the URL tab I select Browse Server and I get the following error:
ActiveRecord::StatementInvalid in Ckeditor::AttachmentFilesController#index
PG::Error: ERROR: relation "ckeditor_assets" does not exist
LINE 5: WHERE a.attrelid = '"ckeditor_assets"'::regclas...
^
: SELECT a.attname, format_type(a.atttypid, a.atttypmod),
pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"ckeditor_assets"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
any ideas?
EDIT
I skipped a migration for the above problem. But I still can't upload a file. I'm getting this error:
Started POST "/ckeditor/attachment_files? CKEditor=blog_entry_body&CKEditorFuncNum=1&langCode=en" for 127.0.0.1 at 2013-05-24 18:10:29 -0500
Processing by Ckeditor::AttachmentFilesController#create as HTML
Parameters: {"upload"=>#<ActionDispatch::Http::UploadedFile:0x000000047e3c28 #original_filename="me.jpg", #content_type="image/jpeg", #headers="Content-Disposition: form-data; name=\"upload\"; filename=\"me.jpg\"\r\nContent-Type: image/jpeg\r\n", #tempfile=#<Tempfile:/tmp/RackMultipart20130524-27036-1g7t9yd>>, "CKEditor"=>"blog_entry_body", "CKEditorFuncNum"=>"1", "langCode"=>"en"}
WARNING: Can't verify CSRF token authenticity
User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."remember_token" = 'M96bQAv-NGdidsn7hypOJA' LIMIT 1
(0.2ms) BEGIN
(0.3ms) ROLLBACK
Rendered text template (0.0ms)
It looks like it's happening in Ckeditor::AttachmentFilesController#create. But I didn't see this controller get generated when I installed the CKEditor gem. I found in another post that I must skip_before_filter :verify_authenticity_token but like I said, I don't see Ckeditor::AttachmentFilesController#create.
That SQL is what ActiveRecord uses to figure out the structure of a PostgreSQL table and thus the attributes for an ActiveRecord::Base subclass. The "relation does not exist" error means that you have a CkeditorAsset ActiveRecord class (hence the ckeditor_assets table name) but not ckeditor_assets table. You're missing a migration somewhere, perhaps there is a generator for initializing your CKEditor plugin that you forgot to run.
Related
I have just upgraded an application from Rails 3.2.8 to Rails 4.0.2 and I've got an strange behaviour with a model that has a "default_scope" defined.
The questions is that it seems like "unscoped" (http://api.rubyonrails.org/classes/ActiveRecord/Scoping/Default/ClassMethods.html#method-i-unscoped) doesn't work in Rails 4 in the same way it used to do in Rails 3.
The problem raises when I try to chain "unscoped" with another "scope". In Rails 3 it worked fine by first removing default scope and then applying the second scope. In Rails 4, it adds the default scope always.
I have a Model defined this way:
class User < ActiveRecord::Base
......
# set a default scope to be aplied to EVERY query. to override this use "unscoped", for example: User.unscoped.all
def self.default_scope
where :active => true
end
# users that can be shown in the application
scope :not_hidden, where(:hidden => false)
.....
end
And here are some examples on how scope and unscoped are working on 3.2.8 and 4.0.2:
User.all (OK)
(3.2.8)
User.all
SELECT "users".* FROM "users" WHERE "users"."active" = 't'
(4.0.2)
User.all
SELECT "users".* FROM "users" WHERE "users"."active" = 't'
User.unscoped (OK)
(3.2.8)
User.unscoped
SELECT "users".* FROM "users"
(4.0.2)
User.unscoped
SELECT "users".* FROM "users"
User.unscoped.not_hidden (FAIL)
(3.2.8) (OK)
User.unscoped.not_hidden
SELECT "users".* FROM "users" WHERE "users"."hidden" = 'f'
(4.0.2) (FAIL)
User.unscoped.not_hidden
SELECT "users".* FROM "users" WHERE "users"."active" = 't' AND "users"."hidden" = 'f'
User.not_hidden.unscoped (OK)
(3.2.8) (OK)
User.not_hidden.unscoped
SELECT "users".* FROM "users"
(4.0.2) (OK)
User.not_hidden.unscoped
SELECT "users".* FROM "users"
Can anybody tell me if I'm missing something on how default scope and unscoped works in Rails 4?
That's desired behaviour (see Removing All Scoping in the guides).
Note that chaining unscoped with a scope does not work. In these
cases, it is recommended that you use the block form of unscoped:
Client.unscoped {
Client.created_before(Time.zone.now)
}
I have just found a solution.
I have changed not_hidden scope defintion from:
scope :not_hidden, where(:hidden => false)
To:
def self.not_hidden
where(:hidden => false)
end
And it works fine!!!!
I have a simple form for Recommendations. REcommendations has_many Assets.
so in my controller I am doing a simple:
6.times {#recommendation.assets.build}
My issue occurs when I try to save the Recommendation and there are Validation errors. My Create action:
def create
#recommendation = Recommendation.new(params[:recommendation])
#recommendation.user_id = current_user.id
respond_to do |format|
if #recommendation.save
format.html { redirect_to thankyou_path, notice: 'Recommendation was successfully created.' }
else
6.times {#recommendation.assets.build} if #recommendation.assets.blank?
render action: "new"
end
end
end
running this page and submitting (with validation errors) causes the following log output and a http 406 error
Started POST "/categories/1/awards/9/recommendations" for 127.0.0.1 at 2013-01-07 11:50:13 -0800
Processing by RecommendationsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"8PVfFZGa72+3KU/km2weZhNy0rxRfp0Qd+CkHdBoQM8=", "recommendation"=>{"nominee"=>"", "title"=>"", "department"=>"", "award_id"=>"9", "summary"=>"", "accomplishments"=>"", "caption"=>"", "url"=>"", "supervisor"=>"You ARE NOT the nominee’s direct manager / supervisor", "approvals_attributes"=>{"0"=>{"email"=>""}}}, "commit"=>"Save/Submit", "category_id"=>"1", "award_id"=>"9"}
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = 2 LIMIT 1
(0.2ms) BEGIN
(0.1ms) ROLLBACK
Rendered shared/_recommend_timeline.html.erb (1.2ms)
Award Load (20.1ms) SELECT "awards".* FROM "awards" WHERE "awards"."id" = 9 LIMIT 1
Rendered recommendations/_form.html.erb (66.7ms)
Rendered recommendations/new.html.erb within layouts/application (69.8ms)
(0.5ms) SELECT COUNT(*) FROM "recommendations" WHERE "recommendations"."user_id" = 2
(0.6ms) SELECT COUNT(*) FROM "approvals" WHERE "approvals"."email" = 'tj#ravennainteractive.com' AND "approvals"."approved" IS NULL
Completed 406 Not Acceptable in 556ms (Views: 188.6ms | ActiveRecord: 31.5ms)
I have looked at multiple questions on stack that seem similar but
I'm not sure there is enough information to be able to answer with much confidence, but I don't think you want to rebuild exactly 6 times. Depending on your model setup, the validation could nullify one, but not all of the associations.
Perhaps you should try:
(6-#recommendation.assets.count).times {#recommendation.assets.build}
My guess is that your view is expecting exactly 6 assets but only finding somewhere from 1-5 after the invalid ones were thrown out, and that this is causing an internal error.
If that doesn't fix it, I think you may need to provide more information about what validations are running on assets, and what your view looks like.
I have a rails 3 application using devise with the subscribers model. I would like the subscribers to update their account information in place using best_in_place gem, but I can't seem to get it to update the database. It will update on the screen, but not the database.
The error sees to suggest the subscriber existing is a bad thing, but it isn't since it would be impossible to update that subscriber if it didn't exist.
All I want to do is be able to allow the users to update their information in place from a the subscriber/accounts#show page that shows them their details.
my subscriber/accounts controller has this:
def update
#subscriber = Subscriber.find(current_subscriber.id)
#subscriber.update_without_password(params[:subscriber])
end
I always get these results in the server log:
Processing by Subscribers::AccountsController#update as JSON
Parameters: {"subscriber"=>{"firstname"=>"Aarof"}, "authenticity_token"=>"Sx6kEQy4NC56ovikMs/D9nVPGJt1q5jNCoFnNjFhDu8=", "id"=>"2"}
Subscriber Load (1.9ms) SELECT `subscribers`.* FROM `subscribers` WHERE `subscribers`.`id` = 2 LIMIT 1
CACHE (0.0ms) SELECT `subscribers`.* FROM `subscribers` WHERE `subscribers`.`id` = 2 LIMIT 1
(0.2ms) BEGIN
Subscriber Exists (0.4ms) SELECT 1 AS one FROM `subscribers` WHERE (`subscribers`.`email` = BINARY 'frostsquid#yahoo.com' AND `subscribers`.`id` != 2) LIMIT 1
(0.1ms) ROLLBACK
Redirected to http://localhost:3000/subscribers/accounts/2
Completed 302 Found in 12ms (ActiveRecord: 2.6ms)
my show page looks like this:
%p.subscriber-account-info
=best_in_place #subscriber, :firstname, :path => subscribers_account_path(#subscriber)
My routes for subscribers looks like:
subscribers_accounts GET /subscribers/accounts(.:format) subscribers/accounts#index
POST /subscribers/accounts(.:format) subscribers/accounts#create
new_subscribers_account GET /subscribers/accounts/new(.:format) subscribers/accounts#new
edit_subscribers_account GET /subscribers/accounts/:id/edit(.:format) subscribers/accounts#edit
subscribers_account GET /subscribers/accounts/:id(.:format) subscribers/accounts#show
PUT /subscribers/accounts/:id(.:format) subscribers/accounts#update
I just checked trying to update subscribers firstname using the console and received the same message that the subscriber exists and it rolled the transaction back. Is this because of something in Devise?
Maybe a little the answer, but do you respond to JSON? here sample code from our project:
def update
respond_to do |format|
resource_files_service.update(#resource_file, params[:resource_file], current_user)
format.html { }
format.json { respond_with_bip(#resource_file) }
end
I stumbled upon a wonderful article about scopes on Rails 3+ : http://edgerails.info/articles/what-s-new-in-edge-rails/2010/02/23/the-skinny-on-scopes-formerly-named-scope/index.html
You can read there (in 'Crazy Town' section) that it's possible to merge scopes from different models like this :
class User < ActiveRecord::Base
scope :published, lambda {
joins(:posts).group("users.id") & Post.published
}
end
which works just as expected, and allows you to do :
User.published.to_sql
#=> SELECT users.* FROM "users"
# INNER JOIN "posts" ON "posts"."author_id" = "users"."id"
# WHERE (posts.published_at IS NOT NULL AND posts.published_at <= '2010-02-27 02:55:45.063181')
# GROUP BY users.id
I tried this approach in my Rails 3.1 project and apparently it's not working anymore.
So I cloned the article's Rails 3.0.0-beta1 project, saw by my eyes that the guys are not lying and things are working the way they tell.
Then I 3.1'ed it up, and now I get :
ruby-1.9.2-p290 :003 > User.published.to_sql
User Load (0.3ms) SELECT "users".* FROM "users" INNER JOIN "posts" ON "posts"."author_id" = "users"."id" GROUP BY users.id
Post Load (0.2ms) SELECT "posts".* FROM "posts" WHERE (posts.published_at IS NOT NULL AND posts.published_at <= '2011-10-05 11:45:00.512231')
User Load (0.1ms) SELECT "users".* FROM "users"
NoMethodError: undefined method `to_sql' for []:Array
from (irb):3
from /home/jerefrer/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0/lib/rails/commands/console.rb:45:in `start'
from /home/jerefrer/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0/lib/rails/commands/console.rb:8:in `start'
from /home/jerefrer/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0/lib/rails/commands.rb:40:in `<top (required)>'
from script/rails:9:in `require'
from script/rails:9:in `<main>'
==> Doesn't work anymore.
And that makes me sad, because scope merging was awesome and now I can't be as DRY as I want.
Do you know :
What happened between the two versions ?
Any other way to do the same ?
The & method doesn't look like it works anymore (too bad, I found the syntax was neat). You can replace it with ActiveRecord::Relation#merge:
class User < ActiveRecord::Base
scope :published, lambda {
joins(:posts).group("users.id").merge(Post.published)
}
end
Edit
And it looks like it won't be back, trying it in rails 3.0.10 gives a deprecation warning:
DEPRECATION WARNING: Using & to merge relations has been deprecated and will be removed in Rails 3.1. Please use the relation's merge method, instead.
Here's the commit deprecating it, in case someone's interested: https://github.com/rails/rails/commit/66003f596452aba927312c4218dfc8d408166d54
I am working on an application that I am wanting to authenticate through a custom oauth provider I have setup on a different server.
I am trying to integrate this custom login using RefineryCMS. I have my routes setup, but for some reason it is still trying to follow the devise route built into RefineryCMS.
Routes.rb
devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
devise_scope :users do
match '/users/auth/:provider', :to => 'users/omniauth_callbacks#passthru'
end
Link for callback
<p><%= link_to "Sign in with Olympus", user_omniauth_callback_path(:olympus) %></p>
Olympus is the codename for the project for now.
Omniauth callback controller:
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def olympus
auth = env["omniauth.auth"]
ap auth
end
def passthru
render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
end
end
The log via rails s once the link is clicked on:
Started GET "/users/auth/olympus/callback" for 127.0.0.1 at 2011-08-12 07:52:09 -0500
Processing by Devise::OmniauthCallbacksController#failure as
SQL (0.7ms) SHOW TABLES
SQL (0.6ms) SHOW TABLES
Page Load (0.3ms) SELECT `pages`.`id`, `pages`.`depth`, `pages`.`parent_id`, `pages`.`lft`, `pages`.`rgt`, `pages`.`link_url`, `pages`.`menu_match`, page_translations.title as page_title FROM `pages` INNER JOIN `page_translations` ON `page_translations`.`page_id` = `pages`.`id` WHERE `pages`.`draft` = 0 AND `pages`.`show_in_menu` = 1 AND `page_translations`.`locale` = 'en' ORDER BY lft ASC
Slug Load (0.1ms) SELECT `slugs`.* FROM `slugs` WHERE (`slugs`.`sluggable_id` IN (1,3) and `slugs`.`sluggable_type` = 'Page' AND (`slugs`.`locale` = 'en')) ORDER BY id DESC
Slug Load (0.2ms) SELECT `slugs`.* FROM `slugs` WHERE (`slugs`.sluggable_id = 3 AND `slugs`.sluggable_type = 'Page') ORDER BY id DESC
SQL (1.3ms) describe `roles_users`
Role Load (0.1ms) SELECT `roles`.* FROM `roles` WHERE `roles`.`title` = 'Refinery' LIMIT 1
SQL (1.4ms) describe `roles_users`
User Load (0.2ms) SELECT * FROM `users` INNER JOIN `roles_users` ON `users`.id = `roles_users`.user_id WHERE (`roles_users`.role_id = 1 )
Redirected to http://localhost:3000/users/login
So its still trying to go through the Devise::OmniauthCallbacksController through RefineryCMS... Does anyone know how to get around this or maybe even override this devise controller?
I also would like to say that I am completely new to working with oauth providers/clients. I have worked with Facebook and Twitter but doing them from scratch is something I am new at. As well as working with Devise/Omniauth. So excuse my ignorance. Thanks!
Fixed routing issue by reading this article: http://groups.google.com/group/refinery-cms/browse_thread/thread/37917e227b26f5ca
The issue I am having now, is that it appears to not be connecting to my oauth provider to do the authenticating :(