Just saw that you're using rbenv. I have been thinking of switching from rvm for a while now, but a Railscast on the subject would definitely get me to actually do it. Please do one!
Excellent screencast as usual. I don't seem to be able to find any documentation though on customising the controllers Or models. Mainly things like having the applications associated to a specific user etc.
Great screencast! One question, I keep getting exception notifications for the default_ignore_exceptions, why is this? Has anyone experienced this problem?
This is difficult to grasp when we don't know the big picture. Diagrams are required to introduce the concepts before jumping into code. Also including specs with the code would be helpful.
Awesome Ryan! Great job. I have one question. Let's say your client app is a mobile app (such as an android app), would you have to redirect to a browser (out of the app) when trying to login? The json part is ok as both android and ios have libraries for those.
Yes I have the same issue, although everything is working fine and it does not appear to be affecting anything (to my knowledge). Just an annoying message hopefully...
My linode had to get restarted yesterday and I noticed that while the nginx service started properly, the unicorn socket didn't come back. I wonder how the deployment needs to be tweaked for events where the server has to get restarted. I assume it's a matter of running bundle exec unicorn on server startup.
Ryan, can you make a tutorial for using "TOTP: Time-Based One-Time Password Algorithm" or "Multi-Factor Authentication" that compatible with Google Authenticator like in Google and AWS?? it will be great to add more security :)
Have anyone tried using grape? It's built directly on top of Rack, which would seem to make it quite efficient. I think it also has an interface for oauth authentication.
Alain, to me and in this case, being verbose is a feature, not a bug. Back to your example, I don't think a commentable_id really belongs to the controller. Most of my other comments apply to your code too.
There is also derby, a very similar framework with somewhat different philosophies. A Railscast on that also comparing it to Meteor would be great. From what I read, derby seems to be more flexible and less "lockin" then meteor.
I have to agree that this cast was timed correctly for me as i was looking into something that could benefit from a polymorphic relation.
the other thing which i found useful is this code from stackoverflow, which shows how to set up a has many through polymorphic table
you just saved my day! Thank your for pointing out the //= require_tree . issue. After I put in at the end of the application.js file everything started working.
hi, is there any way to encrypt on the way out / decrypt on the way in? i have sensitive info in my app that i'd like to ensure remains inaccessible to anyone who may connect to my memcache server.
With the "server side solution" you can just pass your extra params through the path helper like this and the autocomplete jquery plugin will append them to the Ajax request:
This autocomplete data source can be put in a separate generic autocomplete action instead of the index action and be introduced to the client through a view helper:
resources :categoriesdo
collection do
get :autocompleteendend
This module about a generic autocomplete action can be included at the top of every resource controller based on a ActiveRecord::Base child class (you have to set the autocomplete route for each controller as shown above):
The association setters could be generated dynamically through meta programming.
So the following code generates special setter methods for all belongs_to and polymorphic associations when included in an ActiveRecord::Base child class.
ruby
moduleAssociationSetter
extend ActiveSupport::Concern
included do
columns.map(&:name).select{|c| c.match('_id')}.each do |column|
association = column.split('_id').first.classify
define_method "#{association.underscore}_name"doself.send(association.underscore).try(:name)
end
accessible_attributes << "#{association.underscore}_name"
define_method "#{association.underscore}_name="do |name|
returnif name.blank?
association_type = association
ifself.class.columns.map(&:name).include?("#{association.underscore}_type")
association_type = self.send("#{association.underscore}_type")
endself.send("#{association.underscore}=", association_type.constantize.find_or_initialize_by_name(name))
endendendend
P.S.: Maybe it turns out to be worth to extract in a gem some day ;-)
Just put :comment_type => :article, or :events, :photo in the routes as a parameter inside of the resources block and then setup a before filter to classify that value (params[:comment_type]).
I'm using delayed_job (Rails 3.1) on Heroku. It seems to stall a lot, and can be tricky to start workers. I'm constantly paranoid that delayed_job may have fallen asleep and jobs are piling up in the queue (this happens pretty often, actually). Anyone know of any good resources for getting delayed_job to work reliably on Heroku? I installed the 'daemons' gem, but I generally just run "heroku rake jobs: work" to get things going again.
I'm sure I'm just doing it wrong, but I can't find too much out there to help me get everything set up to run efficiently.
Products.all when called from LocationsController::Location
=> MONGODB (0ms) db_development['products'].find({:_id=>BSON::ObjectId('4fb93d02c34cb976d5000004')}).limit(-1).sort([[:_id, :asc]])
Products.all when called from Api::V1::LocationsController::Location
=> MONGODB (0ms) db_development['products'].find({:_id=>BSON::ObjectId('4fb93d02c34cb976d5000004'), :_type=>{"$in"=>["Api::V1::ProductsController::Products"]}}).limit(-1).sort([[:_id, :asc]])
How to convert / remove "Api::V1::ProductsController::Products" ?
I think it's a little confusing that you're showing two forms; a user registration form and than two extra steps in a separate form, while really all three steps could go in one form, making it a lot more sustainable.
More important I was wondering how Wicked handles file uploads?
Is there a way this can be implemented where you only define new functionality in new versions? Say for example:
I have a Users controller and a Products controller. Products has stayed the same between V1 and V2, but Users has changed. It would be nice if we could set it up so that if I call for V2 of Products, my application knows it doesn't exist and simply uses the most recent controller version instead (in this case, V1).
InvalidByteSequenceError using pdfkit jruby 1.6.7-2
+1
sorry Dom
period at the last has gone out the link.
plz consider period at the last.
Thank You.
Just saw that you're using rbenv. I have been thinking of switching from rvm for a while now, but a Railscast on the subject would definitely get me to actually do it. Please do one!
feeling the same +1
Right now, there's no way to customize controller behaviour specifically, but there's a branch which will allow you to do this.
There's also a pull request related to application customization (ownership). Feel free to comment on that, we need ideas :)
OAuth 2 is very strange at first sight. It was for me :-)
But, in the OAuth 2 spec site there's few diagrams that might help you, or check out the applications examples, like this one
Excellent screencast as usual. I don't seem to be able to find any documentation though on customising the controllers Or models. Mainly things like having the applications associated to a specific user etc.
Great screencast! One question, I keep getting exception notifications for the default_ignore_exceptions, why is this? Has anyone experienced this problem?
This is difficult to grasp when we don't know the big picture. Diagrams are required to introduce the concepts before jumping into code. Also including specs with the code would be helpful.
This is a great solution.
The gem was updated with the fix for
whitelist_attributes
. Check out the version 0.3.4For this I'd recommend looking into using the password grant type which doesn't require setting a callback URL.
Awesome Ryan! Great job. I have one question. Let's say your client app is a mobile app (such as an android app), would you have to redirect to a browser (out of the app) when trying to login? The json part is ok as both android and ios have libraries for those.
+100 on this episode.
Yes I have the same issue, although everything is working fine and it does not appear to be affecting anything (to my knowledge). Just an annoying message hopefully...
My linode had to get restarted yesterday and I noticed that while the nginx service started properly, the unicorn socket didn't come back. I wonder how the deployment needs to be tweaked for events where the server has to get restarted. I assume it's a matter of running bundle exec unicorn on server startup.
How do you autocomple the "restrict_access". It looked like it cycled through a few options...
Kevin, the last time i checked, AMI for eu-west-1 for Ubuntu 12.04 LTS 64 bit is ami-e1e8d395 and 32 bit is ami-e7e8d393 :)
AMI code for a kind of Image is different in each region, for example:
Ubuntu 12.04 LTS
Singapore:
64 bit: ami-a4ca8df6, 32 bit: ami-a6ca8df4
Northern Virginia:
64 bit: ami-a29943cb, 32 bit: ami-ac9943c5
I got the codes when i try to launch a new instance from AWS console and copy it. But maybe there's a better way to get it :)
Ryan, can you make a tutorial for using "TOTP: Time-Based One-Time Password Algorithm" or "Multi-Factor Authentication" that compatible with Google Authenticator like in Google and AWS?? it will be great to add more security :)
@Bardwin
Your example works very well. Thank you!
How to show a notice like "no record match" when there is no match record according to the input value?
Is it possible to have a progress meeter like the jquery one you linked to?
+1 on Derby. Derby allows you to use the 10k existing NPM modules vs the ~9 meteor only ones.
did you find any good resources ?
I would love to understand this but my ruby skills are lacking. Can anyone point me to some good 1.9.2 resources?
Have anyone tried using grape? It's built directly on top of Rack, which would seem to make it quite efficient. I think it also has an interface for oauth authentication.
Make a generic api controller and inherit from that. Then override whatever you need to in the subclasses.
I don't think that would be good practice. Some questions:
What about route path translation?
Why would you need a parameterized route when you won't be adding new models in runtime? It's just 3 cases, not infinite associations.
Lastly, this could potentially clash with other routes in your
routes.rb
file depending on your routes order.Alain, to me and in this case, being verbose is a feature, not a bug. Back to your example, I don't think a
commentable_id
really belongs to the controller. Most of my other comments apply to your code too.Interesting. However, the date part of the hash will probably leave you open for re-play attacks.
+1
There is also derby, a very similar framework with somewhat different philosophies. A Railscast on that also comparing it to Meteor would be great. From what I read, derby seems to be more flexible and less "lockin" then meteor.
Why not just use a route like this?
Holy crap, why have I not been using this!
thanks a lot for this, was pulling out my hair over it!
I have to agree that this cast was timed correctly for me as i was looking into something that could benefit from a polymorphic relation.
the other thing which i found useful is this code from stackoverflow, which shows how to set up a has many through polymorphic table
It looks like a great way to link locales to items for me
Hey Alan,
you just saved my day! Thank your for pointing out the
//= require_tree .
issue. After I put in at the end of the application.js file everything started working.Thanks again!
hi, is there any way to encrypt on the way out / decrypt on the way in? i have sensitive info in my app that i'd like to ensure remains inaccessible to anyone who may connect to my memcache server.
With the "server side solution" you can just pass your extra params through the path helper like this and the autocomplete jquery plugin will append them to the Ajax request:
_form.html.erb
<%= f.text_field :category_name, data: {autocomplete_source: categories_path(your_extra_param: 'value')} %>
Great screencast. It helped me to DRY this problem a little bit up for SIMPLE model constellations as mentioned in this screencast.
Enclosed you'll just find an untested refactoring version but an older similar refactoring version has been tested successfully ;-)
So I would generally transform all tags with a data-autocomplete-source attribute into an autocomplete input.
application.js.coffee
This autocomplete data source can be put in a separate generic autocomplete action instead of the index action and be introduced to the client through a view helper:
application_helper.erb
_form.html.erb
<%= autocomplete_input(f, :category) %>
routes.rb
This module about a generic autocomplete action can be included at the top of every resource controller based on a ActiveRecord::Base child class (you have to set the autocomplete route for each controller as shown above):
The association setters could be generated dynamically through meta programming.
So the following code generates special setter methods for all belongs_to and polymorphic associations when included in an ActiveRecord::Base child class.
P.S.: Maybe it turns out to be worth to extract in a gem some day ;-)
An update to this railscast to help write better cucumber scripts would be a welcome step forward.
Maybe a silly question but why the jquery-rails gem is not in the assets group?
Just put :comment_type => :article, or :events, :photo in the routes as a parameter inside of the resources block and then setup a before filter to classify that value (params[:comment_type]).
I'm using delayed_job (Rails 3.1) on Heroku. It seems to stall a lot, and can be tricky to start workers. I'm constantly paranoid that delayed_job may have fallen asleep and jobs are piling up in the queue (this happens pretty often, actually). Anyone know of any good resources for getting delayed_job to work reliably on Heroku? I installed the 'daemons' gem, but I generally just run "heroku rake jobs: work" to get things going again.
I'm sure I'm just doing it wrong, but I can't find too much out there to help me get everything set up to run efficiently.
Suggestions?
I went ahead and started a project with meteor then got stuck on a multi-table-join problem.
I documented it here:
https://github.com/meteor/meteor/issues/147
For mainly this reason, I don't think meteor is production ready, but it certainly has some good ideas.
+ 1
I think, I have the same problem as Eran Kampf
How to convert / remove "Api::V1::ProductsController::Products" ?
Adrian: look at the solution I describe above. Way less verbose than yours and more flexible.
I think it's a little confusing that you're showing two forms; a user registration form and than two extra steps in a separate form, while really all three steps could go in one form, making it a lot more sustainable.
More important I was wondering how Wicked handles file uploads?
Is there a way this can be implemented where you only define new functionality in new versions? Say for example:
I have a Users controller and a Products controller. Products has stayed the same between V1 and V2, but Users has changed. It would be nice if we could set it up so that if I call for V2 of Products, my application knows it doesn't exist and simply uses the most recent controller version instead (in this case, V1).