RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

I am pretty sure my problem is in that routing thing that is not provided in the code, railscast or the book. Perhaps the version he uses has different defaults for routing or something. Anyhow, I have wasted 5 good coding days on what looked like a good idea, but just won't work for me at all - and the logs give no clues that I can use.

Avatar

Ok, so I bought the book, and keyed in the example except I changed the names of tables to fit my project. It didn't work. I beat around the bushes for a couple of days, but couldn't find my bug.

Then I keyed it in using the exact line for line coding from the bug. Still same problem.

Then I found this page, and downloaded the code.

After adding a named route for projects (the code does not have it - I had to figure this part out), it still doesn't work. I get no errors, just neither my project nor my tasks ever get saved.

Has anyone else actually got any of this to work? I mean I would hate to be completely wasting my time - I could code it the hard way in far less time than I have already wasted here.

Avatar

Am I off my rocker or is any solution that modifies self.site going to be un-thread-safe?

If you have 3 processes accessing 3 different sites (different authentications) then when you modify self.site for any one of them, you're either going to have to lock out other processes until you can "reset" it or you're going to allow each unique process to use a random authentication willy nilly.

Avatar

for those that use capistrano, and had followed this screencast, make sure you DO NOT add the log/*.log and config/database.yml to your .gitignore file.

Capistrano will spit out error messages when you begin to migrate your db.

Learn from me :-)

Avatar

http://railsforum.com/viewtopic.php?pid=68710#p68710

railsforum post of the above question in more detail.

Avatar

Ryan,

Love the episode. One quick question: What is the key-combination in TextMate to do the multi-line block select and replace it with "conditions" where it added that on each line?

I don't even know what you'd call that, otherwise I'd probably be able to figure it out.

Thanks!

Avatar

Thanks for a great railscast, I got it working in a lot less time than I thought.

One issue I'm having, is that it will only display the first 7 posts in firefox but in opera it gets all 11. I have repeated the xml.channel do block to also add additional posts as i have both title and title_japanese etc. All works fine except that in firefox it only show one block (either english or japanese) but not both like opera.

any way to have the feed display all articles? For example Railscasts displays all, not 7, so I'm a little stumped.

Avatar

@ Matthew Higgins (re: StaticMatic) that looks like a great solution for *generating* static pages, but it doesn't look like it deals with the question of how to integrate them into your Rails app.

Of course maybe you didn't mention it because it's too obvious--just put them in /public. I'd love to hear any downsides anyone can see (especially Ryan) to simply keeping static pages in /public, besides the obvious one of them being more of a pain to edit.

The reason I'm asking is I have a large static site to convert to Rails, and it seems that just dropping it into /public is the logical starting point, while I gradually replace static bits with Rails. Any tips tricks and gotchas are welcome!

Avatar

@Ryan: toward the end of the screen cast the tone of your voice made me think that you might be on the verge of mentioning possible *security* problems with using the catch-all route:

map.static 'static/:permalink', :controller => 'pages', :action => 'show'

Is there any possible security vulnerability created by having such a route? I can't think of any, but the degree of concern in your voice at *anything* going through the PagesController seemed to hint at possible security problems.

Or am I on crack?

Avatar

Hi!

Thanks a lot for your great casts!
I'm quite new to rails.

Now I got the following problem, which belongs to this subject:

I will explain it on the Project - Task example.

I have an action called <b>addtask</b>
that action creates a form and the possibility to add one task to this project.

Now that works fine.
Now comes the tricky part:
Every project belongs to a person and in the <b>addtask</b> I can changed that person.
Now I want that to write this person_id in the task tabel. So I now which task is ment for whom.

How can I do that?

I hope you can help me Ryan...

Best regards!
Fjord

Avatar

If you're having troubles with getting HTTP Basic Authentication working with Apache fcgi try adding this to your htaccess file.

RewriteRule ^(.*)$ dispatch.fcgi [E=X-HTTP_AUTHORIZATION:%{HTTP:Authorization},QSA,L]

Avatar

@Nadav: yes, you're right that wysiwyg editors are easier for simple users, but the problem is that they are generally given the ability to do things that they shouldn't be allowed to do, which destroy the look and feel of the site.

Using something like Markdown is a nice way to solve this, making it easy to write semantic markup (indirectly of course, via Markdown's transformation into HTML) and harder to write non-semantic HTML (which you can do if you embed HTML in your Markdown).

And once you get the hang of it, it's much much easier to use than a wysiwyg editor, even though as you point out those are easier at first for simple users.

Avatar

Great stuff!! Thanks.
I think that in more complex cases, it pays to replace the simple view's text filed, with a nice javascript based wysiwyg editor, for example the fantastic FCKeditor (http://www.fckeditor.net/)

This is so much easier for simple users to grasp then RedCloth.

Avatar

Bryan,

appart from the fact that it might be the only one doing what Liquid does... it is to my knowledge the only templating language being used on a site where the users can change their own look and feel using it (which says a lot about how safe it is).

Avatar

Ryan, what about 2 episodes per week? :P

Avatar

Thanks for the cool screencast on Liquid.Will be looking foward for more screencast in liquid especially on how to use common layouts in liquid templates!

Avatar

I can't tell you how much I look forward to every monday. I am subscribing to your pragmatic screencasts, and I get them as soon as they come out as well. Thank you for the discipline and the excellence that you have defined in your work.

Avatar

@leethal, Liquid is pretty old, but AFAIK it's still the best at what it does. If anyone knows of alternatives I'd love to hear.

@Matthijs, they're just words from the filler text "lorem ipsum". I got tired of thinking up good names. ;)

Avatar

Hey Ryan, your product names are a little strange! What happened?

Avatar

Ryan,
I mean find some way to have the route filter ONLY for the permalinks that exist. Dynamically rather then manually making an array of all of the permalinks you want to go though.

Avatar

Ryan,
Great screencast - I've been wrestling with static pages and how to handle them over the past couple of weeks.

One thing though... Is the nifty-generators gem no longer available from github? I've tried the link in the comments above (the same one as in the readme file) "gem install ryanb-nifty-generators --source=http://gems.github.com" and I keep getting this message back "ERROR: could not find ryanb-nifty-generators locally or in a repository" - is it something with github or user error on my end?

Avatar
Matthijs Langenberg on #118 Liquid 2008-07-14 11:11:11

Thanks Ryan, this gives me a head-start for the templating system in a SaaS project.

Avatar

Thanks so much for posting this! I'd been looking for something like it for quite sometime. :) You're a hero.

Avatar

And I was thinking Liquid was all outdated and stuff. Niceness!

Avatar

That's pretty cool.

I actually just happened to need the number_to_currency action.

Thanks.

Avatar

@Nicolás, very good point, and you're correct. The old approach is RESTful, I should have been specific and said the controller isn't a RESTful style.

@Tal, hmm, I'm not sure I follow. Would that database find go in the routes? I don't know of an easy way to do that.

@Allyn, I mentioned :include back in episode 22, but, if it works out, I plan to go into more detail on it in the next Everyday Active Record episode.

@Andy, you can still do versioning through the database with something similar to the acts_as_versioned plugin.

That said, normally static content is just text. You can toss around a text file to all involved until you get it right, and then put it on the site. I'm not sure a staging environment is entirely necessary for such simple content. But, of course it depends on the site requirements.

Avatar

Have you tried Watir? I've been using that for a while now. The API is much better than Selenium. I know that Brett P. is working hard on getting Firefox(Firewatir) compatible with IE Watir Scripts.

Avatar

This is a good plugin to know about.

As the video mentions you should use the plugin only if you have a conventional controller. I rarely have conventional controllers and I'd like to see a video on drying up those.

It wouldn't be a short video as there are many cases to consider, but I expect there are patterns that could be shown. Maybe there should be a book on the subject.

Avatar

Anyone know why the following code defaults to selecting the UTC time zone (instead of the config.time_zone or Time.zone setting):
<code>
<%= f.time_zone_select :time_zone, TimeZone.us_zones %>
</code>

Many thanks,
Chris

Avatar

Something worth checking out is StaticMatic (http://staticmatic.rubyforge.org/). It's good for personal homepages and documentation.

Avatar

Umm, found the solution to the problem above.

Looks like I forgot to remove the ":index => nil" part from the task helper

Avatar

I get the same "can't convert String into Integer" error as John (3 posts above)

Any help would be much appreciated.

Thanks

Avatar

Great episode!
On permalinks: there are a number of plugins to transparently handle pretty urls. My own cotribution (http://code.estadobeta.com/plugins/sluggable_finder) turns any field you want into a valid permalink and overwrites AR.to_param and AR.find so you don't need to change anything in your controllers. It also raises AR::RecordNotFound just like with integer IDs. It also handles UTF8 correctly and uniqueness of permalinks (my reason to write the plugin in the first place). Enough with the plug.

Avatar

this is beautiful. i think i'm going to cry :) thanks for all your help!

Avatar

Andy,

Using some ActiveResource you could also allow the content of your page to be copied from and to an environment using the URL of the resource

Avatar

Sorry, submitted the form before I was finished.

but I cannot seem to figure out how to combine the fields for use with auto-complete. I don't care if I'm searching on "first_name OR last_name OR (first_name AND last_name)" or something similar but it would be nice to use the full name.

Avatar

I'm attempting to use the auto-complete field to match related records that have a first_name and last_name field. In the profile model I've defined a full_name method that pairs the names: "#{self.first_name} #{self.last_name}"

I'm not sure if that is the proper way to accomplish what I need.

I've replaced all instances of name with full_name which is not working.

The virtual attributes in my other model are as follows:

def profile_name
profile.full_name if profile
end

def profile_name=(full_name)
self.profile=Profile.find_by_full_name(full_name) unless full_name.blank?
end

Now I know that the find_by_full_name is not correct,

Avatar

Alright, finally got it working!

http://pastie.org/231954

Cheers

Avatar

My bad, seems as if my test cases didn't take into account the joining issues related to named_scopes. The code doesn't seem to work at all. Might be a start though, I'm going to continue digging :(

Avatar

The previous code example was really bad since I was so excited, hence a better one follows:

http://pastie.org/231945

Please replace the previous example with this one :)

Avatar

Forgot the call itself,

Video.search(["published","newest"]).

You may also want to check if Video responds_to? the method you're sending and if it's allowed (keep an array of allowed methods or something in the class itself)

Avatar

<code>
named_scope :published, {:order => "created_at DESC", :conditions => {:published => true}}
  named_scope :newest, { :order => "created_at DESC" }

def self.search(params)
  params.inject(Video) {|v,val| v.send(val) } == Video.newest.published
end
</code>

Seems to work just as fine, without any need of hacking AR::Base :)

Avatar

@dudzjosh:
params passed like version=0 can be accessed using ENV e.g:
if ENV.include?('version') and ENV['version'].eql?(XXX)

Avatar

This is a very nice approach, but I've a few concerns on about how it would be used with multiple environments.

Say your legal department requests a change to the wording of the Privacy page. You'd probably want to deploy to a staging site first for them to review it before going live. But if you change the page through the admin web interface, then that change isn't versioned, which goes against known best practice.

So you'd probably need to write a migration but a migration containing a page of text (or Textile) doesn't seem very appealing.

I suppose you could create a Rake task that generates a migration automatically though?

Andy

Avatar

The link to 111 above is actually pointing to 108.

Avatar

Many thanks Ryan - you are the man! Excellent stuff. I'll be donating shortly!

Avatar

I don't see where anyone else has mentioned this but
@task_months.keys.sort would just sort the months in alphabetical order. Maybe you need something that looks at the arrays pointed to by the month names and looks at the first element of each array (a time object) to see if its newer or older than the next. Then loop through the resulting array of ordered value sets and lookup the correct index for the section title.

@task_months.values.sort{|a,b| a[0]<=>b[0]}.each{|tval|
 @task_months.index(tval) ...

Avatar

hey guys,

I am trying to do this with a has_many :through relationship.

job, division, job_division

i am unsure whether to use the job_division 'join' table as the model in the js.erb file

Any ideas?

Avatar

The new timezone support is really good, however so far I prefer to write out times in UTC and then to use javascript to substitute the correct time using the timezone set on the client. This of cause requires the clients timezone to be set correctly, but that is usually the case I think.

I prefer this solution for two reasons:

1. No need for the user to set his timezone in the app.

2. People are travelling a lot nowadays. When I'm opening a website while in a different country, I like to see times in local time, not my "home" time.

Maybe it is also possible to first render the page without the times and then using a remote call to pass in the user timezone to the rails app which than renders the correct times using ajax. However, the javascript client site solution is probably faster as it saves the second server request.

Avatar

You can also pass in a params hash into the named scope and use for example params[:newer_than] || 2.weeks.ago for the default parameter. I prefer this solution over using args when having more than one parameter as the named scope call becomes easier to understand and parameter order doesn't matter.