[Rails] Re: How to iterate fixtures
On Apr 30, 11:06 am, Colin Law wrote: > I have fixture data in froglets.yml > > In my functional test I specify fixtures :froglets > > I can then access the individual fixture values by froglets(:froglet1) for > example. > > I want to check the data in my index view so I want to iterate through the > froglets checking that the data is correctly formatted using something of > the form > froglets.each do |froglet| ... > but this does not work as the froglets object appears to be an empty array. > > I realise I can do this by iterating the database records instead but this > does not seem the right way to do it. > > I have googled without success. > > Suggestions will be much appreciated. I understand your skeptism, but eventually looping through the database records *is* the right way: Froglet.find(:all).each do |froglet| # ... end Looping through the fixtures only is not possible. Even though it was, it would be a bad idea since some of the records might have changed, new records might have been added and so on. You should always be sure to use the latest state of the database. :) -- Best regards, David Knorr http://twitter.com/perplect --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Ruby and Terminal - why didn't anyone explain this?
On 21 Apr., 00:42, "wejrow...@gmail.com" wrote: > I'm learning RoR. I've been using PHP for 6 years now. I bought the > new Agile Web Dev With Rails book and it took me about 9 hours to get > the first project going. No where did it, or anywhere else explain > the whole terminal inputs. It just said to open your "shell".. What is > the deal with those, why do I have to use them, and why can't it be > just simple text files like PHP? Well, you do use "simple text files", just like in PHP. The difference between PHP and Rails, though, is that the only thing you need to do in PHP is to download a package like xampp (e.g.) and just put your files in the right directory. In Rails, there is a predefined directory structure, so you'll need to generate Rails projects *in the shell*. And you have to actively start the server *in the shell* to view your application in the browser. Also when you generate models and controllers you go to *the shell* and type the respective commands. As you can see, Rails uses the shell to stop you from repeating yourself and thereby it speeds up your development process. The reason why no one has explained this to you, could be because most Rails developers works in operating systems like Ubuntu (Linux) or Mac OS where the shell/terminal/command line is a completely natural place to be, in contrast to on Windows systems where most things are done via graphical interfaces. I hope you understand, and I also hope you'll come to appreciate the power of the shell. -- Best regards, David Knorr http://twitter.com/perplect --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Any plugin to send email asyncronously in the background
On 20 Apr., 19:02, Ajaya Agrawalla wrote: > We would like to queue our emails and send them outside of the > application using an external SMTP provider. Any plugin out there which > will do this for us? I would like to explore before we go all out & > write our own. > > aj You can also take a look at this episode of Railscasts: http://railscasts.com/episodes/129-custom-daemon Making your own daemon to run in the background is surprisingly easy. -- Best regards, David Knorr http://twitter.com/perplect --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: how to download the source
On 17 Apr., 12:10, Vaibhav Deshpande wrote: > David Knorr wrote: > > On 16 Apr., 18:10, Vaibhav Deshpande > s.net> wrote: > >> How to download the source from rails cast (www.railscasts.com)website, > >> i have seen the will_paginate(episode -51) rails cast but, i unable to > >> download the source coad of that screen cast, plz tell me the method to > >> download or read that coad so that i can understood that coad more > >> efficiently. > >> plz be more specific, > > >> thanks in advance, > >> vaibhavi > > > 1. Go tohttp://github.com/ryanb/railscasts-episodes/tree/master > > 2. Press the "Download" button > > 3. Select format > > 4. Unpack after download > > 5. Browse the sourcecode of episode 51 in the "episode-51" directory. > > > -- > > Best regards, > > David Knorr > >http://twitter.com/rubyguy > > Thanks for the replay > > It contain the episode from 106 to 157 and i want episode no 51 which is > older one i search in its browser but could not find the match plz help > me... Oh, I didn't notice episode 51 wasn't in the repository. You're going to have to copy the code manually from http://railscasts.com/episodes/51 -- Best regards, David Knorr http://twitter.com/rubyguy --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: how to download the source
On 16 Apr., 18:10, Vaibhav Deshpande wrote: > How to download the source from rails cast (www.railscasts.com)website, > i have seen the will_paginate(episode -51) rails cast but, i unable to > download the source coad of that screen cast, plz tell me the method to > download or read that coad so that i can understood that coad more > efficiently. > plz be more specific, > > thanks in advance, > vaibhavi 1. Go to http://github.com/ryanb/railscasts-episodes/tree/master 2. Press the "Download" button 3. Select format 4. Unpack after download 5. Browse the sourcecode of episode 51 in the "episode-51" directory. -- Best regards, David Knorr http://twitter.com/rubyguy --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Return to previous page
On 15 Apr., 17:18, Juan Kinunt wrote: > Is there a 'rails way' to allow easy navigation to the previous page or > should we use parameters and 'ifs'? > I'm talking about, for example, a 'Back' button that links to differente > pages depending the previous page. You can easily make a back button like this: <%= button_to "Back", :back %> button_to will pass the second argument (:back) on to url_for, and as you can see in the documentation (http://api.rubyonrails.org/classes/ ActionView/Helpers/UrlHelper.html#M001564), :back will be translated to request.env["HTTP_REFERER"] or javascript:history.back() if referer is blank. That's it! -- Best regards, David Knorr http://twitter.com/rubyguy --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: RSS Feed parsing problem
On 12 Apr., 22:02, Nick Hoyle wrote: > Nick Hoyle wrote: > > hi thanks for the reply, was much needed. > > > I knew what i was trying to do which was like you say call each of the > > items in the array i just wasnt sure how to do it, and attempted a > > similar type of loop but had no luck. > > > I will look into this and see if i can achieve what i want > > > Thanks alot > > > nick > > just another quick question > > how would i able to output each parsed feed from the array @feeds[] in a > view? You would do something like this: <%- @feeds.each do |feed| -%> <%= feed.channel.title %> <%- end -%> Voila, a list of feed titles. :) -- Best regards, David Knorr http://twitter.com/rubyguy --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: RSS Feed parsing problem
On 12 Apr., 18:59, Nick Hoyle wrote: > I want to parse multiple feeds but i have ran into problems > > Im doing a query on a table which returns rss feed urls stored in an > instance variable called @urls . > > with each of these eed urls i want to parse them like below > > @feeds = SimpleRSS.parse open(@urls.feed_url) > > however this only works when doing a query for first or last and not > find:all. eg: just 1 feed url > > undefined method `feed_url' for # > > any suggestions on what the problem is? ive tried the approach of trying > to put this into a loop but had no luck and are struggling to find a > solution To me the problem is pretty obvious. You are trying to call an undefined method 'feed_url' on an Array. To make this work you should call the method on each of the items in the Array individually. Like this: @feeds = [] @urls.each do |url| @feeds << SimpleRSS.parse open(url.feed_url) end You need to know, that whenever you're asking ActiveRecord for multiple records in the database, they will always come back as an Array with each item representing a record or model. But when you're asking for just a single record (Model.find(:first) or Model.find (:last)) you simply get the record/model back. -- Best regards, David Knorr http://twitter.com/rubyguy --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: setup method in functional tests and instance variables
On 8 Apr., 04:04, Mitchell Gould wrote: > David Knorr wrote: > > On 6 Apr., 17:18, Mitchell Gould > > wrote: > >> ActiveSupport::TestCase > > >> from > > >> ActionController::TestCase > > >> works like a charm. > > >> Why don't they fix this? > > > What do mean when saying "fix this". Did you run the rails:update rake > > task? > > > -- > > Best regards, > > David Knorr. > >http://twitter.com/rubyguy > > I did run rails:update rake. And I updated rails. But even now when I > run script/generate controller someController I have to edit the test > file so that it is changed from ActionController::Testcase to > ActiveSupport::TestCase. > > Should I update something else so I don't have to do this everytime? And > it does this only for the functionals not the unit test skeletons. Did you upgrade to another version of Rails recently? -- Best regards, David Knorr http://twitter.com/rubyguy --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: setup method in functional tests and instance variables
On 6 Apr., 17:18, Mitchell Gould wrote: > Just found the answer > > it's worth noting that R2.0.2 subclasses ActionController::TestCase > for functional tests (i.e. UserControllerTest), not > ActiveSupport::TestCase. You need to explicitly change the skeleton > test files for (user|spec|etc)_controller_test.rb files to subclass > ActiveSupport::TestCase. > > So I had to change the test file skeleton class definition to > > ActiveSupport::TestCase > > from > > ActionController::TestCase > > works like a charm. > > Why don't they fix this? What do mean when saying "fix this". Did you run the rails:update rake task? -- Best regards, David Knorr. http://twitter.com/rubyguy --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Another Database Connectivity
On 6 Apr., 10:51, Saurabh Peshkar wrote: > Hi All, > > I'm trying to connect another database using rails > > I made changes in database.yml file > > I succeed in that but with same table name, > > I'm having two issues regarding that: > > 1) How to connect the specific table of another database (suppose table > name is Arthur and it is in database2, I'm working in database1) > > 2) How to connect database without making changes in database.yml file. > > Any feedback appreciated, > Thanks > Saurabh Given that you have a single model (Person) that you want to retrieve data from a table in another database, you'ld make an initializer that you could call people_connection.rb and put something like this inside: Person.establish_connection( :adapter => "mysql", :host => "localhost", :username => "someuser", :password => "secret", :database => "somedatabase" ) This is covered in the documentation for ActiveRecord::Base: http://api.rubyonrails.org/classes/ActiveRecord/Base.html See the "Connection to multiple databases in different models" section. Remember, Google is your friend, and always check the manual. -- Best regards, David Knorr http://twitter.com/rubyguy --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: setup method in functional tests and instance variables
On 6 Apr., 15:36, Mitchell Gould wrote: > I have the following in my functional test file. > > class UserControllerTest < ActionController::TestCase > fixtures :users > > def setup > @controller = UserController.new > @request = ActionController::TestRequest.new > @response = ActionController::TestResponse.new > @invalid_user = user(:invalid_user) > @valid_user = users(:valid_user) > end > > def test_login_success > @valid_user.screen_name > end > > When I run a test that tries to use the @valid_user variable I get the > following error. > > NoMethodError: You have a nil object when you didn't expect it! > The error occurred while evaluating nil.screen_name > > It seems that this class isn't storing the instance variables in memory. > > Any ideas. > The above should work just fine, given that you have a user fixture named 'valid_user'. Do you see something like this in test/fixtures/ users.yaml? valid_user: screen_name: xyz -- Best regards, David Knorr http://twitter.com/rubyguy > Thanks in advance > > Mitch > -- > Posted viahttp://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: How can I render a partial from other controller?
On 31 Mar., 07:53, Zhao Yi wrote: > I use this code to render a partial: > > <%= render :partial=>'test' %> > > The test is not located in the current controller. How can I point it to > other place? <%= render :partial => 'people/test' %> In this case, the name of the controller is PeopleController. See the documentation for partial rendering: http://api.rubyonrails.org/classes/ActionView/Partials.html -- Best regards, David Knorr http://twitter.com/rubyguy --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Accept POST data from external source?
Duane Morin skrev: > Ok, this is harder than I thought. I've got a hunk of XML coming in > from an entirely external source that I do not control (but another > department in my company does, so it's not like a giant security hole). > I was hoping to just have them POST their data to me, and then I'd read > the raw stream and parse it. > > I'm sure folks know what I ran into -- Invalid Authenticity Token. If I > understand my googling right, I'm getting this because Rails did not > generate the "form" that posted the incoming data (even though there > wasn't one), so it doesn't come with an authentication key. > > Anybody got suggestions on how to get around this? Do I have to work > with the folks generating the XML to do some sort of handshake that gets > them an authenticity token? But then, how would they send it over? > Surely there are other occasions when you might want some non-Rails > source to post a raw data stream to a Rails app? Say for example that you want the create action of PeopleController to accept requests from an external source, then you'ld simply add this line to people_controller.rb: protect_from_forgery :except => :create See the documentation for the protect_from_forgery method: http://api.rubyonrails.org/classes/ActionController/RequestForgeryProtection/ClassMethods.html#M000493 -- Best regards, David Knorr http://twitter.com/rubyguy --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---