Along the lines of what @Fred said 4 years ago, I've found plenty of explanations on how to setup the models for many-to-many associations, but I have no idea how to setup the corresponding view and controller.
I have been trying to follow along with this example in a rails 3.0.8 site I'm currently working on. I successfully got the feedzirra gem installed and am able to manipulate feeds in the rails irb console. But I can't seem to get the view to render the information stored in the DB.
I'm new to rails, so may not be any fault of the instructions provide here. In fact from the console an attempt at a mock view work as expected:
FeedEntry.update_from_feed(feed)
for entry in FeedEntry.all
puts entry.name
end
runs the db query and delivers the the list of entry names. I have run
FeedEntry.update_from_feed(feed)
from the console and fired up webrick but everything I've tried in the view results in the same sorry condition; nothing to see. Am I missing something about how webrick is working? How the db is called? Any insights will be appreciated.
I found that I still wanted my users to be able to update their username and email address. Because using user.authentications allows a user to be created without a password devise will complain when prompting to change the info as it requires a current_password.
I used this to allow someone that is logged in via an external auth provider to update without entering a password. You could disable the need for the current_password completely if desired.
First time posting... huge fan - I started with episode 1 and have learned a lot along the way. Thank you Ryan!
views/registrations/edit.html.erb
erb
<% if @user.password_required? %>
.... password fields ...
<% end %>
here is my question.
is it possible to give every viewpath custom assets? say i want to create different themes for every shop or every blog in my application. every theme would have different assets (js, css, images) and different layouts and would inherit default behaviour from /views and /public. currently i am using themes_for_rails gem which provides this feature, but a build in solution in rails 3.1 would be great.
I had a query regarding the "undo" link. What will happen if multiple users are performing updates on various products, and some of them starts undoing their updates. Wouldn't the sample app in your demo always undo the last update on the product table, and hence, many users will never be able to really undo?
Yeah, I'm doing that right now, but it seems like it will become tedious when I have a lot of controllers. Also, how would I define a resource, say "Post", where the controller is at controllers/sites/posts_controller.rb ?
I'm trying to store my I18n using redis for example :
locale: en
key: intro.label.title
value: "Hello World"
but my key change to introlabeltitle even my controller log like :
Parameters: {"commit"=>"Submit", "authenticity_token"=>"ZYoK5MMixIz9hiN8keOd9OTkKo6dBYluATYoyQDbmrY=", "utf8"=>"?", "value"=>"Hello World", "locale"=>"en", "key"=>"intro.label.title"}
and inside the redis-cli my key change to "en.intro\x01label\x01title"
What should you do when you have jobs that really should not be done by a web-app server (like resizing images and S3 uploading), but users are waiting for?
So while the backend benefits to be asynchronous, the user is actually waiting for the end-result.
For those experiencing the same issue, just use UPPER before the input and searchable item. So, in the screencast example, it would be 'UPPER(name) LIKE UPPER(?)'
I'm trying to do something similar to the subdomain trick you just showed, but I want to change the controller that's used rather than the view. Is this possible?
I'm making a CMS where a user can create a site and enter their own subdomain. I'd like "/" to point to "public#welcome" if there's no subdomain, but if there is a subdomain, I want it to point to "sites/public#welcome".
Based on the source code provided with this screencast (for the <%= yield(:head) %> in the app/views/layouts/application.html.erb ), update the app/views/snippets/show.html.erb to add:
into the else branch (the one with <pre><%= @snippet.plain_code %></pre>) that displays the plain code when the highlighted version is not available.
If you wan't a progress bar, you certainly would have to use some javascript, and have the worker in charge of the background processing to update some attribute with its progress.
Maybe the answer to this question is too obvious.In the video, when you submit the snippet, the page does not show you the colored code immediately but instead requires a refresh. For actual production site, how do you avoid having to refresh? Is there an easy way to implement a progress bar?
Hi Ryan, great screencast as always.
Another solution would be to use an AMQP server (like RabbitMQ), it's way faster to fetch the queue item as it's not polling but pushing to the subscriber (i.e. worker). It's maybe less light than Redis though, but it does the job as well.
And you are not tied to load the entire Rails environment too.
Thanks a lot and keep up the good work !
A good missing piece of this screencast would be an Ajax hook, so that the page would get automatically updated when the background worker completes it's job. (So one would not need to reload the page manually to see the highlighted snippet).
I know this screencast is focused on Resque and not necessarily Rails best practices, but wouldn't it be more appropriate to have the enqueuing logic to an after_create callback on the Snippet class?
i am already finishing the tutorial. but in the end i can't add a new answer or question by clicking new question or answer. and there is no error. any one can help me?
Does anyone else think the app directory is getting too big to fast? I'm worried things are getting thrown in there. If you're using this technique, plus carrierwave, maybe some caching, presenters, and emails, your app directory would look like this:
Does anyone know how Ryan gets SQL highlighting in the rails console? I have Wirble, but I only have that colorizing returned values (so if I do some_method.to_sql, I see the highlighting, but not when I do something like Model.find_all and Rails 3.1 shows the actual SQL right there in the console).
Anyone know the .irbrc trick here? Muchas gracias!
Hi Ryan, have you ever considered doing a cast about Torquebox? Torquebox supports all Rack-based (J)Ruby frameworks and it comes with job scheduling and asynchronous task scheduling out of the box (no extra installs necessary) Torquebox is the most enterprise-oriented platform I've seen to date.
Is there a way to update a nested form in a partial from the controller with an update page do call?
I build the Keyword form in a partial
Now I call a controller action from an observefield tag.
n.times { campaign.keywords.build}
page.replace_html "form keyword", :partial => "keyword"
If I place the entre form in a partial, the call goes through, however, If I only have the keyword-part in the partial I can
You might want to consider writing tutorials for SmashingMagazine.com or net.tutsplus.com on How to create a rails app that does X. They pay really well when it someone who knows as much about their niche like you do :)
I guess it makes sense to take precautions if the webservice you are using is down.
Is it possible to automatically re-queue the job if it fails because it cannot reach the webservice?
I'm getting /auth/failure?message=invalid_response although, when I inspect request.env['omniauth.auth'] I can see that it has received the auth info correctly?
I found a problem when I try to use uniqueness validation. It requests an ajax request http://localhost:3000/validators/uniqueness?case_sensitive=true&book%5Bname%5D=test but i receive 404 Not Found.
Should I implement this request myself from rails side?
is there any examples of how to test this authentication using functional tests?
Along the lines of what @Fred said 4 years ago, I've found plenty of explanations on how to setup the models for many-to-many associations, but I have no idea how to setup the corresponding view and controller.
Something like http://railscasts.com/episodes/196-nested-model-form-part-1 but for many-to-many relations would be very helpful.
I have been trying to follow along with this example in a rails 3.0.8 site I'm currently working on. I successfully got the feedzirra gem installed and am able to manipulate feeds in the rails irb console. But I can't seem to get the view to render the information stored in the DB.
I'm new to rails, so may not be any fault of the instructions provide here. In fact from the console an attempt at a mock view work as expected:
runs the db query and delivers the the list of entry names. I have run
from the console and fired up webrick but everything I've tried in the view results in the same sorry condition; nothing to see. Am I missing something about how webrick is working? How the db is called? Any insights will be appreciated.
When I go to the resque interface, i don
I found that I still wanted my users to be able to update their username and email address. Because using
user.authentications
allows a user to be created without a password devise will complain when prompting to change the info as it requires acurrent_password
.I used this to allow someone that is logged in via an external auth provider to update without entering a password. You could disable the need for the
current_password
completely if desired.First time posting... huge fan - I started with episode 1 and have learned a lot along the way. Thank you Ryan!
views/registrations/edit.html.erb
user.rb
How would you recommend installing Redis on Ubuntu server?
great screencast as usual.
here is my question.
is it possible to give every viewpath custom assets? say i want to create different themes for every shop or every blog in my application. every theme would have different assets (js, css, images) and different layouts and would inherit default behaviour from /views and /public. currently i am using themes_for_rails gem which provides this feature, but a build in solution in rails 3.1 would be great.
I figured it out:
Thanks for very good introduction to Papertrail.
I had a query regarding the "undo" link. What will happen if multiple users are performing updates on various products, and some of them starts undoing their updates. Wouldn't the sample app in your demo always undo the last update on the product table, and hence, many users will never be able to really undo?
Regards,
Srikanth
Yeah, I'm doing that right now, but it seems like it will become tedious when I have a lot of controllers. Also, how would I define a resource, say "Post", where the controller is at controllers/sites/posts_controller.rb ?
I think I may have found my answer here actually:
http://glacialis.postmodo.com/posts/cname-and-subdomain-routing-in-rails
...about to try it out now.
http://guides.rubyonrails.org/routing.html#specifying-constraints
I'm trying to store my I18n using redis for example :
but my key change to introlabeltitle even my controller log like :
Parameters: {"commit"=>"Submit", "authenticity_token"=>"ZYoK5MMixIz9hiN8keOd9OTkKo6dBYluATYoyQDbmrY=", "utf8"=>"?", "value"=>"Hello World", "locale"=>"en", "key"=>"intro.label.title"}
and inside the redis-cli my key change to "en.intro\x01label\x01title"
here is my initializer :
and my controller
Thank you and sorry for my bad english
What should you do when you have jobs that really should not be done by a web-app server (like resizing images and S3 uploading), but users are waiting for?
So while the backend benefits to be asynchronous, the user is actually waiting for the end-result.
I thought the controller had to have a respond_to block to do the ajax or will it just default to to index.js.erb in this case?
For those experiencing the same issue, just use UPPER before the input and searchable item. So, in the screencast example, it would be 'UPPER(name) LIKE UPPER(?)'
Awesome !
Great screencast!
I'm trying to do something similar to the subdomain trick you just showed, but I want to change the controller that's used rather than the view. Is this possible?
I'm making a CMS where a user can create a site and enter their own subdomain. I'd like "/" to point to "public#welcome" if there's no subdomain, but if there is a subdomain, I want it to point to "sites/public#welcome".
Based on the source code provided with this screencast (for the
<%= yield(:head) %>
in the app/views/layouts/application.html.erb ), update the app/views/snippets/show.html.erb to add:into the else branch (the one with
<pre><%= @snippet.plain_code %></pre>
) that displays the plain code when the highlighted version is not available.If you wan't a progress bar, you certainly would have to use some javascript, and have the worker in charge of the background processing to update some attribute with its progress.
Thanks Ryan!
As usual, this is great!
Maybe the answer to this question is too obvious.In the video, when you submit the snippet, the page does not show you the colored code immediately but instead requires a refresh. For actual production site, how do you avoid having to refresh? Is there an easy way to implement a progress bar?
How easy or difficult would it be to work this into a user account activation/verification email as well as password resets?
Hi Ryan, great screencast as always.
Another solution would be to use an AMQP server (like RabbitMQ), it's way faster to fetch the queue item as it's not polling but pushing to the subscriber (i.e. worker). It's maybe less light than Redis though, but it does the job as well.
And you are not tied to load the entire Rails environment too.
Thanks a lot and keep up the good work !
Is this buildin solution capable to replace and be a real alternative to authetication gems/plugins like authlogic?
A good missing piece of this screencast would be an Ajax hook, so that the page would get automatically updated when the background worker completes it's job. (So one would not need to reload the page manually to see the highlighted snippet).
Best regards,
Ajasja
Love the ep
As I don't use devise and HTTP Basic seems a bit weak for my uses I got the route to be conditional based on CanCan permissions:
http://www.arcath.net/post/Controlling_access_to_Resque_with_CanCan
Love Resque and your screencasts as always.
I know this screencast is focused on Resque and not necessarily Rails best practices, but wouldn't it be more appropriate to have the enqueuing logic to an after_create callback on the Snippet class?
will wait for jquerymobile railscasts!
thanks for the tutorial.
i am already finishing the tutorial. but in the end i can't add a new answer or question by clicking new question or answer. and there is no error. any one can help me?
Another great screencast from you, Ryan. Went through Resque's github Readme, saw the comparison between DJ and it, and got a couple of questions:
For few background jobs each costing a few hours to run, which is preferable, DJ or Resque?
Resque doesn't rely on Activerecord. It should work fine with MongoDB, right?
Does anyone else think the app directory is getting too big to fast? I'm worried things are getting thrown in there. If you're using this technique, plus carrierwave, maybe some caching, presenters, and emails, your app directory would look like this:
assets
controllers
helpers
mailers
views
uploaders
models
sweepers
workers
presenters
Does anyone know how Ryan gets SQL highlighting in the rails console? I have Wirble, but I only have that colorizing returned values (so if I do
some_method.to_sql
, I see the highlighting, but not when I do something likeModel.find_all
and Rails 3.1 shows the actual SQL right there in the console).Anyone know the .irbrc trick here? Muchas gracias!
I've just realized this is an sqlite issue, since on Heroku (Postgre) everything is working properly.
Hi Ryan, have you ever considered doing a cast about Torquebox? Torquebox supports all Rack-based (J)Ruby frameworks and it comes with job scheduling and asynchronous task scheduling out of the box (no extra installs necessary) Torquebox is the most enterprise-oriented platform I've seen to date.
Oops! Fixed. Thanks for reporting.
Is there a way to update a nested form in a partial from the controller with an update page do call?
I build the Keyword form in a partial
Now I call a controller action from an observefield tag.
n.times { campaign.keywords.build}
page.replace_html "form keyword", :partial => "keyword"
If I place the entre form in a partial, the call goes through, however, If I only have the keyword-part in the partial I can
This fork of resque adds some nice features:
Must be me, but lib/tasks/resque.rake has the content of config/initializers/resque_auth.rb.
@Ryan,
Does eventmachine serve the same purpose? And when will you use eventmachine?
Great information :)
Great screencast as always Ryan!
You might want to consider writing tutorials for SmashingMagazine.com or net.tutsplus.com on How to create a rails app that does X. They pay really well when it someone who knows as much about their niche like you do :)
fschwahn, see Resque, how to requeue failed jobs
Ryan, thanks, another clear and well structured episode.
I guess it makes sense to take precautions if the webservice you are using is down.
Is it possible to automatically re-queue the job if it fails because it cannot reach the webservice?
I'd like to use that Redis installation script:
Doesn't work man. I followed your guide from A-Z.
uninitialized constant User::BCrypt
But i have included the gem in the gemfile and also ran the bundle command.
I'm getting
/auth/failure?message=invalid_response
although, when I inspectrequest.env['omniauth.auth']
I can see that it has received the auth info correctly?It seems this very issue was discussed on Github - I've even upgraded to ruby-1.9.2 and am running Rails 3.0.9.
Sadly, no luck!
I liked the article so much, thanks you.
I found a problem when I try to use uniqueness validation. It requests an ajax request http://localhost:3000/validators/uniqueness?case_sensitive=true&book%5Bname%5D=test but i receive 404 Not Found.
Should I implement this request myself from rails side?
Any way to make it work better with UTF-8 characters? If I have "
Any suggestions on how to get UTF-8 characters like "
I found the solution, you must use ilike instead of like, cause heroku database is case sensitive:
I found this at this thread: Link
It worked ok for me, now I'm looking to make this work on my local development brunch.
just use:
I didn't test that, just writing from head but should do the job.
I get the following error:
/Library/Ruby/Gems/1.8/gems/activesupport-3.0.9/lib/active_support/xml_mini/rexml.rb:20:in `parse': uninitialized constant ActiveSupport::XmlMini_REXML::StringIO (NameError)
This error propagates from the "gateway.authorize()" call. Any idea what's wrong with my setup? Thanks.