That said, would anyone be willing to share opinions on when it's appropriate to use these frameworks (Angular, Backbone, etc.) vs. the traditional Rails/AJAX way of doing things? I image the benefit has to be pretty tremendous to undertake the learning curve but it's not apparent to me.
For example, would building the app the traditional way be suboptimal? And why?
I really appreciate the guidance! I'm allocating my excess capacity toward becoming a better Ruby programmer but would be willing to divert resource toward learning a new .js framework if that's a more prudent direction.
This is perfect. I needed to export some data as CSV, and all the previous go-by's I had seen built the CSV content in the controller. Yucky! This moves it out to the view template where it should be, and frees you up to make the respond_to handler look nice and pretty. Good work!
How could I accomplish this sort of thing with a single model? I want to create several records at once with an "Add Another Record" button, but I'm only using a single model, not nested...
I had this issue. I develop on Windows 7, and certain gems have windows-specific versions. I went into my Gemfile.lock and removed all "x86-mingw32" in the gem version numbers. After commiting the changes and deploying again, it worked.
I also had this problem with postgres and the pg gem.
Hi Ryan,
Thanks for sharing all your free railcasts.
I have a question:-
Since you can intercept the incoming request and process the Ability why not process the rendered page and automatically filter out all the links and actions that would be routed to incoming resources that are protected ?
So let's start by saying Thanks, Ryan, great cast, really helpful and all that jazz.. (I mean it though)
Just one difference I'd like to share that I encountered on a fresh Ubuntu 12.04 VPS installation following the instructions of this screencast. After installing postgres, and adding a project specific user with password, I also had to modify the pg_hba.conf (/etc/postgresql/9.1/main/pg_hba.conf) file to enable the md5 authentication method, so that rails is able to connect to it with user and password specified in database.yml. Details are easily googleable, just wanted to point it out..
Here's a simple multi-rating system for Photos based of Ryan's videocast. It is simple: just pass the value as the params[:type]: vote_photo_path(photo, type: "1"). Aalso using twitter/bootstrap/font_awesome for the vote icons
vote:
Notice the current_user cannot vote on their own photos;
And I included a 'status' attribute for 'Approved' or 'Denied' the display/hide the photo from public viewing.
Automatic Quality Control: Notice the automatic status change to 'Denied' is ONLY after 10 votes and with an average value less than 3.
vote_range:
This is in the application_controller.rb because I use the reputation system on several models: Ads, Photos, Profiles.
defvote@photo = Photo.find(params[:id])
if current_user
if@photo.user_id != current_user.id
value = params[:type]
if vote_range?(value)
@photo.add_or_update_evaluation(:review_photos, value, current_user)
end# if low score on photo - automatically update status to "Denied" to hide from "Public" - @photos = Photo.publicif@photo.reputation_for(:review_photos).to_i < 3 && @photo.evaluations.count >= 10@photo.status = "Denied"@photo.save
endendend
respond_to do |format|
format.html { redirect_to :back, notice:"Thank you for voting" }
format.js
endenddefvote_reset@photo = Photo.find(params[:id])
if@photo.present?
evaluations = @photo.evaluations
evaluations.each do |eval|
eval.destroy
end
reputations = @photo.reputations
reputations.each do |rep|
rep.destroy
end@photo.status = "Approved"@photo.save
end
controllers/application_controller.rb
defvote_range?(value)
value.to_i.between?(-3,10)
end
helper_method :vote_range?defvotable?if user_signed_in?
if add - your - criteria - for example...
if current_user.status == "Approved"trueendendendend
helper_method :votable?
Erwin's solution is a nice one and scales better than mine. However mine is a little bit easier on the fingers as it does not require the --skip-bundle option.
ruby
deftest@generator.gem 'rspec-rails', group: [:test, :development]
at_exit do
generate 'rspec:install'endend
You can work around the issue with running bundle install multiple times with the --skip-bundle-option for the rails-command and calling bundle_command('install') from the leftovers-method:
It isn't the most elegant solution, but it saves a little time by calling bundler only once. It would be nice if you could modify the options-variable in the AppBase-class
i am using :window=>1 for my pagination. by this i'm able to sho only 2 pages i.e. 1,2 when user 1st time see, but i want to show here 1,2,3..... using window =>1.
How can i show 3 page when 1st time user see the page.
defself.current(except = nil)
now = Time.current
result = where(:starts_at.lte => now, :ends_at.gte => now)
result = result.where(:id.nin => except) if except.present?
result
end
lte : less than or equal gte : greater than or equal nin : not in
Good information, but most of these steps are almost hard coded into my brain already. However, I do see where it can be useful for creating templates for certain configurations with twitter-bootstrap, cancan, sorcery/devise, user model, etc. with the most commonly used gems.
Though, usually it only takes a few minutes to do this stuff now.
Didn't know about the appscrolls. Does seem useful.
Ryan uses the rails executable in the episode. It is important to mention that depending on your setup, that probably will call your 3.2.X install of rails. While Rails is in beta and there is no prerelease gem, you need to use bin/rails:
11 months later...the answer to this question is capistrano (as well as some other applications) expects to find a database owned by a user of the same name 'deployer' (read that in the postgres documentation). I'm wondering if you happen to be developing in windows so won't be using agent-forwarding, and I suspect this is the root cause of permissions errors.
A perhaps related problem...I'm getting a permission-denied error when the capistrano task deploy:start/restart attempts to run. Anyone know why? Anyone still read these 11 months later?
anyone have tips on creating a dynamic query with Squeel. for example if i have an array of conditions [[column,operator,value],[column,operator,value]]
How would i iterate over those and dynamically build a query in squeel?
in ultra basic format
ruby
defself.with_conditions(conditions)
where do
conditions.each do |column,operator,value|
(column operator value)
endendend
hey guys. I spent some time rooting around and it's possible to do the same on linux...but it's not elegant.
Here's a post I wrote on how to do it. Or, at least it will point you in the right direction.
Excellent Railscast, as always!
That said, would anyone be willing to share opinions on when it's appropriate to use these frameworks (Angular, Backbone, etc.) vs. the traditional Rails/AJAX way of doing things? I image the benefit has to be pretty tremendous to undertake the learning curve but it's not apparent to me.
For example, would building the app the traditional way be suboptimal? And why?
I really appreciate the guidance! I'm allocating my excess capacity toward becoming a better Ruby programmer but would be willing to divert resource toward learning a new .js framework if that's a more prudent direction.
thanks very nice... I think will take this alternative over Backbonejs ... very nice
Everyone just a note.... In some of the firefox browsers the headers get passed as HTML.
To fix this Ajax issue just respond_with :json, :html
Running "god log mydaemon" only gives me "Please wait..." and nothing shows up. What could that be?
Fantastic jump start (as always); mirrors all the lessons I had to learn myself over the last couple weeks.
I highly recommend https://github.com/tpodom/angularjs-rails-resource, especially the nested_urls branch, as an alternative for synchronizing with rails.
I get the error uninitialized constant Model::Excel. Anyone else have this problem?
Changing jquery-rails version to 2.1.4 seems to have done the trick.
I have this same issue which cropped up when I tried adding the progress bars.
Did you find help for this? I, too, would like to copy the record above to create a new record - like an Excel sheet...
This is perfect. I needed to export some data as CSV, and all the previous go-by's I had seen built the CSV content in the controller. Yucky! This moves it out to the view template where it should be, and frees you up to make the respond_to handler look nice and pretty. Good work!
Has anyone got this working with jQuery 1.9.0?
I did an gem update on jquery-rails and now getting the following error
Uncaught Error: Syntax error, unrecognized expression: ...
Sizzle.error
How could I accomplish this sort of thing with a single model? I want to create several records at once with an "Add Another Record" button, but I'm only using a single model, not nested...
I had this issue. I develop on Windows 7, and certain gems have windows-specific versions. I went into my Gemfile.lock and removed all "x86-mingw32" in the gem version numbers. After commiting the changes and deploying again, it worked.
I also had this problem with postgres and the pg gem.
Answered my own question. Rewrote the unicorn_init.sh file on a Unix machine instead of my usual Windows box.
Did you ever find an answer to this? I'm can't seem to beat this one.
Doesn't work if I use respond_with (db_runtime is always 0 after POST request)
Hi Ryan,
Thanks for sharing all your free railcasts.
I have a question:-
Since you can intercept the incoming request and process the Ability why not process the rendered page and automatically filter out all the links and actions that would be routed to incoming resources that are protected ?
Any suggestions how to do this ?
Best regards ozpoz
So let's start by saying Thanks, Ryan, great cast, really helpful and all that jazz.. (I mean it though)
Just one difference I'd like to share that I encountered on a fresh Ubuntu 12.04 VPS installation following the instructions of this screencast. After installing postgres, and adding a project specific user with password, I also had to modify the pg_hba.conf (/etc/postgresql/9.1/main/pg_hba.conf) file to enable the md5 authentication method, so that rails is able to connect to it with user and password specified in database.yml. Details are easily googleable, just wanted to point it out..
Nice video like the gems i just got some problem. I can't find how to setup urlhandler for sublime text 2 on linux.
Scoping is slightly different in rails 3.2 as shown below:
Essentially,
lambda
is replaced by->
andnamed_scope
byscope
in rails 3.2Here's a simple multi-rating system for Photos based of Ryan's videocast. It is simple: just pass the value as the params[:type]: vote_photo_path(photo, type: "1"). Aalso using twitter/bootstrap/font_awesome for the vote icons
vote:
Notice the current_user cannot vote on their own photos;
And I included a 'status' attribute for 'Approved' or 'Denied' the display/hide the photo from public viewing.
Automatic Quality Control: Notice the automatic status change to 'Denied' is ONLY after 10 votes and with an average value less than 3.
vote_range:
This is in the application_controller.rb because I use the reputation system on several models: Ads, Photos, Profiles.
vote_reset:
This allows for resetting the values.
voteable?:
Allows control of who can vote
I hope this helps
Can you pls elobarate how should i use this
I've used it do have resources like:
/orgaizations/lend-a-hand/needs/pillows
Works nicely.
I've looked into the
at_exit
callback, and thought of this:This way, you have a single method for postprocessing which is called after bundler.
Erwin's solution is a nice one and scales better than mine. However mine is a little bit easier on the fingers as it does not require the
--skip-bundle
option.You can work around the issue with running
bundle install
multiple times with the--skip-bundle
-option for therails
-command and callingbundle_command('install')
from theleftovers
-method:It isn't the most elegant solution, but it saves a little time by calling bundler only once. It would be nice if you could modify the
options
-variable in theAppBase
-classRyan, you could provide the source code before and after the screencast... that would be amazing...
the first source code, so we can follow you
the second source code, so we can check the app actually working
:)
i am using :window=>1 for my pagination. by this i'm able to sho only 2 pages i.e. 1,2 when user 1st time see, but i want to show here 1,2,3..... using window =>1.
How can i show 3 page when 1st time user see the page.
+1 to Pro Screencast
Late response but it can be usefull for someone else.
There's no "LIKE" command for MongoDB, you can perform a search with a regex.
But as always there's already some gem that do the work for you :
For Keyword search : https://github.com/mauriciozaffari/mongoid_search
For FullText search : https://github.com/artsy/mongoid_fulltext
For Mongoid
lte : less than or equal
gte : greater than or equal
nin : not in
I really love the Mongoid syntax.
Last few seconds of this talk appears to be cut off as well.
Good information, but most of these steps are almost hard coded into my brain already. However, I do see where it can be useful for creating templates for certain configurations with twitter-bootstrap, cancan, sorcery/devise, user model, etc. with the most commonly used gems.
Though, usually it only takes a few minutes to do this stuff now.
Didn't know about the appscrolls. Does seem useful.
thanks
Did you get this fixed? I'm having the same issue!
When I install the Rubber gem, I only have access to the config command. I.e. I can't call Vulcanize. See my post on Stack Overflow for a print screen: http://stackoverflow.com/questions/14522051/rails-rubber-gem-no-such-sub-command-vulcanize/14536914#14536914
Does anybody know how to fix this? It sounds like it could fix @kmamit's problem above too.
I think I resolved this by removing the deferred option in config/nginx.conf
server {
listen 80 default deferred;
}
Did you find a solution to this? I'm having the same issue.
Ryan uses the
rails
executable in the episode. It is important to mention that depending on your setup, that probably will call your 3.2.X install of rails. While Rails is in beta and there is no prerelease gem, you need to usebin/rails
:This bit me when I found that
rails s
did not start the server.Years later, this is still very helpful, great ep !
helps me clear my mind a lot, thx Ryan!
I am trying to use RABL with a model structure using inheritance. I fail setting up a matching template.
Maybe you can take a look here.
Thanks for adding this… really nice
The link you posted got me partway there, but I rewrote the cvim file so that it works for both better_error and RailsPanel.
https://gist.github.com/4699980
11 months later...the answer to this question is capistrano (as well as some other applications) expects to find a database owned by a user of the same name 'deployer' (read that in the postgres documentation). I'm wondering if you happen to be developing in windows so won't be using agent-forwarding, and I suspect this is the root cause of permissions errors.
A perhaps related problem...I'm getting a permission-denied error when the capistrano task deploy:start/restart attempts to run. Anyone know why? Anyone still read these 11 months later?
Solved it...
Had to set jQuery to noConflict(), convert the script to jQuery and add it to a javascript file. Dunno why this happens though...
I have a problem with rails notifications described here
http://stackoverflow.com/questions/14665016/rails-activesupport-notifications-wrong-db-runtime-value
Any help?
Thanks :D this help me.
anyone have tips on creating a dynamic query with Squeel. for example if i have an array of conditions [[column,operator,value],[column,operator,value]]
How would i iterate over those and dynamically build a query in squeel?
in ultra basic format