Unless you're explicitly handling particular formats (for example you have a respond_to block in your action that only handles the html format), then Rails will automatically look for a view that matches the incoming requested format. So if you have the following in your controller:
ruby
defnew@post = Post.new
end
And the incoming request format is js, Rails will look for a matching js view to render (ie. new.js.erb). If the request format is html, then Rails will look for a matching html view to render (ie. new.html.erb).
no worries, i was able to fix my problem by changing last two line of code on the route
ruby
match '*path', to: redirect {|params| "/#{I18n.default_locale}/#{params[:path]}"}, constraints: lambda { |req| !req.path.starts_with? "/#{I18n.default_locale}/" }
match '', to: redirect("/#{I18n.default_locale}")
Hi, anybody knows why when i type long urls it redirected to an escaped url?
http://localhost:3000/users/login becomes http://localhost:3000/id/users%2Flogin
the problem That I did the steps but when running service nginx start .....no welcome message ,,just only error message ...I dont know why.?..the steps were working great before installing nginx ...
OK. I do not know much about the newer method. But the following works. It comes right out of Ryan's code on the RailsCasts itself which he has kindly open-sourced here:
The code is not mine, as I pointed out above, it comes from the RailsCasts code. I have tested it and it works as explained above. If this is not what you are looking for, please ignore.
As a gotcha, if you've followed any other of the railscasts on searching (e.g. Search, Sort, Paginate with AJAX remember to remove the private def self.search methods from the controllers!
I agree. I requested an ajax episode hoping that newer methods for binding would be demonstrated. I was also hoping that binding events through the ajax cycle would be covered. I've been trying to bind events to show a spinner user .on and then using the ajax events at the different points in the ajax call life cycle. It seems there's ways to do this with UJS and ways to just do it with jQuery now as well. I was hoping for coverage on that. Disappointed though that at least the new proper ways to do event bindings weren't covered.
So, I now tried everything possible and the only thing that worked was upgrading to Rails 3.1 or newer. So my recommendation for everyone using 3.0.15 or lower would be not to try this Railscast as it seems not to work. The problem must be somewhere with the render command in the link_to_add_fields method.
I am using PDFKit on Mac 10.7 and powify as my local development server. I tried installing the software as described in the cast but am getting the following error when running through my app.
If I run through the command line I can generate pdf's. If anyone has an idea on how to fix this that would be great. I'm really new to rails so a detailed explanation would be helpful.
If you don't need to be able to add new records to the referenced model implicitly then there's a nicer, pure jQuery option that works solely on IDs and does not require you to add accessors to your models: https://gist.github.com/3842296
I am running on windows ,,,and I usually used to deploy to Heroku ,and I want to try linode . I have a question "deploying from different operating system like windows which I am using ,could work ?"
regards
Ryan very timely as always. I was having trouble getting this to work in a legacy project. Same code worked great in a new rails app. But the legacy always resulted in "AccessDenied" response from AWS. Had me perplexed. Hours of tracing and debugging later, realized someone had set the time_zone in our rails config to EDT, and this threw off the expiration key in the policy_data that is sent in the POST request. Hope this might save others hours of tracing.
+1 on vickash explanation, the path you give seems pretty adapted to anyone who already has a running CarrierWave+Fog based app and wants to extend it to take benefit of CORS without too much refactoring.
Thanks a lot to both you and Ryan :).
Like many other commenters have already asked, anyone have a decent pattern they can offer for handling nested resources?
Imagine if this "painting" actually belonged to an "album" resource. I'd like the ability to upload paintings right on the form where I create the album. If the album isn't created until i submit the form, how can I create painting records as they are uploaded?
To accomplish what your looking for, you can use the "force_pass" option in a middleware before the request hits rack-cache: https://gist.github.com/3836818
Nice episode Ryan, one thing, instead of using key.present? you should use: has_image_upload? since calling Painting.new.key will return uploads/<guid>/${filename} resulting in true when you call present?. It's documented in the README here: https://github.com/dwilkie/carrierwave_direct#uploading-from-a-remote-location
My main problem is that my default compiler is clang++ but then I didn't have it install. Once I install that it's fine.
I am not sure you have the same problem though, it seems like you have Javascript runtime environment conflict with therubyracer?
If you have compiler problem like I did, make sure you have clang++ install or change your default system c++ compiler to whatever you have, gcc or g++
I had this problem as well. The issue is that when Devise generates the migration for the users table, it includes a unique index on the email address. So you can't have more than one user with an email address of "", which is what you get when you get more than one non-local-auth user. Devise also sets up the schema so that email defaults to "", rather than null.
Basically, instead of just indexing on the email address, I index on the tuple of email, provider, and uid, since I only plan on allowing one provider per account.
This isn't perfect since it would allow the same email to be used with a Twitter login and a Facebook login, for instance. Not sure what it does to Devise if you change the default for email to null.
Anybody tries to wire oauth though backbone.js?
thx Ryan, so useful for me now.
Has anyone have an template for monitoring Passenger workers? I'm also finding so hard to include pid-file into my.cnf using MySQL. Any ideas?
Thanks all!!
This is excellent - it removes so much of the hassle. Thanks for sharing, I'm definitely going to be using this.
Hi i can't make the charts appearing using twitter bootstrap, is there any aditional task to do to?
Thanks
Unless you're explicitly handling particular formats (for example you have a respond_to block in your action that only handles the html format), then Rails will automatically look for a view that matches the incoming requested format. So if you have the following in your controller:
And the incoming request format is
js
, Rails will look for a matching js view to render (ie. new.js.erb). If the request format ishtml
, then Rails will look for a matching html view to render (ie. new.html.erb).http://guides.rubyonrails.org/layouts_and_rendering.html and http://guides.rubyonrails.org/action_controller_overview.html are good resources for understanding ActionController and ActionView.
I had the same problem. As "Steve Fox" mentioned before, you just have to change:
root /usr/share/nginx/www
to
root /usr/share/nginx/html
in this file:
/etc/nginx/sites-enabled/default
and then restart the server.
no worries, i was able to fix my problem by changing last two line of code on the route
Hi, anybody knows why when i type long urls it redirected to an escaped url?
http://localhost:3000/users/login becomes http://localhost:3000/id/users%2Flogin
the problem That I did the steps but when running service nginx start .....no welcome message ,,just only error message ...I dont know why.?..the steps were working great before installing nginx ...
Check out http://stackoverflow.com/questions/3619361/update-owner-tags-via-form, implementing this functionality in an observer worked for me.
I got weird error. Have any of you experienced it?
InvalidPolicyDocumentInvalid Policy: Invalid JSON.06F63A9785323ECD+kEOXcGMeFmCmcwLDhJKI2xiUViqDMYjbrxwu9+b20mMG+ApNip7yEE0QNxjNuxK
OK. I do not know much about the newer method. But the following works. It comes right out of Ryan's code on the RailsCasts itself which he has kindly open-sourced here:
https://github.com/ryanb/railscasts
In order to show a spinner on a page, you need to first create a div like so:
<div id="spinner" class="spinner">
<img id="img-spinner" src="/assets/spinner.gif" alt="Loading"/>
</div>"
Then in the document ready function, insert the following code:
$(document).ready(function(){
$("#spinner").bind("ajaxSend", function() {
$(this).show();
}).bind("ajaxStop", function() {
$(this).hide();
}).bind("ajaxError", function() {
$(this).hide();
});
});
The code is not mine, as I pointed out above, it comes from the RailsCasts code. I have tested it and it works as explained above. If this is not what you are looking for, please ignore.
Hi Enrico,
first of all thanks for your hints on how to get Bootstrap up and running.
I noticed that in the meantime
rake refinery:override view=layouts/application
works for generating
app/views/layouts/application.html.erb
Best,
Ben.
As a gotcha, if you've followed any other of the railscasts on searching (e.g. Search, Sort, Paginate with AJAX remember to remove the
private def self.search
methods from the controllers!I agree. I requested an ajax episode hoping that newer methods for binding would be demonstrated. I was also hoping that binding events through the ajax cycle would be covered. I've been trying to bind events to show a spinner user .on and then using the ajax events at the different points in the ajax call life cycle. It seems there's ways to do this with UJS and ways to just do it with jQuery now as well. I was hoping for coverage on that. Disappointed though that at least the new proper ways to do event bindings weren't covered.
So, I now tried everything possible and the only thing that worked was upgrading to Rails 3.1 or newer. So my recommendation for everyone using 3.0.15 or lower would be not to try this Railscast as it seems not to work. The problem must be somewhere with the render command in the link_to_add_fields method.
Hello,
I am using PDFKit on Mac 10.7 and powify as my local development server. I tried installing the software as described in the cast but am getting the following error when running through my app.
command failed: "/usr/local/bin/wkhtmltopdf" "--page-size" "Letter" "--margin-top" "0.75in" "--margin-right" "0.75in" "--margin-bottom" "0.75in" "--margin-left" "0.75in" "--encoding" "UTF-8" "--ignore-load-errors" "--quiet" "-" "-"
If I run through the command line I can generate pdf's. If anyone has an idea on how to fix this that would be great. I'm really new to rails so a detailed explanation would be helpful.
Thanks
Eric
If you don't need to be able to add new records to the referenced model implicitly then there's a nicer, pure jQuery option that works solely on IDs and does not require you to add accessors to your models: https://gist.github.com/3842296
Hi Ryan, great episode.. thank you.
I am running on windows ,,,and I usually used to deploy to Heroku ,and I want to try linode . I have a question "deploying from different operating system like windows which I am using ,could work ?"
regards
Ryan very timely as always. I was having trouble getting this to work in a legacy project. Same code worked great in a new rails app. But the legacy always resulted in "AccessDenied" response from AWS. Had me perplexed. Hours of tracing and debugging later, realized someone had set the time_zone in our rails config to EDT, and this threw off the expiration key in the policy_data that is sent in the POST request. Hope this might save others hours of tracing.
+1 on vickash explanation, the path you give seems pretty adapted to anyone who already has a running CarrierWave+Fog based app and wants to extend it to take benefit of CORS without too much refactoring.
Thanks a lot to both you and Ryan :).
+1
Sometimes it is better not to write
Anyone had luck with using jQuery File Upload UI in Rails?
It seems the error is generated by the line has_secure_password
My Gemfile is OK, don't understand :(
Edit : Ok, it works, I installed brypt-ruby before, so I needed to update my bundle and restart my server !
Like many other commenters have already asked, anyone have a decent pattern they can offer for handling nested resources?
Imagine if this "painting" actually belonged to an "album" resource. I'd like the ability to upload paintings right on the form where I create the album. If the album isn't created until i submit the form, how can I create painting records as they are uploaded?
+1
To accomplish what your looking for, you can use the "force_pass" option in a middleware before the request hits rack-cache: https://gist.github.com/3836818
This episode was a catch of a fresh air for me. Now I have a better understanding of rails modularity.
Thank you!
Yeah would definitely love an update
Thanks for mentioning dom_id. I wrote my own helpers for this. I can now go remove code. :)
Got this error on signup
undefined method
key?' for nil:NilClass`Any idea ?
Thanks
Nice episode Ryan, one thing, instead of using
key.present?
you should use:has_image_upload?
since callingPainting.new.key
will returnuploads/<guid>/${filename}
resulting in true when you callpresent?
. It's documented in the README here: https://github.com/dwilkie/carrierwave_direct#uploading-from-a-remote-locationSo, how did you accomplish that?
This is fixed with slim 1.3.2 https://github.com/stonean/slim/issues/301
Bloody hell, that's complicated!
I created a question on SO and problem solved:
http://stackoverflow.com/questions/12720909/therubyracer-install-error-i-tried-all-other-so-solutions-and-still-no-luck/12722230#12722230
My main problem is that my default compiler is clang++ but then I didn't have it install. Once I install that it's fine.
I am not sure you have the same problem though, it seems like you have Javascript runtime environment conflict with therubyracer?
If you have compiler problem like I did, make sure you have clang++ install or change your default system c++ compiler to whatever you have, gcc or g++
I had this problem as well. The issue is that when Devise generates the migration for the users table, it includes a unique index on the email address. So you can't have more than one user with an email address of "", which is what you get when you get more than one non-local-auth user. Devise also sets up the schema so that email defaults to "", rather than null.
I solved it short-term like this:
Basically, instead of just indexing on the email address, I index on the tuple of email, provider, and uid, since I only plan on allowing one provider per account.
This isn't perfect since it would allow the same email to be used with a Twitter login and a Facebook login, for instance. Not sure what it does to Devise if you change the default for email to null.
Does this work well on Rails 3? I doubt it. I changed RAILS_ROOT to Rails.root. But, it doesn't work yet.
Hi,
I've a new question.
Which is the best way to completely remove an apps deployed by capristano.
nginx vhost unicorn_init script,....
Thanx
Does the new action automatically call both the html.erb and js.erb?
So, I tried almost everything I know and still can't get the add_field javascript to work. Barista translates it to the following code:
And Firebug gives me this error:
TypeError: $(this).data("fields") is undefined
I would really appreciate any help or hints.
For some strange reasons i keep getting
the task `unicorn:setup' does not exist
cap unicorn:setup unicorn:stop unicorn:startwhen i type in
I am getting the 'Graph Placeholder not found' aswell, which breaks most of the JS on my site, can we get a solution on this please?
Hi guys,
I see that paper_trail gem uses the Thread.current to pass current_user to model. Is it safe to use it when we use server like puma?
That is an amazingly easy gem to use.
How would you go about allowing file uploads to S3 from an API (e.g. I want to allow users of my site to upload images to my service through our API)?
I'd do an upload via fog but we're using Heroku and the connection times out after 30 seconds.
Excellent episode, hmm but how can I add some ajax to avoid reload the page when someone votes??
joining Ben & Sergioo - tried a bit with a for ... in loop on the parent element, but didn't got it yet.