RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

Any idea what this error is about?

-- create_table(:participants)
rake aborted!
private method `file' called for #<ActiveRecord::ConnectionAdapters::TableDefinition:0x1a7500c>

Avatar

Whenever I try to view http://localhost:3006/pages.rss I get the error:

No route matches "/pages.rss" with {:method=>:get}

I cannot seem to work out where in my routes this is going wrong?

Also when I map.resources :pages it makes 'show' the default view instead of index!

Help?!

Avatar

Exactly what my app needed. Thanks

Avatar

Hi,

I've implemented OpenID authentification like described in Ryan's tutorial and got a error like this:
NameError in SessionsController#create

uninitialized constant OpenIdAuthentication::OpenID

Can somebody help me?

Greetings,
Jonathan

Avatar

This is an interesting way of doing it - but there is a reason why this should NOT be done as a general way of implementing admin interface.
The reason is should you ever want to update your view (css, html etc) you may break down your site. Thus you will break your admin.
If - on the other hand your admin features are separated (i.e. admin/episodes, thus having a different view) - then you will always be able to alter/admin the site regardless of your view working or not.

Just my 5c

Avatar

@Dan - I'm getting the same problem. I'll post back if I find a fix. Using a HMT really mixes things up!

Avatar

I'm using the technique you presented, but with a :has many :through. I've added the setter method to my model, and its editing fine. But when I add a new, I'm getting a "You cannot call create unless the parent is saved" error.

How do I get my parent object created before the children?

Avatar

Is there any strategy for using this technique with radio buttons? The problem being that instead of having separate "button groups" for each task, you end up with one huge button group for all the radio buttons across tasks, because they all use the same "name" for radio widgets in each task.

Avatar

Hi Ryan, Thx for all your railscasts, they are really great!

Do you have any idea how to build a form tis way for double nested models? For example, a Company has many Offices, and an Office has one address.

I'd like to have a form where you can add a company with one or more associated offices along with the address of each office.

I tried the following, but the attributes of address don't get passed for some reason

<% fields_for "company[office_attributes][]", office do |office_form| %>
<p>
office:<%= office_form.text_field :name %><br />

<% fields_for "company[office_attributes][][address_attributes]", Address.new do |address_form| %>
<%= address_form.text_field :street %>
<% end %>
</p>
<% end %>
<% end %>

any help would be appreciated.

thx in advance!

Ben

Avatar

Your work is amazing valuable. Thank you very much!

Avatar

I'd love to see how validation errors are highlighted in fields that are dynamically added to the form - if you added some task fields and these failedvalidation, when the default view for the form is reloaded (to highlight the errors) the additional fields that were added in the previous step (that failed validation) wouldn't be there...

Avatar

Great screencast, although after installing it i'm getting a "Install the ruby-openid gem to enable OpenID support" error even though the gem is definitely installed. any ideas?

Avatar

I notice that :cache_path removes the name of the host if a string is returned.

Without :cache_path the fragment may be called "localhost:3000/foobar", but if you specify :cache_path => "/foobar", the fragment is written as just "/foobar" without the host which is a big difference.

Using the to_proc technique explained here returning a string is basically the same as using just a string, so you'll lose the hostname in the fragement as well.

So if you depend on the host in the written fragment, you'll have to include the hostname in your string.

Avatar

@ Premek

See http://beast.caboo.se/forums/2/topics/1077

So instead of
  map.resource :session
use rather
  map.resource :session, :controller => 'session'

Avatar

I am using sendmail to allow users visiting my site to send emails. This works fine with my configuration except when the recipients have a yahoo address. Yahoo seems to put my mail into the spam folder. Has anyone else encountered this?

Avatar

First off Ryan thank you so much for all your railscasts. They have been invaluable in my learning process. Now I'm wondering if action caching will work with pagination. I tried a couple of different things but I can't seem to get it to work. I was just wondering before I go to a lot of recoding on my existing blog to add this.

Avatar

As a followup to my previous post, my issue appears to have been a bug, and has been resolved in changeset 8822.

http://dev.rubyonrails.org/changeset/8822

Avatar

I have a plugin called conditional caching that I wrote years ago, and is still maintained.

http://agilewebdevelopment.com/plugins/conditional_caching

Although after seeing this railscast, there are some features (:cache_path) that didn't exist when I first wrote it, so I think I'll be making another update of the plugin soon to make use of it. :)

Avatar

Hey Ryan, I'm wondering if it could have been a little more clever and used string replacement like this:

caches_action :index, :cache_path => Proc.new{ "/products/#{admin?}" }

That would put the cache files as "/products/true" and "/products/false". Granted not the best of names, but what do we care what the cache files are named under the hood? ;-)

Avatar

Got a link to that caching plugin you were talking about?

Avatar

I went through akita's screen cast and realized how powerful resource_controller was but had the sick feeling of how heavy the plugin was, excluding the app that comes bundled! I just found this screen cast and converted a project from r_c to m_r. I am happy with it as a much smaller plugin that hides most of the same work. The only thing I can't figure out is how to override the actual behavior of a rest method for associating objects like comments to posts. Response_for is only concerned with rendering. Where is the hook for the behavior?

Avatar

"Tied plugin to ruby-openid 1.1.4 gem until we can make it compatible with 2.x [DHH]"

14th Feburary 2008

http://dev.rubyonrails.org/changeset/8872

P.S.: Thank you very much for Railscasts!

Avatar

As in the comment from "space" mentioned, it's a bit complicated to build helper method for multiple wrapped tags. I found, that with HAML this task is very simple, because you get the helper methods "open" and "puts".

I have written a blog entry about this:
http://www.dipl-wirt-inf.de/2008/02/17/elegante-block-helper-mit-haml/

(german language, but you will get point with the code examples).

Avatar

Ryan,

I have been using this style of rendering partials since I first watched this screencast, and I really appreciate the abbreviated syntax and the conventions that it encourages. However, I seem to be having some issues passing locals to partials with this method, as in I can't seem to do it at all. I have asked the railsforum, but haven't had any luck and was hoping you might chime in. Thanks! The post is here:

http://railsforum.com/viewtopic.php?id=15301

Avatar

Is it possible to implement the same logic using 3 dynamic menus?

Avatar

I'm curious: what is the best way to limit the number of fields the user can add during both create and update? For instance in my application I'm using this to add picture upload fields, but a user has a max of 9 pictures to they're allowed to upload.

As a side note: Loved these 3 Eps! Thank you so much for taking the time to demo RoR to the masses. Many blessings to you as you work toward your 100th episode!

Avatar

Ryan, thank you very much for your work! It is really enlightening! I actually learned from railscasts more that from awdwr book! Thank you!

By the way, I would like to ask you how you get that nice color output in autotest?

Avatar

for those having the problem of tasks not being saved or deleted on Update. i had the same problem and i just tracked it down (i'm usin Rails 2.0 as well and didn't have to change anything from Ryan's example -- nice work by the way!). anyway, my issue was i inadvertently had a single = sign in the task_attributes method. i had this:

photo = photos.detect { |p| p.id = attributes[:id].to_i }

so an assignment was happening, rather than the correct:

photo = photos.detect { |p| p.id == attributes[:id].to_i }

that fixed my issue.

Avatar

Ryan, thanks for yet another insightful cast. They are even great for brushing up on TextMate tricks. I guess you're typing ^L when typing a hash pair for clarity, however I thought it wouldn't hurt to mention that this can even more easily be achieved by typing a colon followed by pressing 'tab'.

Avatar

Actually it wasn't me that posted the first message :-) Anyway. make_resourceful is a tremendous plugin and it came first. Caitlin definitely has the edge. James Golick used to contribute to this plugin but decided to make his own because of his disagreements with some of the concepts of the original project. Alas, the 'big' block around everything for one.

Now, to me, the biggest benefit of resource_controller over make_resourceful are the view helpers that makes your view set virtually independent of nesting depth. If you're working with polymorphic associations, this is a must have.

Avatar

Oops, my bad. realised i was using an old version of prototype. i used Element.remove(this.parentNode) instead.

cheers!

Avatar

Adam, I have the same problem. Scarce documentation and this cast claim the Foxy Fixtures approach works (with no explicit foreign key column names) - but it does not, at least by default.

I'm having trouble finding any useful information on the problem. is it possible that we need to include some module to the model classes?

Avatar

@Ryan,

I think Hampton rules, HAML is gold and from what I am seeing make_resourceful looks really nice. For my current project I'm using resource_controller, I really like the new scaffolding which is HAML based if you have HAML installed, I also like the fact my controllers are completely empty of code. Farther more RC is really hackable, I managed to write a new base class that gives me base level handling for my xhr calls, (which is not handled by default)

I don't think its a case of one plugin is better than the other, as hampton says: "two different approaches, with different strengths"

As usual, your screencasts are great.

PS. can you make this text area a bit bigger, its hard to type in long comments :)

Avatar

Has anyone did this using an auto complete instead of a select and text box. I was hoping to add the feature where the user would start typing a name, if it was in the list it would add it if not it would create a new one.

Avatar

The use of the instance variable comes down to intelligent choice, really. It seems unlikely that you're going to calculate the total weight, alter the cart, then calculate the weight again within one request. It depends if you're looking for the simplest solution that works in your application or a solution that is perfect in every edge case.

Avatar

Hi Ryan, thanks for the great ideas!

I have a question about the build method (as do many others I see). I can't seem to find any documentation for this method but from what I gather it bubbles up through to the ActiveRecord::Associations package. I understand what build does but could you possibly point me in the right direction for documentation just so I can learn a bit more about it? I'm still a bit of a noob!

Thanks
Tristan

Avatar

This screencast and the before are great.

I just want to share a tip for a small caching challenge that I had.

usually I set the cache directory to "public/cache", but this "break" the caching of dynamic javascripts.

A solution that I found is to redefine @page_cache_directory on javascripts_controller

Check it here: http://pastie.caboo.se/150570
 
Hope it may be useful.

Marcus

Avatar

hey, how about making a download section for all the videos in one place. All these videos are priceless , but a pain to download all one by one :(

Avatar

Or there's the original resources_controller

http://agilewebdevelopment.com/plugins/resources_controller

Avatar

@REST, I wasn't very familiar with resource_controller, but taking another look at it now it looks very good and in some ways looks more powerful and concise than resource_controller. I should have mentioned it in the screencast as an alternative, thanks for pointing it out.

@sintaxi, in some ways I agree with you. Trying to DRY up the controller can often lead to a solution that's too clever for its own good. But at the same time I think it can lead to more concise and readable code as long as you use it properly and understand the conventions. Instead of thinking about it hiding the controller actions, think of it as highlighting the exceptions to the conventions, which is often more important.

Avatar

Hi,

i'm having problems with the remove function. i can add new items, but when i click on the remove, i get a javascript error: $(this).up is not a function.

am i missing something?

thanks for your help.

Avatar

@akita
I follow your blog and watched the last video u made about resource_controller and rails 2.0.
It was very good, but I think it would have been better if u used:

make_resourceful vs resource_controller
haml vs erb

these 2 plugins simplify the development of web apps, please take a look at them and make another great video!!

http://haml.hamptoncatlin.com/
http://mr.hamptoncatlin.com/

BTW
thanks ryan for this great screencast, u r still the leader of screencasts!!!

Avatar

@Matt Hooks: The whole point of make_resourceful is to dry up the default model CRUDS, so if you're doing anything other than that, I'd say typing the SessionsController out by hand would make sense.

Avatar

Any tips on using this with RESTful controllers that do not control their own model (i.e. a sessions controller for User authentication)? Or would you recommend not using m_r in that case?

Avatar

First of all I think this is a beautiful plugin. I feel though that it is perhaps clever to a fault. Thats adding 572k to my project so I *cannot see my controllers? Even if I were to stick completely to the REST convention I would rather run 'scaffold' and move on. That being said I am happy to see people taking REST this seriously.

Avatar

thanks for this episode. It's a great way to cover the RESTful controllers for standard Model access in a nice and dry way.

Avatar

What do you think about resource_controller http://www.akitaonrails.com/2008/1/25/easy-restful-rails-screencast

Avatar

I set up the auth model you described and it worked great. I switched my site to using it in development no problem. Then I went live, which is mongrel w/apache cgi. I can't seem to get the username and password through to rails. Has anyone found a good way to do this. I've gone through a lot of tutorials and guessing with no luck.