I'm probably missing the obvious, but I'm curious why you would place the JSON inside a tag in the HTML. Why wouldn't a user who is interested in the JSON just append .json to the URL?
Ember Data expects the server to respond JSON with errors as the root key, then the attribute name with the errors nested inside of that. You can basically do the following in Rails and Ember will accept it.
This will set 'isError' on that model and will remain at isError (and refuse to commit) until the attributes that the server said had errors are changed.
I have to agree with this. Ryan normally provides an amazing resource in Railscasts, but I find the raffler example too contrived to be useful. Especially for a pro cast.
I'd like to pass a parameter to the datatable.rb... specifically, the @user = User.find(params[:id]). Side note, I'd also like to be able to use current_user in the new class. I haven't tried it, so I'm not sure if that will even work.
I have an application using devise for my authentication. How do I allow users to NOT have to input their current password every time they want to update their settings?
how can I replace the method find_by_name in rails4? where(:name = 'params[:name]') ?
i have error in session_controller: undefined method `authenticate' =/ anyone help?
Prawn is working fine in development but in production, my app is not even opening. When I check production logs I get a looping message
production.log
...
19x.xxx.xxx.xxx: Connecting to database specified by database.yml
19x.xxx.xxx.xxx: Connecting to database specified by database.yml
19x.xxx.xxx.xxx: Connecting to database specified by database.yml
19x.xxx.xxx.xxx: Connecting to database specified by database.yml
...
Exactly right. This why, if I "must" use AR in a migration, I prefer to redefine (much simplified) classes within the migration file... ensuring that the AR class definitions match the db schema.
Also, for large datasets, executing SQL rather than instantiating AR records can mean your migration runs in seconds rather than minutes/hours.
if status == 200
$('#order_stripe_card_token').val(response.id)
$('#new_order')[0].submit()
clause in your script below?
coffeescript --yum
if response.error.message == "An unexpected error has occurred. We have been notified of the problem."
$('input[type=submit]').attr('disabled', false)
else
$('#stripe_error').text(response.error.message)
$('input[type=submit]').attr('disabled', false)
After you test for "An unexpected error..." or before?
I am testing on a legacy machine running XP (so IE 8) and not seeing the error. Should probably try on a machine running IE 10.
I cannot track down what I did (probably upgraded the Stripe API on our account), but as I worked back through my Stripe test logs, about 2 weeks ago each execution of:
in my coffee script started generating two tokens at the Stripe end, not one. Don't know if it is related because with FireFox (both XP and Mac) the "An unexpected error has occurred. We have been notified of the problem.", does not generate a token log entry (or 2) in the Stripe log, but :
js.coffee
handleStripeResponse: (status, response) ->
if status == 200
$('#order_stripe_card_token').val(response.id)
$('#new_order')[0].submit()
gets to the .submit() line, presumably because of a status ==200.
With Chrome, the error is there, but the token is in the hidden token field on the form and dismissing the error results in a new order being properly created. With FireFox, there doesn't seem to be anything in the hidden token field and order creation fails (but not by redirecting back to the "submit order" page.
I'm getting with Firefox (with subsequent failure to create to new entry--order in my case rather than subscription), Chrome (here the new entry is created...)
My 2 cents on Ember after watching this screencast:
- the code after refactoring to extend ArrayController looks actually pretty worse than it was before ( added magic, more lines of code, and bizarre stuff like #each controller ).
- No way in hell am i ever gonna use Ember.js. Weird setters and getters, weird routes that sets controller data, and really a lot of files to do something that looks much simpler in other frameworks. I would prefer going full JS with meteor or another Node framework or Angular.
view_context is a method on ActionController::Metal (iirc) that builds a new 'view context object.' This is usually an instance of ActionView::Base, but is override-able. Every time you call it, it generates a new one, because caching is hard, basically.
Hi there! I maintain both AMS and Draper, so maybe I can give you some insight. ;)
Draper is about general decoration, AMS is about serializing to JSON. I know several people that use both together: Draper for adding presentation-only concerns, and then AMS to actually do the conversion.
It's arguable that serialization and view-specific logic are two different concerns, and require two different objects.
Also, if you use Draper's #to_json, you miss out on the conventions that AMS provides.
Yes, angularjs is great for my contacts app. But ember is better than angularjs for a whole project. Because ember has associations, rails like model, view, router, controller.
USE ANGULAR: If your project has a single model like contact. USE EMBER: If your project has several models like railcasts.com app.
[Thu Mar 14 03:34:18 2013] [warn] default VirtualHost overlap on port 8080, the first has precedence
** [out :: staging.absolutecommerce.com]
** [out :: staging.absolutecommerce.com] [Thu Mar 14 03:34:18 2013] [warn] default VirtualHost overlap on port 7001, the first has precedence
** [out :: staging.absolutecommerce.com]
** [out :: staging.absolutecommerce.com] [Thu Mar 14 03:34:18 2013] [warn] default VirtualHost overlap on port 7000, the first has precedence
** [out :: staging.absolutecommerce.com]
** [out :: staging.absolutecommerce.com] [Thu Mar 14 03:34:18 2013] [warn] NameVirtualHost *:8443 has no VirtualHosts
** [out :: staging.absolutecommerce.com]
** out :: staging.absolutecommerce.comAddress already in use: make_sock: could not bind to address 0.0.0.0:7000
** [out :: staging.absolutecommerce.com]
** [out :: staging.absolutecommerce.com] no listening sockets available, shutting down
** [out :: staging.absolutecommerce.com]
** [out :: staging.absolutecommerce.com] Unable to open logs
** [out :: staging.absolutecommerce.com]
** [out :: staging.absolutecommerce.com] Action 'start' failed.
** [out :: staging.absolutecommerce.com]
** [out :: staging.absolutecommerce.com] The Apache error log may have more information.
Awesome episode! I was wondering though, how might you handle AND statements for searching on a has_many association? The OR (contains any) is simple enough, just an IN statement. I'm curious how this might handle the other situation.
Testing subdomains in Rails with xip.io
http://www.chrisaitchison.com/2013/03/17/testing-subdomains-in-rails
Covers how to get Capybara to play nice without editing /etc/hosts
If there was a railscast I'd wish it was covered with tests, then this is the one.
This was also useful for ubuntu 12
http://blog.sudobits.com/2013/01/07/how-to-deploy-rails-application-to-vps/
I'm probably missing the obvious, but I'm curious why you would place the JSON inside a tag in the HTML. Why wouldn't a user who is interested in the JSON just append .json to the URL?
Thanks.
It is samey but it demonstrates all the things you need to know about these frameworks.
I'd expect these screencasts to take a lot longer to produce if Ryan had to write new boilerplate for each one.
+1 for an updated railscast
I just took a look at the ASCIIcast and the show notes, it looks like someone has corrected this already.
Excelent article: AngularJS for jQuery Developers
(using ubuntu 12.10)
vim ~/.bashrc # add rbenv to the top vim: command not found
So I used
Ember Data expects the server to respond JSON with errors as the root key, then the attribute name with the errors nested inside of that. You can basically do the following in Rails and Ember will accept it.
This will set 'isError' on that model and will remain at isError (and refuse to commit) until the attributes that the server said had errors are changed.
I have to agree with this. Ryan normally provides an amazing resource in Railscasts, but I find the raffler example too contrived to be useful. Especially for a pro cast.
I'd like to pass a parameter to the datatable.rb... specifically, the @user = User.find(params[:id]). Side note, I'd also like to be able to use current_user in the new class. I haven't tried it, so I'm not sure if that will even work.
Thoughts?
+1
I have an application using devise for my authentication. How do I allow users to NOT have to input their current password every time they want to update their settings?
Is Google charts an option for proprietary data? I have an app that is strictly for internal use.
how can I replace the method find_by_name in rails4? where(:name = 'params[:name]') ?
i have error in session_controller: undefined method `authenticate' =/ anyone help?
+1
ActionView::MissingTemplate: Missing partial exception_notifier/current_user
Any clues?
Prawn is working fine in development but in production, my app is not even opening. When I check production logs I get a looping message
Exactly right. This why, if I "must" use AR in a migration, I prefer to redefine (much simplified) classes within the migration file... ensuring that the AR class definitions match the db schema.
Also, for large datasets, executing SQL rather than instantiating AR records can mean your migration runs in seconds rather than minutes/hours.
Hi guys,
How to refactor link_to_function using UJS since it will be deprecated in Rails 4.
Hi @caiolufer, I am also facing a problem similar to this. Can you let me know how you solved this?
Kobaltz,
Where are you putting the
clause in your script below?
After you test for "An unexpected error..." or before?
I am testing on a legacy machine running XP (so IE 8) and not seeing the error. Should probably try on a machine running IE 10.
I cannot track down what I did (probably upgraded the Stripe API on our account), but as I worked back through my Stripe test logs, about 2 weeks ago each execution of:
Stripe.createToken(card, order.handleStripeResponse)
in my coffee script started generating two tokens at the Stripe end, not one. Don't know if it is related because with FireFox (both XP and Mac) the "An unexpected error has occurred. We have been notified of the problem.", does not generate a token log entry (or 2) in the Stripe log, but :
gets to the .submit() line, presumably because of a status ==200.
With Chrome, the error is there, but the token is in the hidden token field on the form and dismissing the error results in a new order being properly created. With FireFox, there doesn't seem to be anything in the hidden token field and order creation fails (but not by redirecting back to the "submit order" page.
Not sure if this is the most elegant, but this works if you want permission.rb working with Carrierwave.
References:
strong parameter example for hashes with integer keys
strong_parameters#nested-parameters
There's a ton of simple apps he could make. A blog, a forum, a store etc
Exactly what I was looking for! Thanks.
Does anybody know how to use Gon in helper methods?
I had not tried it with different browsers. I'm on IE 10.
I think the order of the routes is important to make this work properly.
resources :products
get ':id', to: 'pages#show', as: :page
resources :pages, except: :show
root to: 'products#index'
I have a version of this that re-uses the form partial and avoids letting you edit fields that require unique values automatically:
https://github.com/spilth/rails-mass-update-test/blob/master/app/form_builders/mass_form_builder.rb
And
https://github.com/spilth/rails-mass-update-test/blob/master/app/views/books/mass_edit.html.erb
Are you seeing the error with all browsers?
I'm getting with Firefox (with subsequent failure to create to new entry--order in my case rather than subscription), Chrome (here the new entry is created...)
And not seeing the error with Safari or IE.
I still read these. :)
Did you resolve your permissions issue?
+1
My 2 cents on Ember after watching this screencast:
- the code after refactoring to extend ArrayController looks actually pretty worse than it was before ( added magic, more lines of code, and bizarre stuff like #each controller ).
- No way in hell am i ever gonna use Ember.js. Weird setters and getters, weird routes that sets controller data, and really a lot of files to do something that looks much simpler in other frameworks. I would prefer going full JS with meteor or another Node framework or Angular.
view_context
is a method onActionController::Metal
(iirc) that builds a new 'view context object.' This is usually an instance ofActionView::Base
, but is override-able. Every time you call it, it generates a new one, because caching is hard, basically.Hi there! I maintain both AMS and Draper, so maybe I can give you some insight. ;)
Draper is about general decoration, AMS is about serializing to JSON. I know several people that use both together: Draper for adding presentation-only concerns, and then AMS to actually do the conversion.
It's arguable that serialization and view-specific logic are two different concerns, and require two different objects.
Also, if you use Draper's
#to_json
, you miss out on the conventions that AMS provides.Rails is built on conventions. AMS is built on conventions. RABL and JBuilder are built on customizing every last detail of the response.
I literally just merged
respond_to
support yesterday, so it wasn't there when he reviewed.Also,
respond_to
isn't all that great, many of us don't actually use it.What do you suggest he builds? I think the point is to just show the basics of working with the technology. I'm happy with samey.
+1
I did it like this
confirm: t("sure")
but in fact my question is more for links like the one below :
Yes, angularjs is great for my contacts app. But ember is better than angularjs for a whole project. Because ember has associations, rails like model, view, router, controller.
USE ANGULAR: If your project has a single model like contact.
USE EMBER: If your project has several models like railcasts.com app.
+1
It works like a charm :) Thank you very much !
Just a question, how can I use I18n in javascript confirmation, for example to delete an item
<%= link_to raw(''), user, confirm: 'Are you sure?', method: :delete %>
Thanks :)
+1 for follow up!!!!!
An alternative is to use the Representer pattern outside of the view context. There are some implementations such as https://github.com/apotonick/representable.
In my last deployment I received this:
[Thu Mar 14 03:34:18 2013] [warn] default VirtualHost overlap on port 8080, the first has precedence
** [out :: staging.absolutecommerce.com]
** [out :: staging.absolutecommerce.com] [Thu Mar 14 03:34:18 2013] [warn] default VirtualHost overlap on port 7001, the first has precedence
** [out :: staging.absolutecommerce.com]
** [out :: staging.absolutecommerce.com] [Thu Mar 14 03:34:18 2013] [warn] default VirtualHost overlap on port 7000, the first has precedence
** [out :: staging.absolutecommerce.com]
** [out :: staging.absolutecommerce.com] [Thu Mar 14 03:34:18 2013] [warn] NameVirtualHost *:8443 has no VirtualHosts
** [out :: staging.absolutecommerce.com]
** out :: staging.absolutecommerce.comAddress already in use: make_sock: could not bind to address 0.0.0.0:7000
** [out :: staging.absolutecommerce.com]
** [out :: staging.absolutecommerce.com] no listening sockets available, shutting down
** [out :: staging.absolutecommerce.com]
** [out :: staging.absolutecommerce.com] Unable to open logs
** [out :: staging.absolutecommerce.com]
** [out :: staging.absolutecommerce.com] Action 'start' failed.
** [out :: staging.absolutecommerce.com]
** [out :: staging.absolutecommerce.com] The Apache error log may have more information.
[
** [out :: staging.absolutecommerce.com]
** [out :: staging.absolutecommerce.com] fail
** [out :: staging.absolutecommerce.com]
** [out :: staging.absolutecommerce.com] ]
Can anybody tell me how to solve the problem?
Awesome episode! I was wondering though, how might you handle AND statements for searching on a has_many association? The OR (contains any) is simple enough, just an IN statement. I'm curious how this might handle the other situation.
recompiling doesn't work for me. what else should I try?
+1