I've done this. I was having difficult getting templates to work, probably with haml, I don't really know, but the solution wasn't difficult once you realize there's no magic happening in the tmpl function.
In place of data.context = $(tmpl("template-upload", file)) pass file to your own function that marks up some html and set it to data.context. i.e. data.context = createNewStatusbarElement(file).
That function can build up the html element for the status bar from hardcoded html in strings, jquery methods, handlebars templates, or - as I've done - by cloning a hidden element (basically a poor-man's template).
Thanks Ryan, exactly the right episode at the right time :)
One note on using curl. It seem easy and nice to simply generate the static pages via "curl http://localhost:3000/errors/404 > public/404.html".
But beware that you generate them under the development environment but serves them in production. At least when they are checked in and deployed to production.
Your pages may contain stuff that should only be visible in development mode and not on staging or production.
So you may need to run the curl command on production to get the correct pages. That can be done manually after each deployment but that's cumbersome.
One can add a capistrano recipes that runs after deploy:restart (when the app is up using the maybe new layout). But then you great the pages whenever you restart the app.
And with static pages you cannot serve different pages for different context. For example a signed in user will get a 404 page without his user menu (preferences, account, ...) and
maybe without the logout button. That can be ok in your case but should be considered.
If you are fine with static pages you may generate them outside the controller via a rake tasks and run that task on every deployment via after "deploy:create_symlink", "deploy:error_pages:create"
We tried this but now using your solution via the ErrorsController.
I guess, you might have added the GoogleCalendars support.
I am facing problem in working out the google calender, event insertion using OmniAuth on google oAuth v3
Here's a suggestion for your railscasts that deal with JSON responses. Make the server reaponse automatically pretty-print the JSON so that it's easier to visually follow.
Not sure if I did something wrong or if Rails 4 changed, but I ran through this episode using Rails 4 beta. The link in the view to point to page_path("about") worked fine if I wanted http://site/pages/about as my link but did not change to just http://site/about even after changing the route.
I wound up making that page_path["about"] and it seemed to work correctly. Just dropping this here if anyone else encounters it.
Following the instructions from this screencast, I was able to configure the gem to work on my local machine (a Mac) perfectly fine. However, deploying the application via capistrano to a Linux box, running the app with unicorn doesn't appear to be working. My unicorn.log contains the following error:
E, [2013-04-24T15:20:23.211288 #6163] ERROR -- : uninitialized constant ExceptionNotifier (NameError)
/path/to/app/releases/20130424201053/config/environments/production.rb:80:in `block in '
even though the gem is installed. I can't figure out how to load the library. Any help?
Just in case you were still wondering, Rails creates these IDs when you use the <%= form_for ... %> helper. It knows that you're creating a new record so it defaults to a form ID of "new_model". It does the same thing for the IDs for various inputs.
Actually had this problem in a project a while back. Ended up using a UUID as the property's hash key, but using a display_name when displaying them, allowing the field names to change without breaking the rest of it. It was complicated, though, and I'm not sure doing so would work well with Hstore. It did add a few extra layers of abstraction and wasn't very fun to work with. @phillyslick also makes a good point that deleting fields doesn't delete the data from the properties hash. The only way we found to work around that was to update all the items of a certain type if the type changed.
This is a great cast, but in my experience doing this kind of thing can bring you down a pretty slippery slope if the users aren't warned of the consequences. With great flexibility comes great responsibility, and diligence and well tested rake tasks should be built into the system.
Nice episode, but it would be beneficial to add something like response.status = request.path[1..-1] to make the status code carry over (if anyone knows of a nicer way to do this, speak up).
Otherwise, the error pages will all have a status of 200 OK since the error controller itself responded normally.
+1 for counter_culture. This really should be how Rails works by default. In my experience the need to have multiple counter cache columns (goals, completed goals - books, books read) is the norm rather than the exception and this gem allows that and much more.
I have been thinking to change an existing app of mine to a single page app. Planning to use either backbone, angular or ember. Saw the railscasts on all three of them and I understood how to get them to rails.
I am sure that each of these have their own pros and cons depending on the situation. It would really be nice if you have a railscast that can elaborate on the situations where one them would be better than others.
For example, in my app I have a genre field, and if, say "Punk Rock" is already an option, and someone wants to just add "Punk", "Punk Rock" shows up in the dropdown and there is no option to add just "Punk".
Seems that If you want to add anything that is already included in another name you won't be able to.
As much as I love Ryan and all the Railscasts, this one is a bit confusing, for this reason:
When Ryan talks about "reputation_value_for" (now "reputation_for") as giving him the "total number of votes," it is in fact giving him the SUM OF THE VOTE VALUES. So, if one is looking for the actual total number of votes, regardless of vote value, the returned value is incorrect.
In fact, as far as I can tell, there is no generic way to get the total number of votes on a model without assigning a constant "1" to a vote tally value and using reputation_for(:vote_tally). So, in order to end up with:
78% of 281 voters like this Haiku. You like it, too.
...there is a need to add a THIRD reputation to get the count of ReputationSystem::Evaluations on the Haiku model, since we need to use:
I had the same error. I am using company names instead of countries. All of my companies have a space in the name. Was wondering if you possibly found a fix.
when i try to search the words which has special characters like(computer & laptops,compuers)and plural word searching is also became problem for me using sunspot.kindly anyone help me to solve this issue.
Thank you, Ryan.
I got a syntax error with tokenInput and Rails 3.2.13, but fortunately fixed it by myself.
I guess that the new version of CoffeeScript compiler in Rails caused it.
What I got was
SyntaxError: unexpected INDENT
The solution is simple.
Just add "," after '/tags.json' in books.js.coffee.
Can someone please help me - very desperate, will pay!
My very simple Rails App has a Model with two methods:
:From :To
I use the awesome (Google Maps API) powered address-rails-picker app for the :to and :from in the form to automplete any location the user types in.
I do however have trouble in writing a validation that forces the user to choose an autocomplete location instead of writing any gibberish the user wants.
Would the Token Input help here by limiting it to one? I don't wan the Facebook look though with the X etc.
Oh Hey James! Haha. I tend to agree by the way, although lately I have my doubts on JBuilder's performance. But I might be hallucinating. Need to benchmark.
Raffler.EntriesController = Ember.ArrayController.extend
# include the following method.
removeItem: (obj) ->
obj.get('content').deleteRecord()
@store.commit()
My issue was that I was not calling 'deleteRecord()' on the 'content'.
You're welcome! I certainly did not perceive your comment about typos as rude, and I can certainly imagine that some of these typos could certainly confuse beginners a great deal. I do not write the ASCIIcasts though ;-)
As a moderator I am happy with anyone who takes the time to report inconsistencies or flaws in the textual content on the site so that they can be corrected by one of the moderators, by doing so you make Railscasts a better place for everyone! I am glad this work is appreciated!
When i try to deploy VPS after running service nginx start command i got following error:
root@li356-76:~# service nginx start
* Starting nginx nginx nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
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.
Problem solved. :)) Thank's
Hi, i am new with ruby on rails.
I have this problem:
LoadError in Products#index
Showing /Users/bogdy/store/app/views/layouts/application.html.erb where line #5 raised:
cannot load such file -- less
(in /Users/bogdy/store/app/assets/stylesheets/bootstrap_and_overrides.css.less)
Extracted source (around line #5):
This make all like in the video. Help please!!!
I've done this. I was having difficult getting templates to work, probably with haml, I don't really know, but the solution wasn't difficult once you realize there's no magic happening in the tmpl function.
In place of
data.context = $(tmpl("template-upload", file))
passfile
to your own function that marks up some html and set it to data.context. i.e.data.context = createNewStatusbarElement(file)
.That function can build up the html element for the status bar from hardcoded html in strings, jquery methods, handlebars templates, or - as I've done - by cloning a hidden element (basically a poor-man's template).
Thanks Ryan, exactly the right episode at the right time :)
One note on using curl. It seem easy and nice to simply generate the static pages via "curl http://localhost:3000/errors/404 > public/404.html".
But beware that you generate them under the development environment but serves them in production. At least when they are checked in and deployed to production.
Your pages may contain stuff that should only be visible in development mode and not on staging or production.
So you may need to run the curl command on production to get the correct pages. That can be done manually after each deployment but that's cumbersome.
One can add a capistrano recipes that runs after deploy:restart (when the app is up using the maybe new layout). But then you great the pages whenever you restart the app.
And with static pages you cannot serve different pages for different context. For example a signed in user will get a 404 page without his user menu (preferences, account, ...) and
maybe without the logout button. That can be ok in your case but should be considered.
If you are fine with static pages you may generate them outside the controller via a rake tasks and run that task on every deployment via after "deploy:create_symlink", "deploy:error_pages:create"
We tried this but now using your solution via the ErrorsController.
Thanks!
I have the same question.
I guess, you might have added the GoogleCalendars support.
I am facing problem in working out the google calender, event insertion using OmniAuth on google oAuth v3
thank you very much
In case anyone failed to notice:
http://railscasts.com/episodes/408-ember-part-1
http://railscasts.com/episodes/410-ember-part-2
Ryan,
Here's a suggestion for your railscasts that deal with JSON responses. Make the server reaponse automatically pretty-print the JSON so that it's easier to visually follow.
I've found this neat rack middleware trick:
http://stackoverflow.com/a/13029297/1148455
Thanks for mentioning this. I ran into the exact same thing.
Has anyone found a good way to test this with RSpec?
Hello there,
This episode is great and helpful,but what if I need additional fields for storing like tag description? Any idea?
Not sure if I did something wrong or if Rails 4 changed, but I ran through this episode using Rails 4 beta. The link in the view to point to page_path("about") worked fine if I wanted http://site/pages/about as my link but did not change to just http://site/about even after changing the route.
I wound up making that page_path["about"] and it seemed to work correctly. Just dropping this here if anyone else encounters it.
http://en.wikipedia.org/wiki/Domain-specific_language
Following the instructions from this screencast, I was able to configure the gem to work on my local machine (a Mac) perfectly fine. However, deploying the application via capistrano to a Linux box, running the app with unicorn doesn't appear to be working. My unicorn.log contains the following error:
E, [2013-04-24T15:20:23.211288 #6163] ERROR -- : uninitialized constant ExceptionNotifier (NameError)
/path/to/app/releases/20130424201053/config/environments/production.rb:80:in `block in '
even though the gem is installed. I can't figure out how to load the library. Any help?
+1
@tpy,
Just in case you were still wondering, Rails creates these IDs when you use the <%= form_for ... %> helper. It knows that you're creating a new record so it defaults to a form ID of "new_model". It does the same thing for the IDs for various inputs.
Actually had this problem in a project a while back. Ended up using a UUID as the property's hash key, but using a
display_name
when displaying them, allowing the field names to change without breaking the rest of it. It was complicated, though, and I'm not sure doing so would work well with Hstore. It did add a few extra layers of abstraction and wasn't very fun to work with. @phillyslick also makes a good point that deleting fields doesn't delete the data from the properties hash. The only way we found to work around that was to update all the items of a certain type if the type changed.This is a great cast, but in my experience doing this kind of thing can bring you down a pretty slippery slope if the users aren't warned of the consequences. With great flexibility comes great responsibility, and diligence and well tested rake tasks should be built into the system.
Nice episode, but it would be beneficial to add something like
response.status = request.path[1..-1]
to make the status code carry over (if anyone knows of a nicer way to do this, speak up).Otherwise, the error pages will all have a status of
200 OK
since the error controller itself responded normally.Hi Jesus H. Did you ever figure this out? I'm having the exact same issue. Thanks!
+1 for counter_culture. This really should be how Rails works by default. In my experience the need to have multiple counter cache columns (goals, completed goals - books, books read) is the norm rather than the exception and this gem allows that and much more.
authors << {id: "<<<#{query}>>>", name: "New: \"#{query}\""}
Removing the brackets makes it work.
Thanks for all the railscasts.
I have been thinking to change an existing app of mine to a single page app. Planning to use either backbone, angular or ember. Saw the railscasts on all three of them and I understood how to get them to rails.
I am sure that each of these have their own pros and cons depending on the situation. It would really be nice if you have a railscast that can elaborate on the situations where one them would be better than others.
Has anyone figure this out?
For example, in my app I have a genre field, and if, say "Punk Rock" is already an option, and someone wants to just add "Punk", "Punk Rock" shows up in the dropdown and there is no option to add just "Punk".
Seems that If you want to add anything that is already included in another name you won't be able to.
As much as I love Ryan and all the Railscasts, this one is a bit confusing, for this reason:
When Ryan talks about "reputation_value_for" (now "reputation_for") as giving him the "total number of votes," it is in fact giving him the SUM OF THE VOTE VALUES. So, if one is looking for the actual total number of votes, regardless of vote value, the returned value is incorrect.
In fact, as far as I can tell, there is no generic way to get the total number of votes on a model without assigning a constant "1" to a vote tally value and using reputation_for(:vote_tally). So, in order to end up with:
78% of 281 voters like this Haiku. You like it, too.
...there is a need to add a THIRD reputation to get the count of ReputationSystem::Evaluations on the Haiku model, since we need to use:
has_reputation :votes, source: :user, aggregated_by: :sum
has_reputation :avg_vote, source: :user, aggregated_by: :average
...in order to get the user's vote (assigned as 1 = like or 0 = unlike) as well as the average vote. So we add:
has_reputation :vote_tally, source: :user, aggregated_by: :sum
Then, in the vote action in the controller:
v_value = params[:type] == "up" ? 1 : 0
@haiku.add_or_update_evaluation(:votes, v_value, current_user)
@haiku.add_or_update_evaluation(:avg_vote, v_value, current_user)
@haiku.add_or_update_evaluation(:vote_tally, "1", current_user)
If there's an easier way to get the total number of votes on a model, I'd love to hear about it.
I had the same error. I am using company names instead of countries. All of my companies have a space in the name. Was wondering if you possibly found a fix.
On REVISION: 12 it's not needed anymore. obj.deleteRecord() would suffice.
hi, great! I am trying to figure out how to get the right syntax highlighting for unicorn_init.erb as shown in the screencast?
when i try to search the words which has special characters like(computer & laptops,compuers)and plural word searching is also became problem for me using sunspot.kindly anyone help me to solve this issue.
thanks in advance
Thank you, Ryan.
I got a syntax error with tokenInput and Rails 3.2.13, but fortunately fixed it by myself.
I guess that the new version of CoffeeScript compiler in Rails caused it.
What I got was
The solution is simple.
Just add "," after '/tags.json' in books.js.coffee.
JavaScript way, for table:
http://datatables.net/extras/tabletools/
Can someone please help me - very desperate, will pay!
My very simple Rails App has a Model with two methods:
:From :To
I use the awesome (Google Maps API) powered address-rails-picker app for the :to and :from in the form to automplete any location the user types in.
I do however have trouble in writing a validation that forces the user to choose an autocomplete location instead of writing any gibberish the user wants.
Would the Token Input help here by limiting it to one? I don't wan the Facebook look though with the X etc.
Thanks Michael Hawkins. That comment put an end to my misery.
Just want to point out the massive acronym typo in the description.
It's WYSIWYG as in "woh-zee-wig". What You See Is What You Get.
I can't for the life of me figure out what "WISYIWYG" could stand for...
Wild Industrial Skeletons. You and I Will Yell Greatly?
Oh Hey James! Haha. I tend to agree by the way, although lately I have my doubts on JBuilder's performance. But I might be hallucinating. Need to benchmark.
This is certainly an area of my apps that needs some TLC. Thanks!
Ok. Found it!
My issue was that I was not calling 'deleteRecord()' on the 'content'.
Any progress in how to sort column data from associated tables using server side processing?
Records are associated by id ( workshop.id = location_id)
On the Workshop datatable class, the information displayed is the location_name
I would like to be able to sort the location column by location_name and not by location_id.
I have the same scenarios with many to many categories. I have found difficulty with update method on product. Any ideas to help?
What is the proper way to delete an Entry?
@Bharat Ruparal
https://github.com/lazylester/error_pages_engine
Problem got fixed using add this line in top of ~/.bashrc on remote server.
Assuming that i am using rvm in my remote as well as in my local computer.
Thanks Ryan
Awesome!
Unfortunately I've been swamped with a ton of work and have not attempted to get it working yet.
If I get some free time this weekend I'll try and give the implementation a shot :)
I am trying to deploy my rails app to Linode VPS but after i finished all steps when i did
i got following error:
full log is below:
I tried all the ways and update following in deploy.rb
require "bundler/capistrano"
but problem still unresolved,Anyone can help me?
You're welcome! I certainly did not perceive your comment about typos as rude, and I can certainly imagine that some of these typos could certainly confuse beginners a great deal. I do not write the ASCIIcasts though ;-)
As a moderator I am happy with anyone who takes the time to report inconsistencies or flaws in the textual content on the site so that they can be corrected by one of the moderators, by doing so you make Railscasts a better place for everyone! I am glad this work is appreciated!
Thanks, i have similar problem, now problem got fixed.
Thanks @jeremydt by your solution my problem got fixed
Hello
When i try to deploy VPS after running service nginx start command i got following error:
What should i do to fix this problem?
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.