[Rails] erb_variable and migrating old rails app 2.0.2 -- 2.1 --.
Hi, I'm migrating an old rails app from 2.0* to 2.3 and eventually 3. I thought I'd start with 2.1.* so as to progressively fix any issues that cropped up. Unfortunately both 2.1.2 and 2.1.1 fail to run my unit tests and complain with the following message: {:erb_variable==The erb variable will no longer be configurable. Use the concat helper method instead of appending to it directly.} is not a symbol The changelog for 2.1.1 has: Deprecate ActionView::Base.erb_variable. Use the concat helper method instead of appending to it directly. [Jeremy Kemper] 2.1.0 works ok. So it seems that there is something that is trying to use erb in a deprecated way - and presumably it is not in the framework itself but in my rails app and possibly any gems it is loading. Trouble is I'm having no luck wading through the stack trace (rake test:units --trace). Everything in the trace is either the framework itself or 3 other gems: rake, rubygems and deprecated. There is only one reference to my rails app, specifically to the line in my environment.rb file that runs Rails::Initializer.run do |config| ... Anyone have some sage advice on upgrading rails and locating/pinpointing strange issues like the one with erb? Regards, Daniel Bush -- Posted via http://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-t...@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] SOLVED Re: erb_variable and migrating old rails app 2.0.2 -- 2.1 --.
The problem was the version of the deprecated gem I was using and not erb or any of my rails code. Rails 2.1.1+ works find with deprecated-3.0.0. I had an older version which was blowing up in 2.1.1+. Regards, Daniel Bush -- Posted via http://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-t...@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: Polymorphic Associations... confusing. Do I need them?
2009/4/29 Robert Walker rails-mailing-l...@andreas-s.net Daniel Bush wrote: 2009/4/29 Chris Hanks rails-mailing-l...@andreas-s.net has_many :examples, :as = :sections And get: sections for each tutorial, also, to make sure they appear in the right order. Does that make sense? I think single table inheritance might do this, but I'm planning on using examples and questions for a bunch of other things, so I don't think it would work that well. I'm thinking about defining a whole new section model, and using that, but I don't know yet. I must be missing something here, but given that you have separate models [Tutorial, Question, Example] then what's wrong with: I might be missing something too and over-complicating things. The Section model in my previous post has a position attribute and allows Chris to create a tutorial of ordered sections where each section is linked to an Example or Question. I'm not sure how you guarantee that with your version, although maybe with some effort you could. Because the Examples and Questions are has_many Sections, they are also reusable in a future tutorial; it is the sections that are tied specifically to a given tutorial instance. Anyway, it seemed like the Section abstraction was a nice way to show off polymorphic routes. -- Daniel Bush http://blog.web17.com.au http://github.com/danielbush/sifs/tree/master http://github.com/danielbush --~--~-~--~~~---~--~~ 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: Polymorphic Associations... confusing. Do I need them?
2009/4/30 Daniel Bush dlb.id...@gmail.com 2009/4/29 Robert Walker rails-mailing-l...@andreas-s.net Daniel Bush wrote: 2009/4/29 Chris Hanks rails-mailing-l...@andreas-s.net has_many :examples, :as = :sections And get: sections for each tutorial, also, to make sure they appear in the right order. Does that make sense? I think single table inheritance might do this, but I'm planning on using examples and questions for a bunch of other things, so I don't think it would work that well. I'm thinking about defining a whole new section model, and using that, but I don't know yet. I must be missing something here, but given that you have separate models [Tutorial, Question, Example] then what's wrong with: I might be missing something too and over-complicating things. The Section model in my previous post has a position attribute and allows Chris to create a tutorial of ordered sections where each section is linked to an Example or Question. I'm not sure how you guarantee that with your version, although maybe with some effort you could. Because the Examples and Questions are has_many Sections, they are also reusable in a future tutorial; it is the sections that are tied specifically to a given tutorial instance. Anyway, it seemed like the Section abstraction was a nice way to show off polymorphic routes. oh crap, I mean polymorphic associations. The word polymorphic is getting too polymorphic... -- Daniel Bush http://blog.web17.com.au http://github.com/danielbush/sifs/tree/master http://github.com/danielbush --~--~-~--~~~---~--~~ 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: help active record modeling.
2009/4/29 serenobs seren...@gmail.com Hi. I have difficulties to model active record. So please help my trouble. Let's suppose there are nations which have castles at least 1, and there are 3 types of castles. So I will make these tables. NationsTable, CastlesTable have common attributes of 3 types of castle. CastlesATable, CastlesBTable, CastlesCTable each have its unique attributes. Easier to call your tables: 'nations' for 'Nation' model and 'castles' for 'Castle' model ... etc In this case how can I represent this DB to AR? I think class Nation ActiveRecord::Base has_many :castles end class Castle ActiveRecord::Base belongs_to :Nations end Using the naming convention I suggested above you'd say: belongs_to :nation After all, a castle can only belong to one nation at a time right? but I'm not sure of what will be coded to these models. class CastleA ActiveRecord::Base end class CastleB ActiveRecord::Base end class CastleB ActiveRecord::Base end please help me. You could use single table inheritance (STI). 1) all castles are stored in one table ('castles') which has all the required attributes for all types of castles. 2) in app/models you'll have your Castle model and then you'll have a CastleA,B and C models like above but you now inherit from Castle: class CastleA Castle end 3) You include a 'type' field in 'castles' table which is a string and is the same as the class name of the castle. (ie for an A-type it would be 'CastleA') This is a tidy way to handle your castles as everything is in one table. It does mean that not all attributes will be used by a given castle instance if you have specialised attributes; these will probably be null so I don't think the wastage will be much. and second question is when nation deleted, CastleA, CastleB have to be deleted but not for the castleC type. how can I do? I'm never good at this stuff. But you could do it with a callback in your Nation model: class Nation ActiveRecord::Base has_many :castles before_destroy do |nation| Castle.destroy_all nation_id=#{nation.id} and type!='#{CastleC}' end end There's probably a sexier way to do that. -- Daniel Bush http://blog.web17.com.au http://github.com/danielbush/sifs/tree/master http://github.com/danielbush --~--~-~--~~~---~--~~ 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: Polymorphic Associations... confusing. Do I need them?
2009/4/29 Chris Hanks rails-mailing-l...@andreas-s.net Sorry, no, I'm looking for questions and examples to each belong_to one tutorial, and a given tutorial has_many examples and has_many questions. What I'm really looking for is a way to refer to questions and examples together in certain situations. I'm wondering if I can do something like this (crazy fantasy code): class Tutorial ActiveRecord::Base has_many :questions, :as = :sections has_many :examples, :as = :sections end That way, questions and examples could be represented as different sections of a tutorial. Then, when I want to display a table of contents for a tutorial, I could write: % for section in @sections do % %= section.title % % end % And get: (an example title) (a question title) (an example title) (an example title) (a question title) (a question title) (an example title) ... In the order they appear. I'd also need a position attribute on the sections for each tutorial, also, to make sure they appear in the right order. Does that make sense? I think single table inheritance might do this, but I'm planning on using examples and questions for a bunch of other things, so I don't think it would work that well. I'm thinking about defining a whole new section model, and using that, but I don't know yet. You could define a Section model which belongs_to your Tutorial model and has a position attribute so you can determine the order. In your Tutorial model has_many :sections , :order = 'sections.position ASC' You then set up your Example and Question models so that they have a polymorphic has_many association with the Section model. In Section: belongs_to :sectionable , :polymorphic = true In Question or Example: has_many :sections , :as = :sectionable Now you can say: @tutorial.sections.each do |section| section=section.sectionable case section when Example puts section.some_example_method when Question puts section.some_question_method else puts 'what!' end end Has the nice benefit that you can recycle your examples and questions in next year's tutorial if you're lazy :) -- Daniel Bush http://blog.web17.com.au http://github.com/danielbush/sifs/tree/master http://github.com/danielbush --~--~-~--~~~---~--~~ 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: Rails and Sphinx
2009/4/16 fausto fausto.ga...@email.it Hi, i'm currently using ferret+acts_as_ferret for doing some searches in the db (not so big for now, just 40k~ records, but they will be near 2M+ soon). For now ferret it's working quite well, but sometimes i've indexes corrupted (i use it's drb server in production) and i've to rebuild all the indexes, so i've bad indexes, angry users and time spent to make it right. I'm looking at sphinx and it seems the answers to this problems, as it seems that it doesn't have this such of problems. But i've seen that i've to remake indexes everytime (/hour or less).. does it take a lot to rebuild them? Is there anyone who use shpinx in production? Another big question about it is if it's possible to create custom indexes without having the records in the db, You can send an xml docset document to sphinx to build the index; use the xmlpipe2 source type in your conf and have a script that will generate the xml to STDOUT. The docset contains a set of documents with id's (which you might map to the id in a table in your database if you were using it). Each document contains a set of field tags with the information you want to index. I don't know how that squares with large datasets - my app was very small. I use the Riddle client that comes with Thinking Sphinx to talk to searchd. Some of this stuff is documented on the sphinx website somewhere, though piecing it altogether took some effort. -- Daniel Bush http://blog.web17.com.au --~--~-~--~~~---~--~~ 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: export to excel
2009/4/8 Sijo Kg rails-mailing-l...@andreas-s.net Hi I have some data to be exported as well as imported to/from my rails application to Excel.Could anybody please point me some good advise on how to do this..Also expect some good links on the same Thanks in advance Sijo -- Posted via http://www.ruby-forum.com/. The exporting bit came up on the roro list recently. See the last post in the thread. I've just been using csv format and fastercsv myself with some visual basic to help the end user. Often wondered about the xml format of excel as well... http://groups.google.com/group/rails-oceania/browse_thread/thread/9de19f779a944d2a/50438843fd8d4993?hl=en -- Daniel Bush http://blog.web17.com.au http://github.com/danielbush/sifs/tree/master http://github.com/danielbush --~--~-~--~~~---~--~~ 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: What does the ' %s ' mean ?
2009/4/9 Tom Ha rails-mailing-l...@andreas-s.net Hi there, can anyone explain to me how I have to understand the: %s in the following code line: yield :error, There was a problem resending your activation code, please try again or %s., resend_activation_path Whant does it stand for, what does it mean, what does it do? I'm not familiar with that particular bit of code, but I think this relates to the % method for String classes in ruby. See http://www.ruby-doc.org/core/classes/String.html#M000785 . This is ruby's way of doing format control letters and modifiers. If you've programmed in C etc or something like awk, you often use these in print statements (eg printf) to format strings and numbers etc. Whenever I have to look these up I check out the gawk reference - here's one online: http://www.gnu.org/software/gawk/manual/gawk.html#Control-Letters Simple example in ruby: foo%s % bar = foobar foo%05d % 1 = foo1 -- Daniel Bush http://blog.web17.com.au http://github.com/danielbush/sifs/tree/master http://github.com/danielbush --~--~-~--~~~---~--~~ 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: Ajax Rails
2009/4/9 Phlip phlip2...@gmail.com div id=%= post.title % style=display: none; Just make sure that %= post.title % is unique for the page. An id must conform to roughly the same rules as a JavaScript identifier. No leading numbers, no spaces, no funny business. Of course no browser bothers to enforce that, but such rules exist to help us Rails programmers write rigorous code that goes far beyond browser forgiveness. div id=post_%= post.id % style=display: none; Just to complicate things, it was recommended in the past not to use underscores for id and class names because of the css specs. http://devedge-temp.mozilla.org/viewsource/2001/css-underscores/ I don't think it's a problem these days but I started to hyphenate in place of underscoring because I noticed my syntax highlighter didn't like underscores which led me to this whole weird issue. -- Daniel Bush http://blog.web17.com.au http://github.com/danielbush/sifs/tree/master http://github.com/danielbush --~--~-~--~~~---~--~~ 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: Displaying 'ticked' check boxes
2009/4/7 Helen Smith rails-mailing-l...@andreas-s.net I need to display check boxes as 'ticked' in my edit function where there is a corresponding value for them in the database. In my new function a user can select between 1 and 4 tick boxes and I need these ticked check boxes displayed back to them when they go in to the edit function for that database item. Most appreciated if anyone out there can help please? Here's the code from the new function that sets up the database fields from the check boxes - so I just need to display these as 'ticked' in my edit function. tr td nowrapfont size=2 color=#9E0B0EAgreement Type nbsp a href=javascript:openNewWindow(' http://security/transfers/transfer_help.htm'http://security/transfers/transfer_help.htm%27 )img src=http://security/transfers/images/info.jpg; width=10 height=10 border=0/a/td td colspan=2 nowrapfont size=2 input type=checkbox name=transfer[agreement_1] value=YContract nbsp nbsp input type=checkbox name=transfer[agreement_2] value=YData Transfer Agreement nbsp nbsp input type=checkbox name=transfer[agreement_3] value=YData Destruction Agreementnbsp nbsp input type=checkbox name=transfer[agreement_4] value=YNon-Disclosure Agreementnbsp nbsp /td /tr Currently my edit function is as below but I'm missing the bit to get the boxes ticked. tr td nowrapfont size=2 color=#9E0B0EAgreement Type nbsp a href=javascript:openNewWindow(' http://security/transfers/transfer_help.htm'http://security/transfers/transfer_help.htm%27 )img src=http://security/transfers/images/info.jpg; width=10 height=10 border=0/a/td td colspan=2 nowrapfont size=2 input type=checkbox name=transfer[agreement_1] value=value=%= @transfers.agreement_1 if @transfers.agreement_1 %Contract nbsp nbsp input type=checkbox name=transfer[agreement_2] value=value=%= @transfers.agreement_2 %Data Transfer Agreement nbsp nbsp input type=checkbox name=transfer[agreement_3] value=value=%= @transfers.agreement_3 %Data Destruction Agreementnbsp nbsp input type=checkbox name=transfer[agreement_4] value=value=%= @transfers.agreement_4%Non-Disclosure Agreementnbsp nbsp /td /tr -- Hi Helen, Had a bit of trouble reading the last section. To check a checkbox, you have to say: input type=checkbox ... checked=checked / The value attribute can be whatever you set it, but maybe use the rails default which is 0 and 1 for not-ticked and ticked respectively. Bear in mind that the html spec says that if you don't tick the box, it won't get sent back to the server so other things being equal, your server won't get to see 0. You should read http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html as a starting point for what rails can do to help you build forms and in particular check out the 'check_box' function which employs a little hack to get round the html spec so that you do see '0'. Ideally, you want something a little like this: % form_for :transfer do |f| % ... %= f.checkbox 'agreement_1' % ... % end % I'm assuming you have a @transfer model or object which is created in your controller action with an 'agreement_1' method that returns a boolean or something like that. You can of course create the checkbox manually, but you'll need to write code to test the boolean and insert the checked attribute/value pair into your tag: % checked=i checked = %{checked=checked} if agreement_1 % input ... %=checked% / -- Daniel Bush http://blog.web17.com.au http://github.com/danielbush/sifs/tree/master http://github.com/danielbush --~--~-~--~~~---~--~~ 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: Difference in minutes betwen two Datetime
On Dec 5, 10:02 pm, Günther Lackner [EMAIL PROTECTED] wrote: Hi! I need to calculate the difference between two Datetime and convert it into minutes. diff = Time.now() - my_date How can I convert diff now into minutes? What class is my_date ? (my_date.class) Is it DateTime, or is TIme or ActiveSupport::TimeWithZone ? In general, the difference seems to be in seconds when you subtract two objects of the same class so you'd divide by 60 to get minutes. I think you can also subtract between Time and TimeWithZone but you may run into trouble with other combinations. -- Daniel Bush --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: search implimentation for tags
Hi, I think you have several issues... srikanth wrote: hi, i am implementing a search box from index page,search box allow s the tag name to be searched and it should display the results on the other page. if enter a tag name in search box once i press the search button i am getting error like: ActiveRecord::RecordNotFound in StreamsController#show Couldn't find Stream with ID=search RAILS_ROOT: E:/srikanth/InstantRails-2.0-win/rails_apps/stdb Application Trace | Framework Trace | Full Trace E:/srikanth/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.0.2/lib/active_record/base.rb:1267:in `find_one' E:/srikanth/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.0.2/lib/active_record/base.rb:1250:in `find_from_ids' E:/srikanth/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.0.2/lib/active_record/base.rb:504:in `find' app/controllers/streams_controller.rb:16:in `show' This appears to be a 'show' action - not 'search'. I'd say that your GET-request for /streams/search?search=... is being mapped to your 'show' action - see last comment below. corresonding url have like: http://localhost:3000/streams/search?search=352x240 so can any one help me out in this issue. 1)in controller added search method like: added for search option def search search_criteria = Article.find_tagged_with(params[:search]) if search_criteria.empty? flash[:notice] = Please enter search criteria @searchresults = else @searchresults = Streams.find (:all, :conditions=search_critera) Even though the error was in 'show', there look to be some errors here in 'search'. I think Article.find_tagged_with will return an array of Article models. You haven't mentioned your Article model - you seem to have a Stream model (which you should use in the singular not plural). So maybe you mean Stream. You then use this for the :conditions clause in Streams.find(...) which is probably not going to work because :conditions corresponds to a WHERE-clause in sql. Check the docs for the 'find' method (api.rubyonrails.org). end respond_to do |format| format.html # show.html.erb format.xml { render :xml = @stream } end end 2)and in view/streams/index.html.erb file % form_tag(search_streams_path(), :method = :get) do % %= label(:search, :tag, Search:) %br / input name=search id=tag type=text size=17 value='%= session[:search_keys] %' style=width:123px; / input type=image id=bt_zoek src=/images/search.jpg alt=search style=border:none;/ % end % 3)in routes.rb added line; map.resources :streams, :collection = {:search=:get} Just a guess: but did you add ':collection' to map.resources :streams after setting up this resource? If you did and you didn't reload the routing table (restart you app), then the search action won't take effect and your show action might be used instead which might be why you get the error in 'show' with id being mapped to 'search'. HTH -- Daniel Bush --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: You have a nil object when you didn't expect it!
On Nov 27, 7:11 pm, Joe Smith [EMAIL PROTECTED] wrote: I got it working, thanks for your help -- Posted viahttp://www.ruby-forum.com/. You can name your files like: shopping_cart_item.rb but define the class inside as 'ShoppingCartItem'. Similarly for shopping_cart.rb and class ShoppingCart. Glad it helped. -- Daniel Bush --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: creating array of hashes
Hi - see below... hema gonaboina wrote: ... I need to have the array of hashes as [{employee_record1},{employee_record2}.. n records] For this i tried as the... result = [] for employee in Employees res = {} for field in fields You used 'Fields' above instead of 'fields' here. res { field = employee.send(field)} res[field] = employee.send(field) 'res' is a hash. You build it by setting key/value pairs not pushing onto a sequential array. That should probably do it. Some other things that might be of interest: employee.attributes will give you a hash of all the fields and their values for an employee object but you might only be wanting a subset. (You could 'delete' them.) Employee.column_names will give you an array of all the column names. end result res end But it is not working... Finally i have to replace the 'result' with the PDF::SimpleTable.data through the statement = table.data.replace result which accepts only the hashes... whose columns are the keys and the column data as values Please Help me Thank You -- Daniel Bush --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: You have a nil object when you didn't expect it!
On Nov 27, 4:24 pm, Joe Smith [EMAIL PROTECTED] wrote: Here's what I now have, not sure where to go from here: NameError in Shoppingcart#my_shopping_cart Showing app/views/shoppingcart/my_shopping_cart.rhtml where line #24 raised: undefined local variable or method `shopping_cart_item' for Shopping_cart:Class Extracted source (around line #24): 21: td valign=top width=50%/bTraded items: /bbr 22: table 23: % if @my_cart 24: for shopping_cart_item in @my_cart.shopping_cart_items % 25: tr 26: t -- What does your Shopping_cart class look like? How is shopping_cart_items defined? -- Daniel Bush --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Models, find not from database??? really need help :(
On Nov 17, 7:37 pm, abusiek [EMAIL PROTECTED] wrote: On Nov 17, 8:43 am, Daniel Bush [EMAIL PROTECTED] wrote: On Nov 17, 5:45 pm, abusiek [EMAIL PROTECTED] wrote: Hi! I'm struggling with this for a while and i'm new to rails so it's quite frustrating ;) I need to create new model object based on old one with only few changes. I have desings - has many - lines - has_many - fields I've got input from user in array like this: field =[ line_id =[ fiel_id = field_value] ] so I iterate: input[:field].each do |line_id, line| line.each do |field_id, field_value| design.lines.find(line_id).fields.find(field_id).value = field_value design.lines.find(line_id).fields.find(field_id).something = field_value end end You're finding stuff and assigning new values to what was found but not saving these changes back to the db as far as I can tell here. Retrieve the field once field=design.lines.find(line_id).fields.find(field_id) update its values and then save it field.something = ... field.save (or field.save!) You're not creating anything new, just updating old. If you want a new field, you'll need to create it: design.lines.find(line_id).fields.push(Field.new({hash-of- attributes})) This will add a new field to design's line with line_id. You could probably do something like new_field=Field.new(field.attributes) to create a new field with the same attributes as the existing 'field', alter its values as required and then push it onto the fields collection: design.lines.find(line_id).fields.push(Field.new(new_field)) Be careful with names like 'field' - I don't know if they'll clash with rails names. Maybe also consider not chaining all those 'finds' together in one line. Find each thing and store it in a local variable or an instance variable so you won't have to get it again during the action. -- Daniel Bush I followed your suggestion and write this code: 1 new_design = Design.new design.attributes There's actually a 'clone' method which is probably better than what I suggested before. new_design = design.clone But don't forget that you'll need to save it at some point. 2 design.background.colour_id = 123 3 new_design.background = Background.new design.background.attributes 4 lines = design.lines 5 for line in lines 6 new_line = Line.new line.attributes 7 fields = line.fields 8 for field in fields 9 field.value = input_data[:field][line.id][field.id] 10 new_field = Field.new field.attributes 11 new_line.fields.push(new_field) 12 end 13 new_design.lines.push(new_line) 14 end and now I'v got error that i have nil object in line 5, 8, 9 so it' seems that rails think's design has no lines. I'm guessing it's line 9 and it has something to do with input_data [:field] or input_data[:field][line.id] that's returning nil. 5 and 8 are just part of the looping which means there are lines and each line does have fields. You could compress your code a little eg design.lines.each do |line| new_line = line.clone ... line.fields.each do |field| ... end end I didn't mean to break everything up into separate assignments; whatever you think is best. -- Daniel Bush --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: can't convert String into Integer error on updating
Hi, Just a guess... On Nov 17, 7:57 pm, Raji Mani [EMAIL PROTECTED] wrote: % form_for (:contact,:url={:controller='contact',:action = 'update',:id = @contact},:html= {:onSubmit = 'return validate()', :id = 'savecontact'} ) do -% . . . . table cellpadding=4 cellspacing=0 border=1 width=100% class=details tr th colspan=4 align=left bgcolor=#797ba8strongfont color=fEmail Addresses/font/strong/th /tr tr % for email in @contact.emails % % fields_for contact[email_attributes][], email do |e| % So this will generate params[:contact][:email_attributes][email_id][email_field] = field value in form Each element in this params is a hash. Check your server logs to verify that that is what you're getting. td nowrap class=formLabelEmail /td td %= e.select ('email_type',%w{Business Personal}, :include_blank = false) % %= e.text_field :email,:size=35,:maxlength=80 % %= e.radio_button ('isprimary', '1') %Primary /td /tr % end % % end %/table . . is my view page and here is my update function in contact_cotroller.rb def update @contact = Contact.find(params[:id]) if @contact.update_attributes!(params[:contact]) flash[:notice] = The contact has been updated successfully. redirect_to :action = 'view', :id = @contact else render :action = 'edit' end end is throwing the following error can't convert String into Integer RAILS_ROOT: E:/ruby1/Ruby/BCMS Application Trace | Framework Trace | Full Trace app/models/contact.rb:11:in `[]' app/models/contact.rb:11:in `email_attributes=' app/models/contact.rb:10:in `each' app/models/contact.rb:10:in `email_attributes=' app/controllers/contact_controller.rb:59:in `update Where am i going wrong..?? and my contact.rb is class Contact ActiveRecord::Base belongs_to :company, :counter_cache = false has_many :users has_many :addresses has_many :emails has_many :phones validates_presence_of :namefirst, :namelast,:message='Database Validation Error from Contact' def email_attributes=(email_attributes) email_attributes.each do |attributes| email_attributes is a hash with keys being email id's pointing to email attributes. See previous note above. When you do email_attributes.each |attributes| , 'attributes' will be an array with the first value being the key and the 2nd element being the value. emails.build(attributes) unless attributes[email].empty? Calling attributes[email] would trigger the above conversion error because arrays expect numeric indexes. end end Also, I noticed you're saying :id = @contact . I would have though @contact.id but might be missing something. -- Daniel Bush --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Strange behaviour
On Nov 18, 1:19 am, sigvei [EMAIL PROTECTED] wrote: On 17 Nov, 14:38, Daniel Bush [EMAIL PROTECTED] wrote: On Nov 17, 11:56 pm, sigvei [EMAIL PROTECTED] wrote: I have the following relationships: Document :has_many Proposals :has_many ProposalVersions. This fails: Document.first.proposals.first.proposal_versions.size Do you mean Document.find(:first)... ? ActiveRecord::Base::first is a convenience wrapper for ActiveRecord::Base::find(:first), according to the API. So I can't quite see why that should make a difference. Sorry. Wasn't familiar with it. Hard to imagine rails putting in a random id. Can only surmise that Document.first.proposals.first.id==2 I don't think any order is guaranteed either unless you've specified :order somewhere so it may change randomly depending on your database. Maybe you added a new proposal with no proposal versions in addition to proposal with id=1. Or a new document even. -- Daniel Bush --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Newbie Blues
gsv wrote: Q) Why did the dinosaurs really become extinct? A) They ate their young... ... For the record... I really want RoR to be the accepted first stop for Web Development... the possibilities are tremendous... but from the starting blocks it is NOT a straightforward path... So... Does anyone know of a simple, straightforward, BEGINNERS path to getting started that works with Rails 2+ Cheers yeah, it can be frustrating. I was going to suggest a book, and then I found it was just 1.2. Rails 1.2+ was stepping stone to 2.x but I guess there are differences. I came across this: http://www.sitepoint.com/books/rails2/ but I don't know if it is good or not. Once you do get on the horse, you can then follow the changelogs (http://weblog.rubyonrails.com/releases) for each new release, see or download rails presentations, read blogs like Ryan's Scraps (to name one) so you can see what's changing. Even being on the horse can be frustrating though. I'm not comfortable with the plugin ecosystem - but I can't justify why. I don't like all the helper methods that rails provides that create an extra layer between you and what's going on - but thankfully, they are just helper methods so you can pick and choose. Rails testing is brilliant, but you'll find yourself on a treadmill going from TDD (the default) to BDD (rspec and friends). -- Daniel Bush --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Models, find not from database??? really need help :(
On Nov 17, 5:45 pm, abusiek [EMAIL PROTECTED] wrote: Hi! I'm struggling with this for a while and i'm new to rails so it's quite frustrating ;) I need to create new model object based on old one with only few changes. I have desings - has many - lines - has_many - fields I've got input from user in array like this: field =[ line_id =[ fiel_id = field_value] ] so I iterate: input[:field].each do |line_id, line| line.each do |field_id, field_value| design.lines.find(line_id).fields.find(field_id).value = field_value design.lines.find(line_id).fields.find(field_id).something = field_value end end You're finding stuff and assigning new values to what was found but not saving these changes back to the db as far as I can tell here. Retrieve the field once field=design.lines.find(line_id).fields.find(field_id) update its values and then save it field.something = ... field.save (or field.save!) You're not creating anything new, just updating old. If you want a new field, you'll need to create it: design.lines.find(line_id).fields.push(Field.new({hash-of- attributes})) This will add a new field to design's line with line_id. You could probably do something like new_field=Field.new(field.attributes) to create a new field with the same attributes as the existing 'field', alter its values as required and then push it onto the fields collection: design.lines.find(line_id).fields.push(Field.new(new_field)) Be careful with names like 'field' - I don't know if they'll clash with rails names. Maybe also consider not chaining all those 'finds' together in one line. Find each thing and store it in a local variable or an instance variable so you won't have to get it again during the action. -- Daniel Bush --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Nested forms with multiple models
On Nov 13, 12:40 am, jemminger [EMAIL PROTECTED] wrote: one suggestion: don't put business logic in your views. replace FlightTime.new with @flight_time and let your controller figure out if it should be a new or existing record. On Nov 12, 7:32 am, Alex Jonsson [EMAIL PROTECTED] wrote: ... Now this works perfectly when _adding_ FlightTimes as I'm using a FlightTime.new, but the issue I have is that I also want to be able to edit the values. When I try to use this form for editing, all the values in the boxes are emptied and anything I put in them are added as new FlightTimes (obviously). There can only be one FlightTime per FlightType per Flight, so to speak. As per jemminger, if you want your action and template to both create new objects and edit existing ones you need to put this logic into the action in the controller. So you might have: if params[:id] @foo=Foo.find(params[:id]) else @foo=Foo.new end In your view, you can then get rails to put whatever values are currently in @foo into your fields: form_for :foo , :url ... do |f| f.text_field :field1 ... end or: fields_for :foo do |f| f.text_field :field1 ... end and rails will automagic in @foo.field1 as the value in that text field because you specified ':foo'. (Sorry, can't get my head around your models) I was thinking that if you have an array of objects eg foo has_many bars and you want to edit all those bars, then in the view you could loop thru the array with an index eg: @foo.bars.each_with_index do |bar,idx| fields_for bars[#{idx}] , bar do |b| b.text_field :field1 ... end ... end Which, on submission, will generate params['bars']['0']['field1'] = some-value etc Not sure if that's good but I think it works. You could skip the whole 'with_index' thing if it's just has_one. You'll also need to embed id value for each record into a hidden field in your form if you're editing an existing item so that you can find it and update it instead of creating a new object when the form is submitted. There are security implications here - people can post a random id instead - so you need to think that through carefully. -- Daniel Bush --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Newbie needing help on Legacy DB Rails Concepts
I can't grasp the situation but it just seems to me that if you're migrating old data into a new system going forward, you should probably massage it and get it normalized and put it into the database in one hit. The best swiss army knives I know of are spreadsheets (and all their functions) and databases (sql and large data sets) for sorting this sort of stuff out. Rails isn't necessarily the best way to do it although it might help in some situations. Surely table 3 and table 1 should be combined, shouldn't they? You don't want 2 tables of agencies. You just want one and you can tell which are registered by the fact that they do or don't have a number against them. Merging table 3 into 1 might be the first thing. If registration is more complex than that, then you may have to set up more tables and associations to model it appropriately. Table 2 is already linked to table 1 via legacy ID1 - assuming these id's are ok. So I'd get table2 into the database; pull out unique list of system contacts and create a separate table 'system_contacts' (I'm assuming you've got some other fields to put against them). Table 2 then becomes a joining table. It already has the two fk's - which you might relabel as agency_id and system_contact_id. Once this is done, you'll have 3 tables and 3 models and using them would be a basic rails exercise. I probably haven't grasped the full complexity of the relationships here, so I'll stop there. -- Daniel Bush On Nov 13, 3:44 pm, Phil [EMAIL PROTECTED] wrote: Hi Daniel Thanks for replying so quickly. In a nutshell, yes. An Agency has many People. Essentially the purpose of the project is to perform an interim admin function to sync two systems. Hence there are two sets of Primary keys and two tables. The third table is the output, where it records the Agency business number to ensure that the Agency is registered. Obviously there will be multiple Agency profiles for the two systems with the primary keys for the agencies. Currently this is being done manually. What I want to find out now is how to generate the view to encompass the values from all three tables into one view, when I am using one of the two system generated lists as a list for users to determine if a client has been registered or not. E.g Agency ID 2 is clicked, which is linked to only one Agency Business Number. How do I represent the values for this Agency ID 2 from the other two tables? Obviously some Agency IDs will not have a corresponding Agency Business Number in table 3 as they have not been registered as yet, or in Table 2 for that matter. I am envisaging the use of partials. I worked out how to generate primary and foreign keys. Currently I have some code in my model that does this, but is not the best. Upload Model def self.save FasterCSV.foreach(D:/Rails/MySql/Migration/file.csv) do |row| unless Agency_ID1.exists?(row[0]) agency = Agency.new(:OrganisationName=row[1],:TPID=row[3]) do |i| i.Agency_ID1 = (row[0]) end agency.save end unless person.exists?(row[5]) contact = person.new(:ContactFname=row[6],:ContactLname=row [7],:ContactPhone=row[8], :ContactFax=row[9],:ContactEmail=row[10]) do |si| i.ContactID = (row[5]) end contact.save end end end It's meant to be interim code that helps me load primary key values. I also have a search function working with Acts_as_ferret. This is the model code for Agency 2 (list) acts_as_ferret :fields = [:OrganisationName] This is the controller class SearchesController ApplicationController def index if params[:q] query = params[:q] [EMAIL PROTECTED] = Agency_ID2.find_with_ferret query, :page = params [:page], :per_page = 50 end end end This is the view in views/searches table thead tr tdOrganisationName/td tdsmartbuy ID/td tdSupplier ABN/td tdSupplier TPID/td /tr /thead tbody % @sbtradesuppliers.each do |s| % tr td%= link_to s.OrganisationName, Agency2_path(s.id) %/td td%= s.Agency Business Number%/td td%= s.Agency ID 2%/td /tr % end % /tbody /table br br br %= will_paginate @Agency2 % My last question is, is this restful? Any help would be much appreciated. On Nov 13, 2:48 pm, Daniel Bush [EMAIL PROTECTED] wrote: On Nov 13, 11:10 am, Auch [EMAIL PROTECTED] wrote: Hi I have limited success with rails and am trying very hard to understand the MVC, DRY and RESTful concepts that Rails supports. What I am trying to do is to automate some data manipulation procedures for legacy systems. I have three tables that I need to import into the Rails application. Table 1 Legacy_System_ID1, Agency_Business_Number, Agency_Name belongs to Table 3 belongs to Table 1 Table 2 Legacy_System_ID2, Legacy_System_ID1
[Rails] Re: problem starting mongrel server
On Nov 11, 11:56 am, Chandu Chandu [EMAIL PROTECTED] wrote: Hi, I am newbie started learning ruby on rails i had an application which used to run pretty well latter i upgraded from webbrick to mongrel 1.1.5 then I am getting the foloowing errors and a default application runs on port 3000 by name iphone configuration utility i am unable to attach the screen shot as it is saying file to large. Error which i get in terminal is listed below = Booting Mongrel (use 'script/server webrick' to force WEBrick) = Rails application starting onhttp://0.0.0.0:3000 = Call with -d to detach = Ctrl-C to shutdown server ** Starting Mongrel listening at 0.0.0.0:3000 Exiting /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel/tcphack.rb:12:in `initialize_without_backlog': Address already in use - bind(2) (Errno::EADDRINUSE) You already have a program listening on port 3000 probably an earlier webrick or mongrel. If you didn't detach it, then find it and stop it. If it's detached you need to find its pid and kill it. I'm not sure what system you're using; to see what's running on port 3000 try: netstat -4np (linux) sockstat -4 (bsd) netstat -nb (windows - there's probably a better way here, I don't use windows for rails) Get the pid from the listing and kill it if it's ok to do that. -- Daniel Bush --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Testing modules
On Nov 7, 9:06 am, Greg Lazarev [EMAIL PROTECTED] wrote: I'm curious about standards on unit testing modules. I have a module file in my lib/ directory. Should I create a unit test in test/unit directory and test it as I would any other model? Don't know if there's a standard but I think it makes sense just to test it in test/unit. Is there any kind of naming convention used for unit test files for modules (some_name_test.rb or some_name_module_test.rb)? Don't know. If it's lib/some_name.rb then test/unit/ some_name_test.rb seems ok with contents: require File.dirname(__FILE__) + '/../test_helper' class SomeNameTest Test::Unit::TestCase ... end Works for me at the moment. -- Daniel Bush --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Reading value from .yml file in controller
On Nov 3, 6:41 pm, Sijo Kg [EMAIL PROTECTED] wrote: Hi Thanks for the reply.May I ask one more question? As Daniel Bush said this isn't a test fixture but just a file that is being used to set default values..So my question normally in which directory I can store this yml file whether inside models or view or anywhere? I can't see the reason for using yaml like this - but I guess you have your reasons. Since you're set on having your controller load up a yaml file every time it's accessed then I'd probably stick it in db/ somewhere.As Fred says, you could put it anywhere. You could lazy load it to save hitting the file system every time: class YourModel ActiveRecord::Base def YourModel.default_values @@default_values ||= YAML.load_file(RAILS_ROOT+'/db/ get_value.yml') end end -- Daniel Bush --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: how to create index using btree
On Nov 3, 9:46 pm, Geekforaday-Learnerforlifetime [EMAIL PROTECTED] wrote: Hi, I want to add a migration to create an index using btree , googled a little but couldn't find anything thats relevant. is this possible in rails ? or is there a work around ? appreciate your help , thanks -CG I think btree is a fairly common default. For instance it's the default in postgres, right? So if you just used the rails 'add_index' you'd get a btree index. It looks like add_index doesn't pass on extra options though (there might be some method that does this in rails I just don't know it). So if you needed to specify the index method, you might have to execute the sql manually in your migration. YourARClass.connection.execute('CREATE INDEX ... USING btree...') You'll have to consult your db docs to establish its capabilities and sql to use. -- Daniel Bush --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Reading value from .yml file in controller
On Nov 3, 5:45 pm, mrbless [EMAIL PROTECTED] wrote: Assuming that your yaml file is in test/fixtures directory. Do something like this #say ticket is an object going to be created yml=File.open(#{RAILS_ROOT}/test/fixture/get_value.yml){|ym| YAML::load(ym) } ticket.service_desk_status_id=yml[sd] [service_desk_status_id].to_i #assuming it to be integer ticket.service_desk_category_id=yml[sd] [service_desk_category_id].to_i ticket.service_desk_sub_category_id=yml[sd] [service_desk_sub_category_id].to_i I was going to take a different tack. Assuming this isn't a test fixture but just a file that is being used from somewhere to set default values for new objects, then you could do: default_values=YAML.load_file('path/to/get_value.yml') There are probably other ways to set defaults rather than loading up a file like this though. You could embed them in a class method in the model and just pull them out when you need them. Or maybe apply them in a callback (http:// api.rubyonrails.org/classes/ActiveRecord/Callbacks.html) like before_create. Or use :default in your migration when defining the table - might not be appropriate doing this with id's though. Callback example: class Foo ActiveRecord::Base before_create :apply_defaults private def apply_defaults self.field1='val1' if self.field1.blank? end end -- Daniel Bush --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Help with an RJS
elioncho wrote: The childElements length never changes when I make the event disappear. It's like it remains with what initially is loaded on the html eventhough I have hide this elements. I don't use these effects a lot, but the fade effect in prototype/ scriptaculous is probably setting the css 'display' property to none to take it out of the visual display of the document. It's still sitting there in the dom, so 'childElements' is probably counting it; it's just that it doesn't appear in the visual flow. -- Daniel Bush --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Capistrano question
On Oct 31, 1:38 pm, Joe Blow [EMAIL PROTECTED] wrote: When configuring the ssh_options[:keys] options. It says it should have a value of path/to/ssh/id_rsa. Is that on my local machine or on the host machine? id_rsa is your private key and should stay on your local machine; keep it secret; it will take the place of your password when logging in to the server. If you're worried it may be accessed by other people then encrypt it with a passphrase. id_rsa.pub is the public key and you can push that up to your server and (usually) stick it in ~/.ssh/authorized_keys. (see ssh-copy-id) ssh_options needs to know the private key so that it can authenticate you with your server (once you've pushed up your public key). -- Daniel Bush --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Problem creating Hello World app in Ruby on Rails
David Park wrote: Hi All, I just installed Ruby on Rails on my MacBook Pro and tried to create the Hello World app that is documented in the Agile Development with Rails book. I followed all the instructions for creating the Hello World app but get the following error when I try to load http://localhost:3000/say/hello MissingSourceFile in SayController#index no such file to load -- sqlite3 If you want to use mysql, then set up your rails project like this: % rails --database=mysql name If you leave out the database option, rails will assume you want sqlite3. (I think mysql used to be the default some time ago). You can alter the database and connection settings in config/ database.yaml. -- Daniel Bush --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: store session variable in a table
On Oct 29, 4:19 pm, ruby_ishk [EMAIL PROTECTED] wrote: hi,can anyone tell me how a session variable can store in table,, Do you mean change from storing sessions in a cookie to storing in your database? Or do you mean something to do with using the session? -- Daniel Bush --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: store session variable in a table
On Oct 30, 12:09 am, Ishara Gunathilake [EMAIL PROTECTED] wrote: no, suppose that there's a person who has logged in to a site and when he fill a form so the data should be stored in a table with his user id which has stored in his session. so how can i store it. You could access the session in the controller at the time the user submits. Depends on what your authentication system does. For instance it might be session[:user]. So you have to do something like user=User.find(session[:user]) or User.exists?(session[:user]) to verify the user id is valid. There may be helper methods which come with whatever plugin or system you're using so you should check them out. If you don't have a system, there are quite a few. acts_as_authenticated, restful_authentication to name 2. You'll need to install one of them and read how to use it. -- Daniel Bush --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Long running query causes Mongrel/Rails to block completely?
On Oct 30, 2:00 am, Frederick Cheung [EMAIL PROTECTED] wrote: On 29 Oct 2008, at 14:31, michael_teter wrote: Hi. I'm troubleshooting a problem, and I would love some help understanding what is going on. The problem is that Mongrel/Rails appears to hang or completely block if one of the users initiates a very slow, long-running query (via an ad-hoc report generation tool from within the app). For example, user A does a big query that takes minutes to complete. User B tries to do anything, but Rails seems completely dead. Should Rails be blocking on that query, effectively a single-user server? (I certainly wouldn't expect this...) Yup that's the way it is. load balancing across several mongrels helps a bit, but not massively because most load balancers just spread the load equally - they don't prioritize mongrels that aren't processing a request. Rails 2.2 is thread safe, but MRI's less than stellar threading means that won't make a lot of difference if you are using MRI. For jruby things could get very interesting. Wow, Looks like I'm going to have to try out jruby/rails 2.2 what with jruby using java/os threads. Anyone started looking at this with 2.2 RC or whatever the latest is? http://blog.headius.com/2008/08/qa-what-thread-safe-rails-means.html -- Daniel Bush --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Can not figure out why validation fails
I'm getting an error when posting thru google; this is 3rd time, sorry... On Oct 22, 2:40 pm, Evan [EMAIL PROTECTED] wrote: I did not notice that warning about validates_presence_of before. Thanks for bringing it to my attention. Your thought process helped me understand better what is going on. Take a look at a more recent post from Mark R J: http://www.ruby-forum.com/topic/168650 He shows how you can use validates_presence_of with assocations when building a new object. ie u.books.build(:title = 'The Comedy of Errors', :author = u) where u is an unsaved User object (used as an author). I can't remember your example exactly, but that might work for you with your current validations. The way the (online) docs are worded, though, suggests that the AR-people intended it to be used more for foreign key fields than the associations based on them. The callback before_destroy I mentioned was just a thought about how you might stop an olive oil source from being 'destroyed' ('delete' won't invoke callbacks) if it happens to be the only source for an olive oil object. Anyway, you have a bunch of validations and callbacks to use to achieve whatever you need to do. -- Daniel Bush -- Posted via http://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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Where to place the session variable to access it in model
Sijo Kg wrote: Hi I have the model SDTicket and SDCi SDTicket has_many :service_desk_cis SDCi after_save :update_sd_ticket belongs_to :sd_ticket def update_sd_ticket self.sd_ticket.update_attribute(modified_by_id,#here I need value from session) end I have a user controller in that session[:id] = current_user_id #here I am setting current user id to session[:id] Could you please tell me how I can access this value from SDCi class above in the call back after_save I can't (personally). I would probably create an instance method in the model inside which I would save the model (self.save) and do other things like update the related model. If you do it this way you could also wrap it in a transaction block to make the whole thing atomic - at least you have that option anyway. You'd pass the session value in as an argument to this method from the controller; your model shouldn't need to know about where the current_user_id came from (ie someone's http session). This makes things more testable / less coupled. That's just my thoughts. -- Daniel Bush -- Posted via http://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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Order Values in a Select Box Using select
mikej wrote: Been trawling for a while and know there must be an easy answer to this so reluctant to work round it. My select box: %= form.select( :data, { Yes = 1, No = 0},{:prompt = � Select �}) % The problem is the data is ordered alphabetically so the drop down gives the options no, yes: select id=my_id name=my[data] option value=� Select �/option option value=0No/option option value=1Yes/option /select instead of: select id=my_id name=my[data] option value=� Select �/option option value=1Yes/option option value=0No/option /select Any thoughts? Many thanks, Mike Hashes don't guarantee any particular order. Not sure if rails is sorting the hash by key as you suggest. Maybe try array of arrays. Ordinarily I'd expect the order to be maintained since its an array, but I'm not sure: form.select :data , [['yes','1'],['no','0']] , Regards, Daniel -- Posted via http://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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: testing question
Franz Strebel wrote: Hello folks, I need to write a method that will return a PDF to the user. Does anyone know of any documentation on how to test such functionality? I haven't needed to do such a thing so I'm of limited help. I suppose if you're doing downloads using rails then you've probably looked at the streaming api: ActionController::Streaming The send_data/send_file methods allow you to set the content-type and other headers etc etc. So in your functional tests for your download controller, you could probably do something like def test_1a ... get :download , params assert_equal 'text/html',@response.headers[:type] ... (Obviously replace 'text/html'). You can also access other headers eg content-length and the body (@response.body). I don't know if it's good form to be using @response. Integration test api is a little different so might be worth checking too. Daniel -- Posted via http://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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: monit newbie problem
Frioffol Friofool wrote: Hi, I tried to make monit up on my server to manage ruby on rails application. I have some problem when i try to start monit : Hi, What do you get when you run: # /usr/local/bin/monit -t -c /usr/local/src/monitrc Daniel -- Posted via http://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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: STI problem
cool wrote: I have Person model in that i have used STI like class person ActiveRecord class student person class parent person for every thing i have table called people. when i am adding a student i have fields for parent also like i want to add a student with firstname and last name and at the same time i mean in the same form i wnat to add to which parent he belongs to in the same form i have fields like parent name, email, address This was quite hard to read. Use full stops or bullet points or something. can u give idea abt this So, you have something like class Person ActiveRecord::Base ... in app/models/person.rb And: class Parent Person ... class Student Person ... maybe in app/models/parent.rb and student.rb respectively. And your 'people' table has a column called 'type' which is a string field. In your edit form you could do something like: % form_for :student , :url = {:action = 'update'} do |s| % %= s.text_field :first_name % %= s.text_field :last_name % ... parent stuff - see below ... ... submit button etc ... % end % Within this form you would have something like: %= select :selected_parent , :id , Parent.find(:all).collect{|p|[p.last_name,p.id]} % which will generate a dropdown with existing parents last_names and their id's. Or if you are entering parents details in alongside the student, something like: %= text_field :parent, :first_name % %= text_field :parent, :last_name % Read api.rubyonrails.com and go to ActionView::Helpers::FormHelper and FormOptions for how to use the form fields and what they generate in terms of the params your controller will be receiving. In your controller, the 'update' action would do something like: def update ... @student=Student.new(params[:student]) @student.parent_id = params[:selected_parent][:id] @student.save! ('parent_id' is a field for storing the id of the parent in your 'people' table.) You could save the parent using associations instead but I won't go into it. If you were collecting parent details using the text fields above, you might have: @parent=Parent.new(params[:parent]) @parent.save! Daniel -- Posted via http://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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Cannot start Mongrel
Daniel Bush wrote: ... Just make sure you have the source packages first: % aptitude install libreadline-dev % aptitude install zlib1g-dev % aptitude install libssl-dev % aptitude install libsqlite3-dev Sorry, I meant to say developer packages (which are not source packages). These give you the header files to compile your own stuff. They'll also install the library binaries if you didn't have them installed already. Daniel -- Posted via http://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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Cannot start Mongrel
Paulo Cassiano wrote: Hi, I'm trying to start *Mongrel*, but the system cannot do it and show me this message: ... I'm using *Mint Linux 5* (Debian-based), *Ruby 1.8.7* (2008-06-20 patchlevel 22) [i686-linux], *Gem 1.2.0* and *Rails 2.1.1* *What should I do in order to solve this problem?* Hi Paulo, I can't help directly with the output you provided but I would change the version of ruby for starters. 1.8.6 is the stable branch to be using (unless there's been some change announced with this version of rails). I think 1.8.7 is more experimental and may never become the new 1.8.6. Also, the patch level 22 for 1.8.7 is out of date and might be a security issue - certainly 1.8.6 p230 which was released at the same time was not working well with rails even though it was meant to fix a security issue of the previous release. It may be that your distro patched this version or the one prior to it that had the security issue, but I'd still move on if I could. Worst case, just compile it. It's not hard. But you do lose the benefits of the distro as a result. See http://www.ruby-lang.org/en/news/2008/08/11/ruby-1-8-7-p72-and-1-8-6-p287-released/ . Regards, Daniel -- Posted via http://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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---