If you're wishing to have the list return virtual atributes such as full_name rather than a field such as surname of first_name then I found I had to modify the auto_complete_macros_helper.rb file
I modified it so that it sent the method rather than retrieved the field name. I changed line 98 to
@Juergen post 82. I manage to get the autocomplete working nicely with Thinking_Sphinx. Here's my auto-complete-search:
www.crystalpalacelocal.co.uk
If you search for your enzymes this way then you can limit the number of results back but have the most relevant higher up the list depending upon your search weighting factors.
Hope this helps.
Thanks Ryan for the screencast. Yet again I owe you more than one beer for all this.
BDD is fine. But it takes too much time when compared to TDD. Cucumber looks cool. But is there any real value of using it, when you are sure of the requirements? Because, it slows down the process so much.
What if I want to create a Custom class in lib/ and have this class access the concat and capture View helpers. So that I can use this class in my views.
Example:
lib/my_class.rb
class MyClass
def some_method
concat 'something'
end
end
Hi, great tutorial :) love your work ... but it seems i can't get it working.
i have a form i want to submit with ajax but it allways just renders my javascript source. so i added an alert in the 'this.submit' to see if that submit is being used .. and the alert never shows. So i geuss it is never called correctly. When i put an alert in the submitWithAjax it get's called once which is correct and it's the form i need. Any idea what can be wrong ?
I was wondering what the recommended approach is for building an engine where you anticipate that the main application will need to customize and possibly completely override a significant portion of the database schema, models, controllers and views. In other words, perhaps some of the MVC elements are more of a scaffold or skeleton for the main application. For example, suppose the existing application's models and tables collide with those of the engine and in some cases the model associations in the engine may need to be removed. Would it be possible/practical to include rake tasks to copy also the models (and views) up to the main application and undefine/disable them in the engine. Perhaps using a generator instead of a rake task would be preferred? For migrations, I imagine good documentation explaining how to edit the copied files if necessary would suffice.
Hey everyone. I know this is an old screencast, but I wanted to add a little something to it.
My implementation had about 50 checkboxes, which by Ryan's method, caused about 50 database hits (one per checkbox) to see if it should be selected. I refactored this a bit so it only hits the database once and gets the entire list of selected checkboxes, then references that variable as opposed to the database.
Here's my slightly modified version:
http://pastie.org/458065
@pimpmaster (no. 51),
Thanks ever so much for taking the time to post your solution here. I was tearing my hair out as this wouldn't work until I read your suggestion (adding map.js ':controller/:action.:format' to routes.rb).
Cheers buddy.
Hey Ryan,
kompliment, your tips are really great.Good job. But I have for this example a question
Products => Lord Of The Ring
Category => Movies
Sub_categories => DVD
Genre => Fantasy
Can I also use many to many for this example. Or there is something better.
@Dave Reid
You are calling the method month an an object that contains nil class. Try using debugger to find out where your object becomes nil or call debugger conditional.
I'm trying to implement much of this code into an application I'm working on and I get this error:
The error occurred while evaluating nil.month
When I try to place an order... Any thoughts?
@RyanBates Ezra from Engine Yard cites issues with corrupted indices with ferret in production (about a year ago). This was enough for me to stay away from Ferret.
Are there any factories for regular objects? FactoryGirl, Mechanize, ObjectDaddy and Fixjour are great frameworks for ActiveRecord. But sometimes people write code that doesn't use ActiveRecord.
It's worth re-iterating that whenever you write middleware, it's always worth sticking Rack::Lint *on either side of it*, to check you don't inadvertantly break requests and responses.
Essentially, Rack::Lint *is* the Rack spec, so it saves you a lot of reading :)
I forgot to change the development config file (config/environments/development.rb). Here is only needed to change "config.cache_classes = false" to "true".
I dont know why, but I'm not getting the result I was expecting.
I'm doing a project, when I know that the Id for one object is different in each environment. So the only thing I need is to keep the result of a query in a variable, and use it foreve on.
Somewhere read that :command_path should be used instead of :image_magick_path when setting path of imagemagick, as the later will be deprecated. And when using macport's ImageMagick, /opt/local/bin must be used as the value. Something like this:
Paperclip.options[:command_path] = "/opt/local/bin"
@MadDog and andy, this may seem like needless work up front, but it will result in more maintainable and easier to read tests. Just like any refactoring, you may not see the benefits immediately.
Fixtures can quickly get out of hand as the test suite grows. Once you have 20 different records in a fixtures file of varying attributes trying to get each edge case it becomes difficult to maintain. All of the tests are sharing this same data and no single test really uses all of the records at once.
In short, if you build tests which aren't heavily dependent on external data (fixtures) then they will be much more maintainable and easier to read because everything that is important to that test is in one place.
Hi Ryan:
Wonderful episode. I seem to have uncovered a minor glitch. Perhaps it only happens in my app but I wanted to make sure.
Let's say you create a product with a category. Then you try to edit the product and empty the category field and hit 'Submit'. The product will be saved but will still show the previously stored category.
This may be the case for me because I used your nifty_generator scaffold to set things up. Any ideas?
Thanks! I've been using object mother patterns on all my apps for several months now, and although they are slower, the increase in readability and maintenance more than makes up for it.
My favorite object mother gem by far is Fixjour - http://github.com/nakajima/fixjour/tree/master - which I now use pretty much exclusively.
Thanks for great episode! I have a command in my TextMate bundle for generating factory code for a model in the database. It will build attributes with default values from database if present. It's up on github, http://github.com/jnstq/rubyeqp/tree/master. A real time saver.
Hi Ryan,
Thanks so much for the screencast - It was a massive help.
Recently i refactored my db, and changed the relationship between my 'product' and 'category' from has_many to has_many :through, using the second example in your 'two many-to-many' screencast.
I'm now having trouble getting my app top work - wondered if you had any ideas?
I get an "undefined local variable or method `category' for #<product:0x4cdca2c>"
How would you go about sequencing a specific number length? For example, if I need a 7 digit number, how could I specify that the number must have leading zeros?
I'm currently doing:
http://pastie.org/452428
while this works, it certainly isn't ideal. I'd rather have an option such as :length => 7 that would produce: 0000001, 0000002, etc.
Very nice screencast. I knew that there is more to Cucumber. Thanks
@Eric in post 55.
If you're wishing to have the list return virtual atributes such as full_name rather than a field such as surname of first_name then I found I had to modify the auto_complete_macros_helper.rb file
I modified it so that it sent the method rather than retrieved the field name. I changed line 98 to
items = entries.map { |entry| content_tag("li", phrase ? highlight(entry.send(field), phrase) : h(entry.send(field))) }
THis allowed me to access virtual attributes.
@Juergen post 82. I manage to get the autocomplete working nicely with Thinking_Sphinx. Here's my auto-complete-search:
www.crystalpalacelocal.co.uk
If you search for your enzymes this way then you can limit the number of results back but have the most relevant higher up the list depending upon your search weighting factors.
Hope this helps.
Thanks Ryan for the screencast. Yet again I owe you more than one beer for all this.
Couldn't have done it better myself. Awesome job again Ryan! I'm really happy that you're showing people how to use Cucumber!
Hi Ryan!
Awesome screencast!
You clearly showed a lot of advantages of cucumber.
Thanks,
- Florian
Thanks Ryan for this greeeat screencast!
For my new web application, I will definitely use Cucumber, it's just so... amazing and powerful! ;)
*sigh* When I think that I was just starting to enjoy Cucumber, its getting even more awesome... Thanks for the great(est?) cast !
@Ryanb
BDD is fine. But it takes too much time when compared to TDD. Cucumber looks cool. But is there any real value of using it, when you are sure of the requirements? Because, it slows down the process so much.
Thanks,
Madan Kumar Rajan
Thanks Ryan! Another great screencast! I actually get excited to wake up on mondays to see what you've covered!
Really cool! (As a cucumber!)
@ Greg
> Are there any factories for
> regular objects?
What would a "regular object factory" provide that factory_girl or machinist does not?
Oups, forgot a "self." in the Class method definition:
def self.some_method
[...]
What if I want to create a Custom class in lib/ and have this class access the concat and capture View helpers. So that I can use this class in my views.
Example:
lib/my_class.rb
class MyClass
def some_method
concat 'something'
end
end
views/[...]/index.html.erb
[...]
<% MyClass.some_method %>
Thanks.
which textmate theme are you using?
Hi, great tutorial :) love your work ... but it seems i can't get it working.
i have a form i want to submit with ajax but it allways just renders my javascript source. so i added an alert in the 'this.submit' to see if that submit is being used .. and the alert never shows. So i geuss it is never called correctly. When i put an alert in the submitWithAjax it get's called once which is correct and it's the form i need. Any idea what can be wrong ?
greets,
Daan
I was wondering what the recommended approach is for building an engine where you anticipate that the main application will need to customize and possibly completely override a significant portion of the database schema, models, controllers and views. In other words, perhaps some of the MVC elements are more of a scaffold or skeleton for the main application. For example, suppose the existing application's models and tables collide with those of the engine and in some cases the model associations in the engine may need to be removed. Would it be possible/practical to include rake tasks to copy also the models (and views) up to the main application and undefine/disable them in the engine. Perhaps using a generator instead of a rake task would be preferred? For migrations, I imagine good documentation explaining how to edit the copied files if necessary would suffice.
Thanks for the railscast Ryan. Very cool.
Hey everyone. I know this is an old screencast, but I wanted to add a little something to it.
My implementation had about 50 checkboxes, which by Ryan's method, caused about 50 database hits (one per checkbox) to see if it should be selected. I refactored this a bit so it only hits the database once and gets the entire list of selected checkboxes, then references that variable as opposed to the database.
Here's my slightly modified version:
http://pastie.org/458065
Chris
Hi, thanks for the screencast.
The only issue I am having is with the Xpaths.
I would like to test if a page has certain title, this wont't work:
response.should have_xpath("//title{#{my_title}}")
@pimpmaster (no. 51),
Thanks ever so much for taking the time to post your solution here. I was tearing my hair out as this wouldn't work until I read your suggestion (adding map.js ':controller/:action.:format' to routes.rb).
Cheers buddy.
Ryan,
Thanks for the screencast. A couple of things that aren't covered in the screencast
1. Add the following to environment.rb : config.gem "prawn"
2. You may also need to add the following to your controller for the appropriate actions
respond_to do | format |
format.pdf { render :format=>false}
end
Hey Ryan,
kompliment, your tips are really great.Good job. But I have for this example a question
Products => Lord Of The Ring
Category => Movies
Sub_categories => DVD
Genre => Fantasy
Can I also use many to many for this example. Or there is something better.
Hi guys,
For Ajax Pagination visit my blogpost.
http://pulkitonrails.wordpress.com/2009/04/24/ajax-pagination/
@Ryan Bates
When defining a new factory, couldn't you just do this to achieve a random value for fields?
Factory define :user do |f|
f.full_name "Tim Matheson"
f.email "me@timmatheson#{rand(9999)}.com"
end
Wouldn't that do the same thing? Or is it best to stick with the block as it is more reliable?
@Dave Reid
You are calling the method month an an object that contains nil class. Try using debugger to find out where your object becomes nil or call debugger conditional.
if object.nil?
debugger
end
Good luck.
I'm trying to implement much of this code into an application I'm working on and I get this error:
The error occurred while evaluating nil.month
When I try to place an order... Any thoughts?
Hi,
for all windows (Netbeans) developers:
I've written a Module for Netbeans which allows "Syntax Highlighting" and more for .feature files.
So if you are interested in it, you can find it on the Netbeans homepage:
http://plugins.netbeans.org/PluginPortal/faces/PluginDetailPage.jsp?pluginid=17939
or on my homepage:
http://members.chello.at/server/modules.html
@RyanBates Ezra from Engine Yard cites issues with corrupted indices with ferret in production (about a year ago). This was enough for me to stay away from Ferret.
http://www.ruby-forum.com/topic/137629#612225
Are there any factories for regular objects? FactoryGirl, Mechanize, ObjectDaddy and Fixjour are great frameworks for ActiveRecord. But sometimes people write code that doesn't use ActiveRecord.
Great screencast as usual, thanks Ryan.
It's worth re-iterating that whenever you write middleware, it's always worth sticking Rack::Lint *on either side of it*, to check you don't inadvertantly break requests and responses.
Essentially, Rack::Lint *is* the Rack spec, so it saves you a lot of reading :)
how would you call the call_rake method if your rake task was namespaced my:cool:rake:task? Would you still pass the whole path as a symbol?
I already know the solution :)
I forgot to change the development config file (config/environments/development.rb). Here is only needed to change "config.cache_classes = false" to "true".
Ooops! I tried to paste the following on Gist:
@now ||= Time.now # => or also @@now ||= Time.now
I dont know why, but I'm not getting the result I was expecting.
I'm doing a project, when I know that the Id for one object is different in each environment. So the only thing I need is to keep the result of a query in a variable, and use it foreve on.
As a simple example, I tried to do
<script src="http://gist.github.com/99813.js"></script>
and displaying that on the view, and it has everytime different value.
What is my mistake? should I use memcached instead?
Thanks
Somewhere read that :command_path should be used instead of :image_magick_path when setting path of imagemagick, as the later will be deprecated. And when using macport's ImageMagick, /opt/local/bin must be used as the value. Something like this:
Paperclip.options[:command_path] = "/opt/local/bin"
Thanks Ryan for this.
But i think a more better option for test would be machinist.
it is very easy to use.
I have used it in my project.
Thank you so much for this Railscast. It is exactly what I have been searching for!
Anyone know why my request to join the prawn Google group was not approved?
@MadDog and andy, this may seem like needless work up front, but it will result in more maintainable and easier to read tests. Just like any refactoring, you may not see the benefits immediately.
Fixtures can quickly get out of hand as the test suite grows. Once you have 20 different records in a fixtures file of varying attributes trying to get each edge case it becomes difficult to maintain. All of the tests are sharing this same data and no single test really uses all of the records at once.
In short, if you build tests which aren't heavily dependent on external data (fixtures) then they will be much more maintainable and easier to read because everything that is important to that test is in one place.
Great screencast Ryan! You have an uncanny way of touching on topics that are on my mind.. I hope you can't read all of my thoughts! ;D
Ryan, regarding app_config - plz have a look at http://github.com/eugenebolshakov/app_config/tree/master - very useful plugin :)
Hi Ryan:
Wonderful episode. I seem to have uncovered a minor glitch. Perhaps it only happens in my app but I wanted to make sure.
Let's say you create a product with a category. Then you try to edit the product and empty the category field and hit 'Submit'. The product will be saved but will still show the previously stored category.
This may be the case for me because I used your nifty_generator scaffold to set things up. Any ideas?
Thanks! I've been using object mother patterns on all my apps for several months now, and although they are slower, the increase in readability and maintenance more than makes up for it.
My favorite object mother gem by far is Fixjour - http://github.com/nakajima/fixjour/tree/master - which I now use pretty much exclusively.
Thanks Ryan. Good post.
Great screencast. But I am left wondering - why would you want to do this? It looks to me like factory girl is more complicated than using fixtures.
Thanks for great episode! I have a command in my TextMate bundle for generating factory code for a model in the database. It will build attributes with default values from database if present. It's up on github, http://github.com/jnstq/rubyeqp/tree/master. A real time saver.
thanks! thanks! thanks!
Hi Ryan,
Thanks so much for the screencast - It was a massive help.
Recently i refactored my db, and changed the relationship between my 'product' and 'category' from has_many to has_many :through, using the second example in your 'two many-to-many' screencast.
I'm now having trouble getting my app top work - wondered if you had any ideas?
I get an "undefined local variable or method `category' for #<product:0x4cdca2c>"
Thanks a million,
Gonzo
Excellent screencast as usual.
You can use Machinist's or Object Daddy's syntax from within Factory Girl if you like either of those styles better:
http://giantrobots.thoughtbot.com/2009/2/17/factory_girl-1-2-adding-excitement-to-stale-factories
http://dev.thoughtbot.com/factory_girl/classes/Factory/Syntax.html
Is there any special requirement to make metal apps work with Passenger? In my setup Mongrels work Ok but Passenger silently ignores metal apps.
To answer my own question, you can use sprintf to get leading zeros.
http://pastie.org/452449
How would you go about sequencing a specific number length? For example, if I need a 7 digit number, how could I specify that the number must have leading zeros?
I'm currently doing:
http://pastie.org/452428
while this works, it certainly isn't ideal. I'd rather have an option such as :length => 7 that would produce: 0000001, 0000002, etc.