I have a site using pg_search and GIN indexes per this screencast. Recently I changed the pg_search_scope on a model to use the "simple" dictionary instead of "english". So then, do I need to write a new migration to update the GIN indexes as well since those indexes refer to_tsvector "english"?
Simplified example below.
class ChangeIndexesOnClients < ActiveRecord::Migration
def up
execute "drop index clients_name"
execute "create index clients_name on clients using gin(to_tsvector('simple', name))"
end
def down
execute "drop index clients_name"
execute "create index clients_name on clients using gin(to_tsvector('english', name))"
end
end
Thanks for updating. Also hope my comment below about typos isn't rude. I realize that it takes extra work to add the ASCIIcasts and in the final analysis I find them very useful as I don't always want to rewatch a video. Your diligence in maintaining them is appreciated.
Ok, last comment. I think this screencast should have included a complete Announcement resource with views, controller actions and model validations. It was fairly simple to wire up the controller and views to accomplish this. I assume it wasn't done as this screencast was focusing more on the test side. In my case, I used this as a guide to create an announcement function for a client site where the client needs to be able to easily manage his announcements.
Also was surprised by the number of small, but important typos in the ASCIIcast. Depending on your skill level, small mistakes can really throw you for a loop.
I also just realized that later in the screencast after creating the announcement controller at /app/controllers/announcements_controller.rb the first line has protect_from_forgery which doesn't belong. That is already in the application_controller.rb
A bit farther down is a paragraph about: "Before we change current we’ll write some tests for the new functionality." that references /spec/announcement_spec.rb instead of /spec/models/announcement_spec.rb
Following the ASCIIcast and just noticed a typo: "This test fails when we run it as our app doesn’t have an Application model. We’ll generate one now with the fields we use in our test then migrate the database."
Ok, so after watching this screencast I have two questions.
Why doesn't Ryan ever seem to use the respond_to syntax he covered way back in Episode 224
All the Railscasts episodes I have seen that cover Json always focus on customizing a response, but as a person still learning, I have never figured out what to do with a Json response. I also can't seem to find any good example apps that cover this. So now I know at least three ways to generate a Json response and still no idea of how to "consume" that response on the other end. This might be completely obvious to an experienced programmer, but not to me.
I switched over to strong_parameters and this has broken the basic CSV import method outlined in this screencast I am using on a Documents model. Wondering what syntax I would need to use to fix this line to work with strong_parameters.
Update. I went a little farther into the Screencast to see if the code would eventually work. After failing on the very first import, I spit out a CSV file with the IDs, and all columns and with the following code, it works now.
def self.import(file)
CSV.foreach(file.path, headers: true) do |row|
document = find_by_id(row["id"]) || new
document.attributes = row.to_hash.slice(*accessible_attributes)
document.save!
end
end
I ran into a problem immediately, and from what I can tell it is because I am using a pg_search enabled Document model I am trying to import. I also have another form_tag that I use to search Documents on the index page. Everytime I try to import I am getting.
A ActiveRecord::StatementInvalid occurred in documents#import:
PG::Error: ERROR: relation "pg_search_documents" does not exist
LINE 5: WHERE a.attrelid = '"pg_search_documents"'::reg...
If I remove the include PgSearch section from the Document model the CSV import works perfectly fine. How can I resolve this issue?
A bit belated, but I just implemented this feature into a new app I am working on and was looking for how to download only records in the current view or in a query. +1 for your tip above. Thank you. It works! It works!
I have used and been very happy with thoughbot/clearance but decided to follow this and roll my own since I want to use strong_parameters.
One thing I liked in Clearance is a signed_in? method so I added the following to application_controller. It works, just wonder if this is the proper place for it. I know it is very similar to current_user, but I seem to prefer this in certain places.
ruby
defsigned_in?
current_user.present?
end
helper_method :signed_in?
Here is an example of how I am using it. Note: I use (Haml)[http://www.haml-lang.orl) though indents aren't showing up below.
I enjoyed this episode, though the second migration to populate counts for previous records didn't seem to go over so well when I ran it on Heroku. I ended up rolling back the second migration.
I might be missing something obvious here, but I ran through this tutorial on my own app and then downloaded and setup the Blog After from this screencast. In both cases, when I do a search with more than one word... say for example "Lex Luthor"...
I get the following. So then, one word search no problem.. words with spaces between =
PG::Error: ERROR: syntax error in tsquery: "Lex Luthor"
LINE 1: ...articles" WHERE (to_tsvector('english', name) @@ 'Lex Lutho...
^
: SELECT "articles".* FROM "articles" WHERE (to_tsvector('english', name) @@ 'Lex Luthor' or to_tsvector('english', content) @@ 'Lex Luthor') ORDER BY ts_rank(to_tsvector(name), plainto_tsquery('Lex Luthor'))
desc LIMIT 3 OFFSET 0
Copycopter allows clients to edit text on a site without a developer. Shutting down your copycopter server would be no different from just editing all the text yourself to begin with. In my case, I will probably be the only person who uses Copycopter, but even just playing with it has helped me finally get a better grip on locales and I18n in my Rails apps.
This is an interesting tip. Super cool.
I have a site using pg_search and GIN indexes per this screencast. Recently I changed the pg_search_scope on a model to use the "simple" dictionary instead of "english". So then, do I need to write a new migration to update the GIN indexes as well since those indexes refer to_tsvector "english"?
Simplified example below.
Thanks for updating. Also hope my comment below about typos isn't rude. I realize that it takes extra work to add the ASCIIcasts and in the final analysis I find them very useful as I don't always want to rewatch a video. Your diligence in maintaining them is appreciated.
Ok, last comment. I think this screencast should have included a complete Announcement resource with views, controller actions and model validations. It was fairly simple to wire up the controller and views to accomplish this. I assume it wasn't done as this screencast was focusing more on the test side. In my case, I used this as a guide to create an announcement function for a client site where the client needs to be able to easily manage his announcements.
Also was surprised by the number of small, but important typos in the ASCIIcast. Depending on your skill level, small mistakes can really throw you for a loop.
I also just realized that later in the screencast after creating the announcement controller at
/app/controllers/announcements_controller.rb
the first line hasprotect_from_forgery
which doesn't belong. That is already in the application_controller.rbA bit farther down is a paragraph about: "Before we change current we’ll write some tests for the new functionality." that references
/spec/announcement_spec.rb
instead of/spec/models/announcement_spec.rb
Following the ASCIIcast and just noticed a typo: "This test fails when we run it as our app doesn’t have an
Application
model. We’ll generate one now with the fields we use in our test then migrate the database."I believe the
Application
should beAnnouncement
Ok, so after watching this screencast I have two questions.
Why doesn't Ryan ever seem to use the respond_to syntax he covered way back in Episode 224
All the Railscasts episodes I have seen that cover Json always focus on customizing a response, but as a person still learning, I have never figured out what to do with a Json response. I also can't seem to find any good example apps that cover this. So now I know at least three ways to generate a Json response and still no idea of how to "consume" that response on the other end. This might be completely obvious to an experienced programmer, but not to me.
I switched over to strong_parameters and this has broken the basic CSV import method outlined in this screencast I am using on a Documents model. Wondering what syntax I would need to use to fix this line to work with strong_parameters.
document.attributes = row.to_hash.slice(*accessible_attributes)
Update. I went a little farther into the Screencast to see if the code would eventually work. After failing on the very first import, I spit out a CSV file with the IDs, and all columns and with the following code, it works now.
I ran into a problem immediately, and from what I can tell it is because I am using a pg_search enabled Document model I am trying to import. I also have another form_tag that I use to search Documents on the index page. Everytime I try to import I am getting.
If I remove the include PgSearch section from the Document model the CSV import works perfectly fine. How can I resolve this issue?
The relevant portion from Document.rb:
A bit belated, but I just implemented this feature into a new app I am working on and was looking for how to download only records in the current view or in a query. +1 for your tip above. Thank you. It works! It works!
I have used and been very happy with thoughbot/clearance but decided to follow this and roll my own since I want to use strong_parameters.
One thing I liked in Clearance is a signed_in? method so I added the following to application_controller. It works, just wonder if this is the proper place for it. I know it is very similar to current_user, but I seem to prefer this in certain places.
Here is an example of how I am using it. Note: I use (Haml)[http://www.haml-lang.orl) though indents aren't showing up below.
- if signed_in?
%li= link_to 'Sign out', sign_out_path
- else
%li= link_to 'Sign in', sign_in_path
I enjoyed this episode, though the second migration to populate counts for previous records didn't seem to go over so well when I ran it on Heroku. I ended up rolling back the second migration.
I might be missing something obvious here, but I ran through this tutorial on my own app and then downloaded and setup the Blog After from this screencast. In both cases, when I do a search with more than one word... say for example "Lex Luthor"...
I get the following. So then, one word search no problem.. words with spaces between =
PG::Error: ERROR: syntax error in tsquery: "Lex Luthor"
LINE 1: ...articles" WHERE (to_tsvector('english', name) @@ 'Lex Lutho...
^
: SELECT "articles".* FROM "articles" WHERE (to_tsvector('english', name) @@ 'Lex Luthor' or to_tsvector('english', content) @@ 'Lex Luthor') ORDER BY ts_rank(to_tsvector(name), plainto_tsquery('Lex Luthor'))
desc LIMIT 3 OFFSET 0
Copycopter allows clients to edit text on a site without a developer. Shutting down your copycopter server would be no different from just editing all the text yourself to begin with. In my case, I will probably be the only person who uses Copycopter, but even just playing with it has helped me finally get a better grip on locales and I18n in my Rails apps.
Now you should update the CanCan episode as a part 2 to this revised episode. Thanks for putting the previous episodes together into a single lesson.