def In Place Editor and Collection Partials

posted_by :Adkron, :on => September 2nd, 2007

I've noticed a lot of individuals have been having problems with the in_place_editor function and using a collection partial. The problem comes down to an in_place_editor looking for an variable beginning with an @. So here is the quick fix.


The partial function:

<%= render :partial => "item", :collection => @items %>


Inside the Partial:

>%@item = item%<
>%= in_place_editor_field :item, 'on_hand' %>

I know it is a bit of a hack, but it is a very quick fix. Happy Coding!

end

def Why Should I 'Test Rails Itself?'

posted_by :Adkron, :on => March 21st, 2007

I was reading Google Groups' Rails Group the other day when I ran into someone talking about why should I test the validates functions. Here is a quote from his email:

For example, what is the point of writing a unit test that simply tests a validate statement in the model? Yes, it's interesting (the first time, at least) that the test works and that, golly-gee, Rails works as advertised, as well, but is there any real use in doing this?
I can imagine a scenario where a I update Rails and suddenly a unit test that tests a Rails validator fails, but I expect the Rails development team would find this before me. Or is that too naive?

I just thought I would post my response for anyone who has the same question. Also, sorry if the format is bad or to quick, but I was trying to hurry when I wrote him the response.

Don't look it as testing Rails. You are testing your model on testing validates. Let's say you write this class:

class Person < ActiveRecord::Base
  validates_length_of :phone_number, :within => 7..10
  ...
end

So you write a test:

def test_phone_number_length_incorrect
  person = Person.new(:phone_number => '123456')
  person.valid?
  assert person.errors.invalid?(:phone_number), 'Invalid Phone Number Coming Back as Valid'
end

I think we would all agree that this test makes sure that a valid phone number passes.

Now not thinking you do a find and replace and replace all 7s with 8s or maybe number with numbers is more likely. So you have:

class Person < ActiveRecord::Base
  validates_length_of :phone_numbers, :within => 7..10
  ...
end

Now you can place :phone_number => '12' into your database because you are now validating :phone_numbers.

If you have a test you run tests after you completed the find and replace, and this error would be caught right away. That is why you 'test Rails.'

end

def Great Way to Learn Ruby (for Programmers) pt. 2

posted_by :Adkron, :on => January 17th, 2007

Bob, one commenter, suggested Ruby Quiz as another great source to help learn Ruby.

Ruby Quiz posts different problems, which I believe are a little harder than Code Golf, but it has one great advantage. After trying the problem yourself you can look at other’s solutions to the problem. this may help you notice different methods that you have not yet thought of, and may help you learn more about syntax, and functions that are not as readily documented. This can also be a great source for code snippets, but remember to give credit where credit is due.

I have used Ruby Quiz in my pursuit of knowledge, but forgot to place it in my first article. Thanks, Bob, for your suggestion.

end

def Great Way to Learn Ruby (for Programmers)

posted_by :Adkron, :on => January 14th, 2007

I have found the perfect way to learn ruby. Code Golf! Now I know those of you out there who know about Code Golf, and about programming are thinking, OMG what is this guy thinking, but bear with me.

I’m not suggesting try to learn to program by sitting down and actually trying to write your code in the smallest number of bytes possible. That just creates unreadable code that is a nightmare to trouble shoot. Just use the functionality of Code Golf to help you.

I have a terrible time just reading a programming book and getting anything out of it. I have to have a project to code. Something small that can be done quickly, and I can learn a little at a time. Code Golf does exactly that for me. Each of their problems gives me something to work on.

The best part is, Code Golf checks my answer. It reminds me a lot of a TA in college, but you don’t have to pay to have them look at your code output. You code, and submit, and there is imediate feedback if your answer doesn’t match the expected output. Granted it doesn’t grade your code, and tell you about coding conventions, but every output must be precise.

May I remind you that you can just output the entire answer, but it won’t do you much good, and if you have no experience with programming this may be a tough way to start.

end

def ImThere.com Mobile/Social Networking in RoR

posted_by :Adkron, :on => November 26th, 2006

ImThere.com

I may be a little biased since I’m on board with Ramped Media, but if your looking for something to do, and love going out you should check out this mobile integrated site.

There are many features that include sending media to and from the site with your mobile phone.

Take a look because in the future you and everyone you know will be saying, “ ImThere!

end

end