[Rails] New Version
the gem. Hopefully it will notice this one. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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] Helper to generate css-id from AR model. Do I have alzheimers?
On one of the many Rails projects I've worked on over the years, I seem to recall using either a helper or a method on a model to generate a css id based on the model class and id. It was very useful particularly in making views more testable in RSpec/Cucumber. I can't remember if this was part of rails, or from a plugin or something specific to the project. I've failed to find anything like this in the rails docs. Any ideas what this might have been? -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Re: Helper to generate css-id from AR model. Do I have alzheimers?
On Fri, Nov 26, 2010 at 12:42 PM, Frederick Cheung frederick.che...@gmail.com wrote: On Nov 26, 4:13 pm, Rick DeNatale rick.denat...@gmail.com wrote: On one of the many Rails projects I've worked on over the years, I seem to recall using either a helper or a method on a model to generate a css id based on the model class and id. It was very useful particularly in making views more testable in RSpec/Cucumber. I can't remember if this was part of rails, or from a plugin or something specific to the project. Are you thinking of dom_id / dom_class ? Yes indeed, thanks! -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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] Looking for help to fund my Ruby Conf talk.
I'm in the embarrassing position of passing the hat. I found out a week or two ago that my proposed talk at Ruby Conf had been accepted. Unfortunately, my latest sub-contracting gig just got suspended once again due to the budget constraints of the customer, which is making it a bit tough to finance the trip. I started a pledgie campaign to 'pass the hat' yesterday, and have gotten support from the Ruby community, but I still need more help, hence this posting to the rails list. I'm hoping that some of the folks I've helped here over the years might be willing to contribute. I'll recognize any contributors in my talk, unless they choose anonymity. http://pledgie.com/campaigns/13677 And if anyone has a (preferably long-term) job opportunity for a very experienced OO Programmer and Rubyist, I wouldn't mind hearing from you. -- Rick DeNatale Help fund my talk at Ruby Conf 2010:http://pledgie.com/campaigns/13677 Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] form_for arguments
On Sun, Aug 15, 2010 at 8:28 AM, Abder-Rahman Ali li...@ruby-forum.com wrote: At the following: http://edgeguides.rubyonrails.org/getting_started.html Under: 7.4 Generating a Controller It mentions the following: %= form_for([...@post, @post.comments.build]) do |f| % Why should we insert TWO arguments? Doesn't @post.comments.build do the idea? Since I need a form for the comments belonging to @post? What is the use of the FIRST @post? It's because comment is setup as a resource nested within post. The form_for needs to generate the right combination of url and http verb, and this depends on whether or not the comment is a new record. The form_for helper is designed to allow the same form to be used both for the new and edit views. Passing an array tells form_for that it's a nested resource. In this case, @post.comments.build will be a new record, it won't have an id until it's saved. Let's say that the id of @post is 42. Then the form should be set up to send a post request using the uri path 'posts/42/comments If it was the edit case then the comment would have an id, say 432, and you'd use something like form_for @post, @comment where the edit action in the controller set both instance variables, and the form would send a put request to the url 'post/42/comments/432' If you just gave form_for the single value @post.comments.build then it assumes that the comment resources isn't nested and it would post to the uri path 'comments' but the way the routes are specified this isn't going to work. Does that make sense? -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Re: migration numbers
On Fri, Jul 30, 2010 at 7:42 AM, Ar Chron li...@ruby-forum.com wrote: But please do try to find a newer tutorial... the depot tutorial is ancient, and many things have changed.. I'm assuming the depot example is the one from Agile Web Development with Rails. There have been 3 printed editions of AWDWR, the first came out right before Rails 1.0, the second covered Rails 1.1 (which had lots of changes) but was before the change to timestamped migrations*. The latest, for which Sam Ruby took over the role of primary author from Dave Thomas, covers Rails 2.x and is the first to show timestamped migrations. In each of these the depot app has been brought up to the, then, current version of Rails. And there's a fourth edition in preparation which covers Rails 3. It's available under the Pragmatic Programmers beta program, in softcopy (pdf, epub, and mobi formats) updated as they get closer to press, and optionally as a pre-ordered print edition. Since I'm a bit of a pack-rat, my bookshelf holds all 3 printed editions, I bought the beta versions of at least the 3rd and upcoming 4th editions. I always used to pre-order the paper copy, but since I seem to be able to comfortably read books and the like on my iPad (something I was never comfortable with on a desktop or laptop). I decided to just go with the soft copy, * It hasn't been mentioned, but the reason rails went from sequence numbered to timestamped migrations is that on projects with more than one developer it was not uncommon to have collisions over the numbering when different developers were working on different branches. Since it's highly unlikely that two developers will generate migrations at the same second, this goes a long way to alleviate the problem. As with many things in Rails, it started out as a patch/plugin from some Rails user and eventually got assimilated into the Borg^h^h^h^h^h^h^h^hRails. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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] Quickie blog article about dealing with Bundler, RSpec and Rake
http://talklikeaduck.denhaven2.com/2010/06/25/making-rspec-rake-and-bundler-play-well-together Note this is for Rails 2.3, not sure if Rails 3 and Rspec 2 would be different. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] kind_of? and superclass
On Fri, Jun 25, 2010 at 8:25 AM, onion wushu li...@ruby-forum.com wrote: Hi :) In my application, I would like to know if a class is a subclass of ApplicationController, I mean, if a class is a controller. I thought about this kind of code: klass = classname while klass klass != ApplicationController klass = klass.superclass end It's working well but I'm wondering if there is a way to use the ruby fonction kind_of? to do it well. Actually, when I want to check if (for example) UsersController is a controller, I write: UsersController.kind_of?(ApplicationController), but it doesn't work at all. Do you have any ideas why ? Or do you know a better solution to handle it ? object.kind_of?(class) tests if object is an instance of class or one of it's superclasses, UserController is an instance of it's metaclass so it isn't an instance of ApplicationConrtroller or one of it's subclasses. Use the Module# method UsersController ApplicationController which returns true if the argument is one of the receivers ancestors, there is also Module#= which also returns true if the receiver is equal to the argument as well. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Rails authentication from non-web interface
On Mon, Jun 14, 2010 at 8:12 AM, Joshua Partogi joshua.part...@gmail.com wrote: Hi all, I want to authenticate my mobile phone apps to my online Rails apps. What would be the best approach to do this? Can anybody give suggestion both on how I should do it in the mobile app and in the rails app? I'd set the rails app to accept http basic authorization over https, and have the mobile app store the user's password. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Re: Getting note only the class instances but also instances of subclasses on a has_many associations
On Tue, Jun 15, 2010 at 7:57 AM, Frederick Cheung frederick.che...@gmail.com wrote: On Jun 15, 12:44 pm, gamov gamaud...@gmail.com wrote: I would like the association to return all the container charges which should be the right thing to do Anyone knows how to do this? Does this only happen if cache_classes is set to false ? Fred Fred, I don't think that's the issue here. It seems to me that the problem is the two-level STI ShippingCharge ContainerCharge HandlingContainerCharge ShippingContainerCharge So, since ContainerCharge is an STI subclass, the association has_many :container_charges is going to add a where clause restricting the results to those where the type is ContainerCharge. I haven't tested it but perhaps has_many :container_charges, :class_name = 'ShippingCharge', :conditions = {:type = %w(ContainerCharge HandlingContainerCharge ShippingContainerCharge)} -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] How do you update one object of a has_many :through relationship
On Mon, Jun 14, 2010 at 1:55 AM, Ali ali.akhtarz...@gmail.com wrote: Hi guys. How do you update nested attributes for one object of a has_many :through relationship? So I have an entity model and this model can have many fact_values. The difference between fact and fact_value is that the latter has an extra value attribute. This is because facts can be common among many entities, but each entity can have its own unique value for a specific fact. So my models are the following: class Entity has_many :fact_values has_many :facts, :through = :fact_values end class FactValue belongs_to :entity belongs_to :fact end class Fact has_many :fact_values has_many :entities, :through = :fact_values end Now I've specified that Entity accepts_nested_attributes_for :fact_values. But I want it to accept nested attributes for a single (pre-defined) fact_value and update only that fact_value. The way I'm going about it right now is to have a virtual attribute in my Entity model representing that one fact_value and update that fact_value in the entity controller. I'm wondering if there is any automatic way to accomplish what I'm trying to do? Perhaps something along the lines of class Entity has_many :fact_values has_many :facts, :through = :fact_values belongs_to :anointed_fact_value accepts_nested_attributes_for :fact_values, :reject_if = :not_updatable_fact_value def not_updatable_fact_value(attrs) attrs[:id] != anointed_fact_value_id end end -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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] How to find models that have at least one associated has_many
I'm having a senior moment. I've done this before but I can't remember how. Two active record models, Foo belongs_to Bar Bar has_many Foos I want to find all Bars that have at least one Foo, is it: Bar.all(:include = :foos, :conditions = foo.id IS NOT NULL') or something else? -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Ruby DateTime arithmetic question
On Wed, Jun 9, 2010 at 7:34 PM, Clay H. cchea...@gmail.com wrote: previous = DateTime.strptime(thefile[i-1][1], %m/%d/%Y %H:%M) current = DateTime.strptime(thefile[i][1], %m/%d/%Y %H:%M) ... I then could do something like: diff = current - previous and check to see whether diff is greater than 10 minutes -- if so, then do the processing that I need to do. It appears that diff returns as something like Rational(1, 48). I'm not sure what to do with that. It's the proportion of a 24 hour day, so 1/48 is a half hour. But since you're using rails and have active support you could do if (current - 10.minutes) previous HTH -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] problem: passing post parameters to a controller
On Fri, Jun 11, 2010 at 5:37 PM, Max You li...@ruby-forum.com wrote: Hi, I have a problem passing parameters via post. post_params=name=+name+notes=+notes+parent_nid=+parent_nid+authenticity_token=+window._token; ... the log part: Parameters: {name=abc, authenticity_token=d8c79e2216df723f373a9170fa364f9a3c147092, notes=abcde, parent_nid=0} The parameters aren't nested properly, you want. { category = {name=abc, notes = abcde, parent_nid = 0}, authenticity_token=d8c79e2216df723f373a9170fa364f9a3c147092 } I also suspect that the parent_nid attribute of category probably should be parent_id (based on convention assuming that a category belongs_to :parent) So I think you want something like this javascript: post_params=category[name]=+name+category[notes]=+notes+category[parent_id]=+parent_nid+authenticity_token=+window._token; HTH -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Re: What happens when Rails 1.3.5 is installed on top of 2.3.5?
On Sat, May 22, 2010 at 2:47 PM, pepe p...@betterrpg.com wrote: Just in case it applies here is an extract from the Pickaxe book (Second edition, page 217): Threre's a subtlety when it comes to installing different versions of the same application with RubyGems. Even though RubyGems keeps separate versions of the application's library files, it does not version the actual command you use to run the application. As a result, each install of an application effectively overwrites the previous one. That's actually not the whole story, and excerpt from the output of gem help install: Description: The install command installs local or remote gem into a gem repository. For gems with executables ruby installs a wrapper file into the executable directory by default. This can be overridden with the --no-wrappers option. The wrapper allows you to choose among alternate gem versions using _version_. For example `rake _0.7.3_ --version` will run rake version 0.7.3 if a newer version is also installed. The actual command you use to run the application is actually a bit of boilerplate generated by gems which requires the gem and then calls the executable in the bin directory of the gem. If you use that _{version}_ option it requires a specific version of the gem. So if you have both rails 2.3.5 and 1.2.6 installed then either rails or rails _2.3.5_ will run version 2.3.5 which is the latest version installed. but rails _1.2.6_ will run version 1.2.6 HTH BTW, the OP gave rails version 1.3.5 as a example, as far as I know this a fictitious version since rails went from version 1.2.6 to version 2.0.0 -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Re: Newbie question about views folder
On Sat, May 22, 2010 at 8:35 PM, FrankMurphy sabir.a.ibra...@gmail.com wrote: Okay, I got it to work on the domain root by editing /etc/apache2/ sites-available/default to point to the app's public directory. Is that the right way to go about it, or is that just a hack? If that's what I'm supposed to do, it seems odd that this step isn't mentioned in the mod_rails user guide. I still can't get it to work on a sub-uri using an analogous technique (i.e., creating a virtual host file for the URI in /etc/apache2/sites-available)... On May 21, 9:23 pm, FrankMurphy sabir.a.ibra...@gmail.com wrote: Thanks everyone for your replies. Okay, so this is interesting. When I try deploying the app to the domain root, I can't see the Welcome aboard! page; instead, I see the index.html page that's in Apache's web root directory. Also, when I try http://server_addr/users, I see a directory listing of the (.erb) files that are in the demo_app/app/views/users. Does this mean that Passenger is not set up correctly? I don't know if it matters, but the server I'm using doesn't have a domain name; I'm accessing it using its IP address. Yes I think that matters, in the example you gave in the first post you had VirtualHost *:80 ServerName server_addr DocumentRoot /projects/demo_app/public RailsBaseURI /demo_app /VirtualHost This is what Apache calls a name-based virtual host http://httpd.apache.org/docs/2.2/vhosts/name-based.html If you use an ip address like 192.168.1.123 as the value for the ServerName directive, apache will do a reverse dns search to try to find a NAME. http://httpd.apache.org/docs/2.2/mod/core.html#servername If the server actually has a unique ip address for the app, then you might look at setting up an ip address based virtual host after reading the caveats in the first section of the first url I cited. But the simpler thing would probably be to use a name based vhost and configure the client's dns to resolve the name to the ip address so you can use it in the browser urls. Just putting a line in /etc/hosts (or the equivalent if the client is a doze machine) should be enough. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Re: :body is not being stored in the database
On Sat, May 22, 2010 at 5:23 AM, RubyonRails_newbie craigwest...@googlemail.com wrote: You've writtten comments.create :id = params[:body] which I assume isn't what you wanted. Well- i'd started to follow a tutorial, but didn't quite understand it. ANy idea what id should be to allow it to save? I've tried many combinations of the id, :user_id, body etc and when I change it, the null value shifts to the user_id, or the blogpost_id. I'm probably missing something really simple, but i was looking at this all last night! :-) The id gets assigned automatically when a new record is saved, and create saves the record. def comment @user = User.find(session[:user_id]) Blogpost.find(params[:id]).comments.create(:body = params[:body], :user = @user) ... -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Re: Multiple Databases using an abstract class - help
On Wed, May 19, 2010 at 1:50 PM, Kim kim.gri...@gmail.com wrote: Well like I said, I am trying to figure out how to use an abstract class to access a separate database. I understand why calling the object attribute is not working, what I am looking for is the proper way to interact with the separate database. If an abstract class is not the way, what is? If not find_by_sql then is connection.execute the right way? Looking for an actual solution. I think you've got two things mixed up here. 1) the establish connection is what causes a model to connect to a specific database, effectively overriding the standard connection setup in ActiveRecord::Base. 2) If you want to have multiple models/tables connected to the same database, the way to do that is to have an abstract class from which they inherit the connection (much like normal models inherit the connection from ActiveRecord::Base). So if you only have a single model/table in the database, then just use 1 and not 2, I think. HTH -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] route conflict - help resolving
On Tue, May 18, 2010 at 1:16 AM, sso strongsilent...@gmail.com wrote: These are the routes I would like: map.forums_new_topic 'forums/:forum_id/:subsection_id/topics/ new', :controller = topics, :action = new map.forums_show_topic 'forums/:forum_id/:subsection_id/:topic_id', :controller = topics, :action = show however no matter which order they're in it seems like it always tries to use the show route and it crashes because topics isn't a id. Suggestions? Am I doing this the right way? Maybe if you restricted the format of the topic_id map.forums_show_topic 'forums/:forum_id/:subsection_id/:topic_id', :topic_id = /\d+/, :controller = 'topics', :action = 'show' -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Re: route conflict - help resolving
On Tue, May 18, 2010 at 10:32 AM, Sharagoz shara...@gmail.com wrote: Shallow routing was added to Rails 2.2, and encourage you to check it out. I never use deeply nested routes myself, because I don't see the point in adding information, that you already have, to the URL. By setting :shallow = true on the resource mappings, this: GET forums/:forum_id/subsection/:subsection_id/topics/topic_id will turn into this: GET topics/topic_id Yes, but I took the OP at his word that he wanted particular routes/urls. He wasn't using RESTful routing, something which I noticed but decided not to mention in trying to attack his question directly. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Re: Strange partial
On Mon, May 17, 2010 at 7:47 AM, Neil Bye li...@ruby-forum.com wrote: Frederick Cheung wrote: On May 16, 6:09�pm, Neil Bye li...@ruby-forum.com wrote: Can anybody tell me where the div, that splits submitted from comments, appears from? What does the post partial generated html look like ? Could you have forgotten to close a tag or something like that ? Fred Hope this helps I've attached the generated html. The partials are defined in this extract from user_controller.rb def show �...@user = User.find(params[:id]) �...@posts_submitted = @user.posts.find(:all, :limit = 6, :order = 'posts.id DESC') �...@posts_commented_on = @user.posts_commented_on.find(:all, :limit = 2, :order = 'comments.id DESC') end How can it create a div in the middle of a find operation? Attachments: http://www.ruby-forum.com/attachment/4739/index.html.erb Let's look at the first post from that h2posts commented on by gleb/h2 div class=post id=post_6 h3a href=/posts/6Nathan's tail/a/h3 p class=content Hi, I am a dog. Woof,woof /p p class=new emPlease log in to place a comment./em a href=/session/newLogin/a /p /div p Submitted by: a href=/users/4rover/a /p /div You have one div tag and two /div tags, which isn't balanced. This appears to be consistent for each post. I would guess you want that last closing div tag and not the one 4 lines above. I suspect that this is in _post.html.erb HTH --- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Re: Why does Object.const_defined?() returns false in this case?
On Tue, May 11, 2010 at 6:53 PM, ms m...@tzi.de wrote: Thanks for the quick answer! Yes, I am in development mode and this is actually the problem as you described. How can I force Rails even in development mode to load ALL classes, is that possible? It's not really even a development vs production environment question. Rails in general loads missing constants when referenced. The difference in the development environment is that it cleans them out between requests. Why do you need to use const_defined? Just refer to the class by name and let Rails do it's thing. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Re: Ahhh .count!
On Wed, May 12, 2010 at 4:47 PM, Jesse draco...@gmail.com wrote: Sure thing: class Portal ActiveRecord::Base has_many :users, :through = :programs end class Program ActiveRecord::Base has_many :users, :through = :program_memberships end class User ActiveRecord::Base has_many :program_memberships, :dependent = :destroy has_many :programs, :through = :program_memberships has_many :portals, :through = :programs end I'm pretty sure that Rails 2.x still doesn't support transitive has_many :through associations https://rails.lighthouseapp.com/projects/8994/tickets/1152-support-for-nested-has_many-through-associations There appears to be a plugin, although I've never used it personally. http://github.com/ianwhite/nested_has_many_through -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] redirect_to :create
On Wed, May 12, 2010 at 6:00 PM, badnaam asitkmis...@gmail.com wrote: My requirement is to maintain historical data, so basically each update creates a new record rather than updating the current record. In order to do this, I fetch the the latest record in the edit action and when the form is submitted I am trying to redirect_to :action = create in the update action. But for some reason instead it gets redirected to the index action instead. When I debug, I can see that the form gets submitted to the udpate action but after the redirect_to line, instead of going into the create action it tries to find some default_renderer.. def update redirect_to :action = create end Am I doing this right? I'd say no, you're not. Keeping back versions of a model should be the responsibility of the model, not the controller. You're still updating the record, the difference is what happens when you do. The typical way to do this would be to use something like a before_save callback on the model to save the old version. You might want to look at something like version_fu http://github.com/jmckible/version_fu -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Re: Find ALL and then count them up?
On Mon, May 10, 2010 at 7:37 PM, David Zhu dzwestwindso...@gmail.com wrote: Thanks guys, If I have nested associations, how could i count that? For ex- I want to do something like @totalcount = Post.comment.count , or something like that How could i do that? ( i want to count the comments that belong to that post) Assuming that Post has_many :comments, and you've gotten the particular post of interest to be referenced by the variable post. For the sake of the example below, let's say that the id of that post is 42 then either post.comments.count or post.comments.size will do a sql query like SELECT count(*) AS count_all FROM `users` WHERE (`users`.account_id = 42) and return the value of count_all HTH -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Getting data from an ancestor (I think)
On Tue, May 11, 2010 at 5:00 AM, Colin Law clan...@googlemail.com wrote: On 10 May 2010 21:56, sso strongsilent...@gmail.com wrote: I'm setting up a music catalogue to learn my way around RoR. In index.html.erb I would like to show the band name instead of the id. What is the proper way to do this? # records.rb That should be record.rb, not records class Record ActiveRecord::Base belongs_to :band; end # bands.rb Again, should be singular class Band ActiveRecord::Base has_many :records end # views/records/index.html.erb ... % @records.each do |record| % tr td%=h record.band.name %/td That should work, assuming you change the filenames above. Watch out for the case where no band has been allocated, however, ie record.band is nil Which is one reason that I'd recommend not having the view reach through one model to get to the attributes of another, a violation of the law of demeter (which I personally call the strong suggestion of demeter. So I'd do something like: in the view ... td%=h record.artist %/td and in the record model class Record ActiveRecord::Base belongs_to band def artist if band band.name else Anonymous end end end This decouples the view from the DB representation, and will make changes down the road like changing the database schema to allow multiple artist compilations to be represented, when you will change the belongs_to and has_many relations in Record and Band to either has_and_belongs_to_many or has_many :through associations. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Re: Find ALL and then count them up?
On Tue, May 11, 2010 at 8:43 AM, David Zhu dzwestwindso...@gmail.com wrote: On May 11, 8:36 am, Colin Law clan...@googlemail.com wrote: I believe that if you also say Page has_many davids through comments then you can get at all the davids for a post by @post.davids and hence you can use @posts.davids.count i need a join table? is the join table my comments table? Yes but.. First I notice that you continue to use code of the form Post.comments. Which won't work, since the associations like belongs_to, has_many ... create INSTANCE rather than class methods. You need to use something like some_post.comments. .. where some_post refers to a particular instance of Post. Second, I suspect that David here is a hypothetical model class, and that what you might really be trying to do is count all the comments made by a particular user. Maybe you want something like: class Post ActiveRecord::Base has_many :comments end class User ActiveRecord::Base end class Comment ActiveRecord::Base belongs_to :post belongs_to : user named_scope :by_user, lambda {|user| :conditions = {:user = user} end then some_post = Post.find(params[:id]) # or some other code to get a particular post david = User.find_by_userid(david) # or some other code to get a particular user some_post.comments.by_user(david).count -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] best way to model this
On Mon, May 10, 2010 at 8:52 AM, Dieter Lunn coder2...@gmail.com wrote: I would do: Passengers belong_to Car Car has_many Passengers Car has_one Driver, :class = Passenger I'd do something similar. Actually if I had the freedom, I'd probably rename the class Passenger to something like Person since Driver and Passenger are really roles, not entities. class Person ActiveRecord::Base belongs_to :car end class Car ActiveRecord::Base belongs_to :driver, :class = ;person has_many :passengers, :class = person end -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] rake
On Sat, May 8, 2010 at 2:19 PM, Philip Hallstrom phi...@pjkh.com wrote: On May 8, 2010, at 11:16 AM, doug wrote: I've been looking into rake. rake appears to be a very heavy duty thing along the lines of make. I'm thinking that there must be some pretty serious documentation somewhere; but, I seem to be having trouble turning it up. Can someone please point me in the right direction? Thanks. http://rake.rubyforge.org/ And googling for ruby rake turned up: A classic exposition on Rake albeit rather old: http://martinfowler.com/articles/rake.html A much more recent tutorial, with some more links at the end: http://jasonseifer.com/2010/04/06/rake-tutorial -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Using re to make BidDecimal's more readable using Regexp: problem
On Sat, May 8, 2010 at 7:24 PM, RichardOnRails richarddummymailbox58...@uscomputergurus.com wrote: Hi, I'm on a mission to show my granddaughter how Pi can be computed. For that, I need Sqrt(2) computed accurately, which I've done. But I need to display results in 5-digit groups, space separated. The following aims at displaying the five-or-less decimal components of a 12-decimal-digit number (related to sqrt(2) but ignoring scaling and precision for the moment). bd = BigDecimal(0.141421356237) group_sz=5 re_string = \\.(\\d{1, + group_sz.to_s + })+ r = Regexp.new(re_string) m = r.match(bd.to_s) (0..3). each do |i| puts( %s = %s; m[%d] = %s % [r, m, i, m[i]] ) I get (ignoring scaling for the moment): (?-mix:\.(\d{1,5})+) = .141421356237; m[0] = .141421356237 (?-mix:\.(\d{1,5})+) = .141421356237; m[1] = 37 # want 14142 (?-mix:\.(\d{1,5})+) = .141421356237; m[2] = # want 13562 (?-mix:\.(\d{1,5})+) = .141421356237; m[3] = # want 37 So the extra set of parentheses I added don't capture the way I want them to. I can do it using Ruby to generate a bunch of consecutive \d{1,5} groups to satisfy my requirement, but some insightful Regexp markup is preferable. Any ideas? Does this help? BigDecimal(0.141421356237).to_s.scan(/(\d{1,5}|\.|\E)/).join( ) #= 0 . 14142 13562 37 E 0 -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Re: Input/output error
Based on the walkback, whatever object the @plat instance variable is assigned to is causing the error when sent the id message, hopefully your own debugging skills will enable you to use that clue to figure it out. The code seems to be way too complicated for me to help you much more remotely. On Fri, May 7, 2010 at 2:48 AM, Nitin Mathur li...@ruby-forum.com wrote: Hi Rick, Thanks for reply. Could use of the old version cause this problem? Actually I wanted to use the latest version of Rails but that was not compatible with the ruby installed in my system and I could not figure out which Ruby version was compatible with latest Rails at that time (2.3.4). I my code the instance variable @plat refers to platforms, similarly the variable @rel refers to release. So actually I have folders in my application that is applicable for some releases and platforms. After selecting these platforms and releases a Javascript is called which stores the combination of release and platforms and stored in another dropdown menu with name platrel with platform name nd release name separated by a hyphen (-) so in controller you will only see the variable platrel. I am pasting the controller code below. Contrller code: params[:platrel]['id'].each {|x| pr = pr = x.split(\-) platid = Platform.find(:first,:conditions = ['name = ?',pr[0].to_s]).id relid = Release.find(:first,:conditions = ['release_name = ?',pr[1].to_s]).id �...@newavail = Ownership.find(:first, :conditions = ['folder_id = ? and platform_id = ? and release_id = ? and stop IS NULL and deleted IS NULL', params[:f],platid,relid]) if @newAvail.blank? �...@ownerships = Ownership.new( :folder_id = params[:f], :platform_id = platid, :release_id = relid, :primary_owner = @fold_owner.primary_owner, :secondary_owner = @fold_owner.secondary_owner, :created = Time.new, :start = Time.new ) �...@ownerships.save if (pr[0].to_s != Any) anyid = Platform.find(:first,:conditions = ['name = Any']).id �...@anyavail = Ownership.find(:first, :conditions = ['folder_id = ? and platform_id = ? and release_id = ? and stop IS NULL and deleted IS NULL', params[:f],anyid,relid]) if @anyAvail.blank? �...@any_ownerships = Ownership.new( :folder_id = params[:f], :platform_id = anyid, :release_id = relid, :primary_owner = @fold_owner.primary_owner, :secondary_owner = @fold_owner.secondary_owner, :created = Time.new, :start = Time.new ) �...@any_ownerships.save end end else �...@newavail.stop = 'NULL' �...@newavail.deleted = 'NULL' Thanks, Nitin. -- 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. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Re: Rails fails to find models in subfolders
On Fri, May 7, 2010 at 3:26 AM, Andy Joel li...@ruby-forum.com wrote: Thanks for the reply On Thu, May 6, 2010 at 6:58 AM, Andy Joel li...@ruby-forum.com wrote: I have my models and controllers set up in sub-folders, so, for example, sample.rb is in app/models/sample_log, and samples_controller.rb is in app/controllers/sample_log. The controllers are defined to be within a namespace just though the class name, eg like this: class SampleLog::SamplesController SampleLog::SuperController However, the models are not. class Sample ActiveRecord::Base Where is this file? I'm guessing that it's in app/models/sample_log/sample.rb ? Yes Expected R:/samplelog/app/models/sample_log/sample.rb to define SampleLog::Sample What this is saying is that Rails tried to find a class or module SampleLog::Sample Is that right? I think it is the other way around; it is trying to find Sample, but objects because it thinks it should be in sample.rb, not sample_log/sample.rb. SampleLog::Sample is not used anywhere in the project (and I have done a search to confirm this). app/controllers/sample_log/samples_controller.rb:11:in `home' Here are lines 10 to 12 def home �...@samples = Sample.find :all end Basic Ruby lesson. You have class SampleLog::SamplesController def home @samples = Sample.find :all end end When Ruby needs to figure out what Sample means in that home action, it first looks for a constant in the current namespace so it looks for SampleLog::SamplesController::Sample Rails catches this as a missing constant and tries to find a file under one of the load paths sample_log/samples_controller/sample.rb but doesn't find one so it hands the problem back to Ruby, which then tries to find the constant Sample one step up the namespace chain and looks for SampleLog::Sample. Now rails looks for sample_log/sample.rb and finds it, and loads it, and then checks to see whether SampleLog::Sample is now defined, which it isn't because that file defined ::Sample instead. Did you try just moving app/models/sample_log/sample.rb to app/models/sample.rb as I suggested, I'm pretty sure that doing this, and possibly removing the the stuff you did to monkey with the load paths behind Rails back should fix your problem. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Re: Re: Controller Tests fail
On Fri, May 7, 2010 at 11:03 AM, Greg Donald gdon...@gmail.com wrote: On Fri, May 7, 2010 at 9:46 AM, Marnen Laibow-Koser li...@ruby-forum.com wrote: Use what works for you. But don't claim academic masturbation in the face of many of us who know it not to be true. That's been my experience when using them. There's no reason to to replace what's already there and already works great. Two others help write the book. I would trust the three of those guys before anyone who endorses Cucumber, any day of the week. I'm not a fan of dogmatism on either side. A few observations though: 1) I own every edition of AWDWR, including the latest version covering Rails 3. Each edition is an evolution of its predecessor. It started with test/unit and fixtures since that's what came with Ruby and was baked into rails. Although alternatives have appeared, the book has tended to stay there, probably because a) it's talking about what comes with rails, and b) it's easier not to rewrite sections when you don't have to. There are also pedagogical concerns. AWDWR is primarily an introduction to rails. Just like they teach physics in high school without recourse to calculus, doesn't mean that calculus isn't a very useful tool when you really start to practice Physics, some advanced topics are best left to later courses. 2) Rails 3 has refactored rails so that test/unit isn't closely coupled. If you install the rspec-rails and cucumber plugins, for example the rails3 generators will automatically produce rspec specs and cucumber features. Since the 4th edition of AWDWR is in an early beta form, I don't know how much Sam will cover this. Again, there's a certain amount of inertia. For one thing he has made and effort to bring testing earlier in the depot example, which I like. However he hasn't changed the flow to use test driven design, which is and should be standard practice for rails developers whether they are using test/unit, rspec, shoulda ..., I understand that just breaking up the testing chapter and reshuffling the chapters. It's better but it still comes across as fostering code first then test, which I doubt the authors fully endorse. 3) Fixtures. There are lots of experience Rails developers who have come to the conclusion that fixtures really s*ck. Hence all the fixture replacement plugins. In my experience, these days fixture replacements tend to be used much more than the built-in rails fixtures in real-world rails projects, not that there's much of consensus on which one is best. If fixtures work for you find, if not... 4) RSpec and Cucumber are seen as very powerful tools by a wide range of Rubyists and Rails app developers. Far from spilling our intellectual seeds on the ground, as your colorful characterization would have it, we are being very prolific, thank you! 5) I would argue that the fact that Dave Thomas is the publisher of The RSpec Book, which really should be called the RSpec and Cucumber book, constitutes an endorsement of RSspec and Cucumber. But then as they say in Rome, de gustibus non est disputandum! Use your intellectual seeds as you will. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Rails fails to find models in subfolders
On Thu, May 6, 2010 at 6:58 AM, Andy Joel li...@ruby-forum.com wrote: I have my models and controllers set up in sub-folders, so, for example, sample.rb is in app/models/sample_log, and samples_controller.rb is in app/controllers/sample_log. The controllers are defined to be within a namespace just though the class name, eg like this: class SampleLog::SamplesController SampleLog::SuperController However, the models are not. class Sample ActiveRecord::Base Where is this file? I'm guessing that it's in app/models/sample_log/sample.rb ? Instead, I have added the relevant directories to config.load_paths in environment.rb. Which may be part of the problem. You might well be fighting convention over configuration. Unit testing, functional testing and integration testing all pass without a problem, and I can use the Rails console normally too. However, trying to access the web pages leads to some problems... Putting a print statement in sample.rb, I can see that it is only when I try to access a page with a sample on it that sample.rb gets loaded, which makes perfect sense. However, it then throws an error: Expected R:/samplelog/app/models/sample_log/sample.rb to define SampleLog::Sample What this is saying is that Rails tried to find a class or module SampleLog::Sample What rails does here is to look for samplelog/sample.rb somewhere in the various load paths. It's finding app/models/sample_log/sample.rb which if it indeed contains: class Sample ActiveRecord::Base outside of a class or module block is definining ::Sample, not ::SampleLog::Sample. I'm guessing that moving app/models/sample_log/sample.rb to app/models/sample.rb will fix this. If not then show us the walkback you get on the error, it should point to some piece of code which is referring to some constant (name_space::)*Sample -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Validating the presence of foreign keys /associated objects
On Thu, May 6, 2010 at 10:20 AM, ct9a anexi...@gmail.com wrote: class Fit ActiveRecord::Base belongs_to :Part belongs_to :Brand It probably doesn't make a difference, but conventionally the attribute ids should be lowercase belongs_to :part belongs_to :brand validates_presence_of :part_id The association name is :part not :part_id so validates_presence_of :part HTH -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Input/output error
On Thu, May 6, 2010 at 4:44 AM, Nitin Mathur li...@ruby-forum.com wrote: Hi My application was running fine. All of sudden I started to get an input/output error in one of the templates. However, error goes away once I restart the mongrel server but after some time again same error appears. I am pasting the trace below. Please help me getting rid of this error forever. ActionView::TemplateError (Input/output error) on line #46 of app/views/starwars/edit_folders.rhtml: 43: tr 44: tdPlatform Applicable: nbsp;nbsp;/td 45: td 46: %= select 'plat','id',Platform.find(:all,:order = 'start DESC').collect{|p| [p.name, p.id]},{:selected = Platform.find(params[:p]).id} % 47: /td 48: td rowspan=2 49: %#= link_to_function ADD,Folders.copy_select(); % /usr/local/rubygems/gems/gems/actionpack-1.13.3/lib/action_view/helpers/form_helper.rb:349:in `write' /usr/local/rubygems/gems/gems/actionpack-1.13.3/lib/action_view/helpers/form_helper.rb:349:in `id' /usr/local/rubygems/gems/gems/actionpack-1.13.3/lib/action_view/helpers/form_helper.rb:349:in `send' /usr/local/rubygems/gems/gems/actionpack-1.13.3/lib/action_view/helpers/form_helper.rb:349:in `value' /usr/local/rubygems/gems/gems/actionpack-1.13.3/lib/action_view/helpers/form_helper.rb:340:in `value' /usr/local/rubygems/gems/gems/actionpack-1.13.3/lib/action_view/helpers/form_options_helper.rb:300:in `to_select_tag' /usr/local/rubygems/gems/gems/actionpack-1.13.3/lib/action_view/helpers/form_options_helper.rb:66:in `select' #{RAILS_ROOT}/app/views/starwars/edit_folders.rhtml:46:in `_run_rhtml_47app47views47starwars47edit_folders46rhtml' /usr/local/rubygems/gems/gems/actionpack-1.13.3/lib/action_view/helpers/capture_helper.rb:108:in `call' /usr/local/rubygems/gems/gems/actionpack-1.13.3/lib/action_view/helpers/capture_helper.rb:108:in `capture_erb_with_buffer' That's an OLD version of Rails! Not sure what's going on but it appears that id is being sent to whatever the @plat instance variable is referring to, and that is somehow doing a write. What does the controller code look like -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Re: Using self. Can you newbify this for me?
On Thu, May 6, 2010 at 5:15 PM, Michael Pavling pavl...@gmail.com wrote: On 6 May 2010 22:11, Joshua Martin josmar52...@gmail.com wrote: Question: Doesn't Ruby automatically return the object you were last operating on? not quite. it returns the result of the last operation. Actually the value of the last expression. Which is why ending a method with a variable name doesn't do nothing, as Joshua seems to think, it provides the result of the method. And it IS standard ruby practice. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Getting class in /lib folder to see a model (const_missing)?
On Mon, May 3, 2010 at 9:57 PM, Mike P. li...@ruby-forum.com wrote: When I do this though, I get a 'const_missing' error coming from Active Support. Here's the error: .../lib/active_support/dependencies.rb:105:in `const_missing': uninitialized constant ClassA::ModelA (NameError) The 'ModelA' is the model I'm trying to access, and 'ClassA' is the class in /app/lib/class_a.rb. I'm not sure why it seems to think that ModelA is a part of ClassA, perhaps that's the problem? Shouldn't it be in {Rails.root}/lib/class_a.rb rather than {Rails.root}/app/lib/class_a.rb -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] using delicious api to retrieve favorite bookmarks
On Thu, Apr 29, 2010 at 1:01 PM, alternative451 alternative...@gmail.com wrote: hello there, i develop a litle rails api and i want list most favorite bookmarks from delicious. i'm looking for a request using yahoo id (i have yahoo api key and others stuff needed) Someone already use delicious api ? someone can help me ? I've never done it myself but http://delicious.com/help/thirdpartytools has a couple of Ruby bindings for the delicious API HTH -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Find by Date Regardless of Time
On Tue, Apr 27, 2010 at 4:07 PM, Joshua Martin josmar52...@gmail.com wrote: I have a datetime field in the database. How do I find records for a particular date regardless of the time of day? The method I'm trying does not work.. tasks.find(:all, :conditions = [date == ?, Date.today]) You might want to look at http://github.com/radar/by_star Just discovered this in the past few days. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Re: habtm relation, cannot populate join table
On Thu, Apr 29, 2010 at 1:26 AM, Veena Jose li...@ruby-forum.com wrote: Hai Rick, I have made the change you hav told. Still the join table is not been populated. These are my migration data.Is there any problem with this? . class CreateNewStations ActiveRecord::Migration def self.up create_table :stations do |t| t.string :name t.integer :district_id t.string :MDT_id t.string :sim_no t.decimal :longitude, :precision=10, :scale=6 t.decimal :latitude, :precision=10, :scale=6 t.integer :user_id I don't think you want this field. This would be there if you had class Stations ActiverRecord::Base belongs_to :user end but you indicated that each station could have many users, and each user could have many stations, thus the habtm relations. t.timestamps end create_table :stations_users, :id = false do |t| t.integer :user_id t.integer :station_id end end def self.down drop_table :stations_users rescue nil drop_table :stations end end ... class CreateUsers ActiveRecord::Migration def self.up create_table :users do |t| t.string :name t.string :username t.string :hashed_password t.string :salt t.string :status t.string :phone t.string :email t.integer :station_id t.timestamps end end def self.down drop_table :users end end -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] How to match dynamic named routes in Rails 3
On Tue, Apr 27, 2010 at 6:06 PM, Jury jurew...@gmail.com wrote: Hi everyone, I've been digging pretty deeply into the new routing capabilities in Rails 3 and have been very impressed by what I've seen so far. However, in my exploration I haven't been able to figure out one final piece — it's a bit complicated to summarize, so here's a short example of what I would like to do: Let's say I've got a simple set of forums software, with a controller named Forum. In the data model that Forum uses, there are a bunch of topics with subtopics: Foo |--- Bar |--- Baz |--- Rick |--- Astley Although that's the way the structure looks today, there's nothing that would prevent an admin from adding topics under Bar at a moment's notice — so the main point is that the structure could change. I'd like to be able to write a routing rule such that I could match http://example.com/Foo/Baz/Rick; to a specific action in the Forum controller and know the order of the parameters that were passed in. In a perfect world, I'd really only like to forward the request on to the Forum controller if the path is sensible. I have some feeling that I might be able to do something creative with :constraints, but I'm not quite sure if I can pass in an appropriate method or proc that would have access to the necessary data to do that check. Can anyone out there with some better insight point me in the right direction? Well in Rails 2.x you could use something like this (from the rails guide example): map.connect 'photo/*other', :controller = 'photos', :action = 'unknown' this would set params[:other] to an array of the path segments following photo. I applied this thinking to Rails 3 routing, and added a route to a version of the AWDWR depot app (I'm once again following that example through the new beta version of the 4th edition). I put this at the end. match '*path' = 'products#forum' I then added a forum action to the products controller which just raises an exception so that I can see what the params are, and I get this: {path=products/forum/a/b/c} So instead of breaking it down to an array it just gives you the whole string. Some caveats. 1) Although the existing routes still work since I put this at the end of the routes, unless this is the only controller you have you might want to 'anchor' such urls with a first path component (e.g. forum). 2) Whether or not the fact that a 'globbed' route produces a string rather than an array, might or might not be a bug in Rails 3.0.0.beta3 so it might change before release 1. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Re: why is ActiveRecord tying to select nonex ID column?
On Tue, Apr 20, 2010 at 12:51 PM, Fearless Fool li...@ruby-forum.com wrote: Frederick Cheung wrote: for a normal HABTM there is no corresponding model, so rows never get updated by this code path. The habtm association generates sql fragments directly and runs them Furthermore, because habtm is usually used as a 'dumb' join table, it's only ever a question of deleting or inserting rows Fred Enlightenment is a slow process, at least for me. So I think what's going on is that I've created a table that *should* be declared as HABTM. And now that I think about it in those terms, I'm not sure why I didn't to that in the first place. Time for another script/generate migration... Actually, I think what you want is to use has_many :through 1. add an id to metered_usages 2. class MeterUsage belongs_to :service_address belongs_to :metered_service end class ServiceAddress has_many :metered_usages has_many :metered_services, :through = :metered_usages end class MeteredService has_many :metered_usages has_many :service_addresses, :through = :metered_usages end -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] habtm relation, cannot populate join table
On Wed, Apr 21, 2010 at 8:08 AM, Veena Jose li...@ruby-forum.com wrote: Hai friends, I hav two models related with habtm class User ActiveRecord::Base has_and_belongs_to_many :station, :join_table = stations_users, :foreign_key = user_id, :association_foreign_key = station_id Shouldn't this be has_and_belongs_to_many :stations The plurality is important. Also with that change the join_table, foreign_key and association_foreign key options are unnecessary since those are the defaults. class Station ActiveRecord::Base has_and_belongs_to_many :user And this should be has_and_belongs_to_many :users end When i create a new user its user_id and the station _id is not inserted into the stations_users table.I hav used scaffolding 4 creating these two models.How can i insert the fields for the join table also when a user is created? Can any one help me? Not sure that this is your problem, but I wouldn't be surprised. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Re: id upper bounds
On Mon, Apr 19, 2010 at 12:47 PM, Vladimir Rybas vladimirry...@gmail.com wrote: They're not the same, right. I mean, it depends on what you need. The real ID or just an amount of records. But If task is to get random record you will Company.all[rand(Company.count)] but not Company.all[rand(Company.last.id)] I assume you meant find rather than all. Neither of these will work in the face of deleted records, picking a random record is a bit tricky. One way, which might not work for all databases, but assuming a mysql database might be: Company.first( :order = Rand()) But this isn't very efficient and might not work for tables with lots of records. Another approach is something like. Company.first(:conditions = [id = ?, rand(Company.last.id) + 1] This should always return a random record (unless the table is empty), but the records won't be evenly distributed because the probability of selecting a particular record is proportional to the difference between it's id and the id of the preceding existing record if any, or 0. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Is there a way to use @today in a model ??
On Sun, Apr 18, 2010 at 2:46 AM, Philip Hallstrom phi...@pjkh.com wrote: On Apr 17, 2010, at 10:30 PM, Bob Smith wrote: I'm trying to get records from a has_many that are only from this year. has_many :visit, :conditions = year = #...@today.year}, :dependent = :destroy This has trouble. it thinks @today is null.. Any other ideas? Don't you want :visits (with an s?) has_many :visits, :conditions = year = SQL_FUNCTION_THAT_RETURNS_CURRENT_YEAR,. Replacing SQL_FUNCTION...YEAR with whatever works for your database. If you want to specify the year, look into using a lambda for the conditions... I don't think you can use a lambda on the :conditions option to find/has_many... but you can do it with a named scope has_many :visits, :dependent = destroy named_scope :this_year, lambda { { :conditions = { :year = Date.today.year } }} Then to get the visits this year for a model referred to by the variable model model.visits.this_year Alternatively, you could have a slightly different named scope which would let you specify the year at run-time, assuming that @today might not always Date.today, e.g. if you are using the user's timezone. named_scope :in_year, lambda { |year| {:conditions = {:year = year}} Then you could use model.visits.in_year(@today.year) The reason you need to express this a a lambda is twofold: 1) has_many and named_scope are evaluated in the context of the active record class, so @today is not an instance variable but a class instance variable, which is probably why it is nil. 2) more importantly, @today is being evaluated at the time the association declaration is executed (during class definition time). If you want to use the value at the time you make the query, it needs to be a lambda so that the value gets evaluated each time. HTH -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Re: controller request.body?
On Fri, Apr 16, 2010 at 9:16 PM, Me chabg...@gmail.com wrote: StringIO#request.body says StringIO in the log file. On Apr 16, 7:40 pm, Rick DeNatale rick.denat...@gmail.com wrote: On Fri, Apr 16, 2010 at 8:34 PM, Me chabg...@gmail.com wrote: I am trying to get the body of the request coming in to the controller. request.body is a StringIO object. I cannot seem to see what is actually inside it. any ideas? StringIO#string StringIO#string is a reference to the stringmethod of StringIO, this is normal Ruby notation for talking about an instance method. so request.body.string -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] contet_tag :ul question
On Fri, Apr 16, 2010 at 3:26 PM, Pito Salas li...@ruby-forum.com wrote: Hi all This isn't doing what I expect it to. Can you give it a quick look-see if you have a moment? def user_navigation_helper content_tag(:div, :class =banner_right) do content_tag(:ul, :class = wat-cf) do if current_user() content_tag(:li) { current_user.email } content_tag(:li) { link_to(Edit profile, edit_user_path(:current)) } content_tag(:li) { link_to(Logout, logout_path) } else content_tag(:li) { link_to(Login, login_path) } content_tag(:li) { link_to(Register, new_user_path) } end end end end I am getting just one of the two or thee li items. Is there a better/cleaner/correct way of doing this? Thanks! one way: def user_navigation_helper content_tag(:div, :class =banner_right) do content_tag(:ul, :class = wat-cf) do if current_user() [content_tag(:li) { current_user.email }, content_tag(:li) { link_to(Edit profile, edit_user_path(:current)) }, content_tag(:li) { link_to(Logout, logout_path) }]].join else [content_tag(:li) { link_to(Login, login_path) }, content_tag(:li) { link_to(Register, new_user_path) }].join end end end end -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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] [ANN] ri_cal version 0.8.7 has been released!
ri_cal version 0.8.7 has been released! A new Ruby implementation of RFC2445 iCalendar. The existing Ruby iCalendar libraries (e.g. icalendar, vpim) provide for parsing and generating icalendar files, but do not support important things like enumerating occurrences of repeating events. This is a clean-slate implementation of RFC2445. A Google group for discussion of this library has been set up http://groups.google.com/group/rical_gem Changes: === 0.8.7 fix ticket #29-supress x-rical-tzsource when not relevant === 0.8.6 Fixes an issue of RFC 2445 non-conformance - change management time attributes (dtstamp, last_modified, and created) MUST be zulu time Changed VTIMEZONE export from tz_info Discovered that RFC 2445 expects a timezone period onset to be local time before the change, while TZInfo gives it after the change Thanks to both Michael Hale and H. Wade Minter for reporting this. Changed from generating a single RDATE line for a timezone period with multiple values to multiple RDATE lines to fix a problem reported by Michael Hale. === 0.8.5 Fixes http://rick_denatale.lighthouseapp.com/projects/30941/tickets/26 events with date parameters failing === 0.8.4 - 18 September 2009 Refactored load structure, should now be conforming to http://weblog.rubyonrails.org/2009/9/1/gem-packaging-best-practices I did finesse the load path issue a bit as a workaround to RSpec not putting lib on $LOADPATH the lib directory will get added to load path IF IT ISNT ALREADY THERE Fixes http://rick_denatale.lighthouseapp.com/projects/30941/tickets/25 please clean your code up to be quiet Thanks to Ryan for such a courteous problem report. === 0.8.3 - 18 September 2009 Released with bad gemspec === 0.8.2 - 4 September 2009 Fixes http://rick_denatale.lighthouseapp.com/projects/30941/tickets/23 initialization_methodsrb-syntax Fixes http://rick_denatale.lighthouseapp.com/projects/30941/tickets/24 need-to-handle-empty-property-values === 0.8.1 - 18 August 2009 Fixes http://rick_denatale.lighthouseapp.com/projects/30941/tickets/21 exception-when-count-option-used-to-enumerate-non-recurring-event -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] controller request.body?
On Fri, Apr 16, 2010 at 8:34 PM, Me chabg...@gmail.com wrote: I am trying to get the body of the request coming in to the controller. request.body is a StringIO object. I cannot seem to see what is actually inside it. any ideas? StringIO#string -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] People Centric recherche plusieurs déve loppeurs Ruby on Rails
2010/4/13 Roxana Stefan Malene andreea.mal...@gmail.com: Un bon job de Developpeur Expérimenté Ruby on Rails, sur logiciel marketing digital, équipe pro, Paris 2, Sté Cotée, Paris Rou SiliconValley. Veuillez consulter le lien suivant pour plusieurs détails: http://www.people-centric.fr/2010/01/27/type/6368-job-developpeur-ruby.html/fr/ J'aime Paris, mais, je suis desolé, j'habite en Caroline du Nord. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Advise sought: Upgrade from Rails 2.0.1 to current
I would advise stepping first to 2.1 since there were a lot of changes to ActiveRecord with that release (partial updates/dirty attribute tracking) which had subtle effects on things like callbacks. For some of the apps I was involved in, 2.0 - 2.1 was actually a more difficult transition than 1.2.x - 2.0. On Tue, Apr 13, 2010 at 6:22 PM, Paul Jonathan Thompson rails...@gmail.com wrote: I have upgraded from 1.2.6 to 2.0.1 and successfully passed all my test and manual testing. Everything seems to be working correctly. My application is pretty vanilla and so there where few complications. Question is, should I do another point upgrade (and if so, which point to upgrade to next) or is it safe (and prudent) to just go straight on to the current version (2.3.x). Advise would be most welcome. Paul Thompson -- 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. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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] [ANN] ri_cal 0.8.6 has been released
ri_cal version 0.8.6 has been released! A new Ruby implementation of RFC2445 iCalendar. The existing Ruby iCalendar libraries (e.g. icalendar, vpim) provide for parsing and generating icalendar files, but do not support important things like enumerating occurrences of repeating events. This is a clean-slate implementation of RFC2445. A Google group for discussion of this library has been set up http://groups.google.com/group/rical_gem Changes: === 0.8.6 Fixes an issue of RFC 2445 non-conformance - change management time attributes (dtstamp, last_modified, and created) MUST be zulu time Changed VTIMEZONE export from tz_info Discovered that RFC 2445 expects a timezone period onset to be local time before the change, while TZInfo gives it after the change Thanks to both Michael Hale and H. Wade Minter for reporting this. Changed from generating a single RDATE line for a timezone period with multiple values to multiple RDATE lines to fix a problem reported by Michael Hale. === 0.8.5 Fixes http://rick_denatale.lighthouseapp.com/projects/30941/tickets/26 events with date parameters failing === 0.8.4 - 18 September 2009 Refactored load structure, should now be conforming to http://weblog.rubyonrails.org/2009/9/1/gem-packaging-best-practices I did finesse the load path issue a bit as a workaround to RSpec not putting lib on $LOADPATH the lib directory will get added to load path IF IT ISNT ALREADY THERE Fixes http://rick_denatale.lighthouseapp.com/projects/30941/tickets/25 please clean your code up to be quiet Thanks to Ryan for such a courteous problem report. === 0.8.3 - 18 September 2009 Released with bad gemspec === 0.8.2 - 4 September 2009 Fixes http://rick_denatale.lighthouseapp.com/projects/30941/tickets/23 initialization_methodsrb-syntax Fixes http://rick_denatale.lighthouseapp.com/projects/30941/tickets/24 need-to-handle-empty-property-values === 0.8.1 - 18 August 2009 Fixes http://rick_denatale.lighthouseapp.com/projects/30941/tickets/21 exception-when-count-option-used-to-enumerate-non-recurring-event -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Will rake db:migrate:down VERSION=XXX completely remove that migration from Rails?
On Tue, Apr 6, 2010 at 11:29 PM, Ryan Waldron r...@erebor.com wrote: You'll also need to remove that migration's entry from the 'schema_migrations' table. That's how Rails keeps up with what migrations exist, and whether it's done them all. Running rake db:migrate:down VERSION=XXX should remove the entry. Otherwise rake db:migrate wouldn't run the migration again. A normal use case for migrate down is: rake db:migrate #oops something was wrong in migration 123456 rake db:migrate:down VERSION=123456 edit db/migrate/123456_whatever_it_does rake db:migrate On Tue, Apr 6, 2010 at 10:10 PM, GoodGets goodg...@gmail.com wrote: What exactly does rake db:migrate:down VERSION=XXX do? I understand that it runs the down migration, completely removing any columns/ tables that migration may have created, Well it does whatever YOU told it to in the down part of the migration. It's up to you (or whatever you use to edit/generate the migration) to write the correct code there. I tend to use Textmate snippets from the rails bundle to do migrations, and the table/column migration snippets will generate 'undo' code in the down migration when you expand them in the up migration. But YMMV depending on what tools you use. but does this mean that I can can delete these migration files as well? I'd like for Rails to have no knowledge of their existence. (I was allowing user profile pics with Paperclip, but have since decided to just use their Gravatars.) I know you can delete a migration, and even delete those columns from the schema, but Rails still remembers these changes and just updates them the next time you rake db:migrate. So, I'd like to completely rid my app of a particular migration, is rake db:migrate:down then deleting that migration from the migrate folder the way to do it? When you do rake db:migration the rake task looks for migrations under db/migrate which don't have entries in the schema_migrations table, and runs those (actually I think it's a bit more subtle than that, there's been discussion of a 'bug' which can make the task ignore migrations with a timestamp older than the newest one in schema_migrations, which can keep migrations merged from another branch NOT to be run. But... If you run rake db:migrate:down version=XXX and then remove the file db/migrate/XXX_whatever from your source, the rake task won't see it and it will be gone. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Rails and PHP app under the same domain
On Fri, Apr 2, 2010 at 7:59 AM, Yiannis istoseli...@gmail.com wrote: Hello I have a rails site in a domain like http://domain.com/ which is in one folder the whole application and a blog (wordpress - php application in another folder) under http://blog.domain.com/. How can I do http://domain.com/blog/ shows up the php application? You could have rails redirect from domain.com/blog to blog.domain.com But it might be better to do this at the http server layer. For example if you are using apache as the front end, you could use mod_rewrite to route blog urls the the blog before the rails app ever sees them. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Re: Superclass mismatch with Rails 3
On Fri, Apr 2, 2010 at 8:02 AM, Phil Ostler li...@ruby-forum.com wrote: Indeed you are right, changing the name of my application has fixed this. Thank you! Reason for me naming it Rails is because I have separate folders in my project development for different elements (e.g. Rails, Database Schema, Flex) and it always worked in Rails 2 fine for me this way. I've used rails3b before but was mix and matching gem versions to try and get around this problem. Now running Ruby 1.9.1-p378-rc2 with Rails 3.0.0.beta2! From what I've read 1.9.1 is NOT recommended for use with Rails3 beta 2, they want us to use the latest pre-release version of 1.9.2 instead. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] undefined method `each' for :String
On Wed, Mar 31, 2010 at 2:21 PM, ES emsto...@gmail.com wrote: I implemented creating an object within another object according to this Railscast: http://railscasts.com/episodes/74-complex-forms-part-2 but I'm getting this error after I submit. Any ideas? undefined method `each' for :String I'm guessing that you are using Ruby 1.9, Ruby 1.8 had a String#each method, Ruby 1.9 does not, you need to use each_line instead. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Joining Multiple Tables
On Tue, Mar 30, 2010 at 3:03 PM, khagimoto kumi.hagim...@gmail.com wrote: I'm trying to replicate a join in RoR that I can do in SQL very simply. Three tables/models that I have are: Users, Users_Activities, Activities and Codes. Users and Activities have appropriate has_many associations through Users_Activities model, so it's easy to do a join to get all activities for a given user. Codes, on the other hand, is a different story. It's kind of a repository of all codified data. For example, the Activity table has a Activity Type field that is an integer field. To get the actual Activity Type name, you have to look it up in the Codes table like so (joining with user table to get all activities for user id 1): select activities.*, codes.name from activities, users_activities, codes where users_activities.user_id = 1 and users_activities.activity_id = activities.id and activities.activity_type = codes.id I can do part of the above query if i don't include the Codes table like so: Activity.all(:joins = :users_activities, :conditions = {'users_activities.user_id' = 1}) How do I also join Codes? class User AcrtiveRecord::Base has_many :user_activities end class UserActivity ActiveRecord::Base belongs_to :user belongs_to :code, :foreign_key = activity_type end Activity.find_all_by_user_id(1, :include = :code) This will return a collection of all of the activities for user#1 with attached instances of the code for each activity -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Re: Joining Multiple Tables
On Tue, Mar 30, 2010 at 6:35 PM, khagimoto kumi.hagim...@gmail.com wrote: Not sure if I understand this completely.. The activity_type field is in Activity. If I try to do as you suggested, it complains that Association named 'code' was not found when it tries to execute the line Activity.find... Did you add the association declaration: belongs_to :code, :foreign_key = activity_type to the Activity class? That says that the activities table has a foreign key field called activity_type which is the key of a record in the codes table. And it creates the association called code which the error message is complaining about. On Mar 30, 1:05 pm, Rick DeNatale rick.denat...@gmail.com wrote: On Tue, Mar 30, 2010 at 3:03 PM, khagimoto kumi.hagim...@gmail.com wrote: I'm trying to replicate a join in RoR that I can do in SQL very simply. Three tables/models that I have are: Users, Users_Activities, Activities and Codes. Users and Activities have appropriate has_many associations through Users_Activities model, so it's easy to do a join to get all activities for a given user. Codes, on the other hand, is a different story. It's kind of a repository of all codified data. For example, the Activity table has a Activity Type field that is an integer field. To get the actual Activity Type name, you have to look it up in the Codes table like so (joining with user table to get all activities for user id 1): select activities.*, codes.name from activities, users_activities, codes where users_activities.user_id = 1 and users_activities.activity_id = activities.id and activities.activity_type = codes.id I can do part of the above query if i don't include the Codes table like so: Activity.all(:joins = :users_activities, :conditions = {'users_activities.user_id' = 1}) How do I also join Codes? class User AcrtiveRecord::Base has_many :user_activities end class UserActivity ActiveRecord::Base belongs_to :user belongs_to :code, :foreign_key = activity_type end Activity.find_all_by_user_id(1, :include = :code) This will return a collection of all of the activities for user#1 with attached instances of the code for each activity -- Rick DeNatale Blog:http://talklikeaduck.denhaven2.com/ Twitter:http://twitter.com/RickDeNatale WWR:http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn:http://www.linkedin.com/in/rickdenatale -- 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. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] How to get last url??
On Fri, Mar 26, 2010 at 2:17 PM, Rutvij Pandya li...@ruby-forum.com wrote: Dear all, How can I get lastly accessed url on my current page. i.e. user is on 'Posts' page now if user wants to add new post for that user needs to login first... for that user 'll be redirected to login page...Now after getting logged in successfully user must be redirected to the 'Posts' page again so that now he can add new post.. In a controller you can do request.url -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Testing best practice
On Thu, Mar 18, 2010 at 7:57 AM, Rails Fun rails...@yahoo.com wrote: so what is the best way test bed to use for a rails project? i'm thinking of using Rspec and Cucumber, but where do you do the unit tests? in Rspec? Yes -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Re: Re: Re: Three submits, one controller
On Wed, Mar 10, 2010 at 8:22 AM, Colin Law clan...@googlemail.com wrote: On 10 March 2010 12:44, Neil Bye li...@ruby-forum.com wrote: Colin Law wrote: . Do you mean you have two submits in one form? You had not mentioned that before, or I missed it. Colin There are three separate forms on three pages but they all refer to the stories_controller.rb . In the controller I a 'create' method for the 'new' page The 'update' method is for comments submitted on the 'show' page. Now I want an 'edit' page with a submit. What method can I use and how does the submit on the edit page know how to use it. Attachments: http://www.ruby-forum.com/attachment/4562/stories_controller.rb You can specify the action in the form_for statement. However, as I suggested earlier I would not use a separate action anyway. If you look at your code for update and add_comment you will see there is a lot of similarity. I would combine add_comment into update and test params[:comment] to see whether to add the comment or not. A more conventional approach here might be to treat comments as nested resources, and have a Comments controller. http://railscasts.com/episodes/139-nested-resources And if you substitute Story for Article in Ryan's example app in the railscast, it would appear to pretty much be the OPs problem. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Re: making a generic comment model
On Mon, Mar 8, 2010 at 10:20 PM, eggie5 egg...@gmail.com wrote: thanks you! polymorphic association it's called you say. It works now. You might want to have a look at the acts_as_commentable plugin http://github.com/jackdempsey/acts_as_commentable It expands on this idea, but uses commentable rather than attachable as the association name, which I think makes a bit more sense, and is less likely to collide if you decide that one or more of the models which can have comments can also have uploaded files as attachments. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Attaching, literally, a link
On Mon, Mar 8, 2010 at 3:40 PM, theduz duzenb...@gmail.com wrote: attachment :content_type = message/external-body; access- type=URL; do |a| a.transfer_encoding = binary a.body = URL=\http://www.biltd.com\\n\nContent-type: text/html \nContent-Transfer-Encoding: Binary\n\nTHIS IS NOT THE BODY!\n end Content-Type: message/external-body; access-type=URL Content-Transfer-Encoding: Binary Content-Disposition: attachment; access-type=URL URL=http://www.biltd.com; Content-type: text/html Content-Transfer-Encoding: Binary THIS IS NOT THE BODY! Which doesn't look quite like RFC2017 shows. There seems to be an extra new line, and a couple extra headers. RFC2017 expects the mime body to look like: Content-type: message/external-body; access-type=URL; URL=http://www.foo.com/file; Content-type: text/html Content-Transfer-Encoding: binary THIS IS NOT REALLY THE BODY! Not tested: attachment :content_type = message/external-body; access- type=URL; URL=URL=\http://www.biltd.com\; do |a| a.transfer_encoding = binary a.body = THIS IS NOT THE REAL BODY!\n end -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Upgrading rails project - version 1.2.6 to current (2.3.5)
On Sun, Mar 7, 2010 at 3:23 PM, Paul Jonathan Thompson rails...@gmail.com wrote: Can anyone please advise me what is involved in up grading a project from version 1.2.6 to current (2.3.5). The project is pretty much vanilla code and does not use plugins. Are there scripts that can do the job (or pull out incompatibilities). Any websites or blogs that point the way or should I just bite the bullet and rewrite? Reason for wanting to upgrade is that I now do want to add features and start using plugins and of cause a lot of the plugins that I would like to use require rails 2.3+ First, I'd recommend doing this in steps, first upgrade to Rails 2.0, then 2.1, then 2.3.5 Why? Rails 1.x to 2.0 was a pretty big change, for some apps 2.0 to 2.1 was even bigger because of some subtle and significant changes to ActiveRecord. So I'd do each step, and pause to make sure your tests are working. You DO have tests don't you? Googling for rails upgrade, flushed out this article on the first step, more specific searches are likely to find articles on the others: http://www.sitepoint.com/blogs/2008/01/25/upgrading-to-rails-20-a-recipe/ It includes a pointer to a rake task written by Geoffrey Grossenbach (of Peepcode fame) which find stuff deprecated in 2.0. Recent versions of Rails have rake tasks to aid in upgrading e.g. in 2.3.5 rake rails:update # Update both configs, scripts and public/javascripts from Rails rake rails:update:application_controller # Rename application.rb to application_controller.rb rake rails:update:configs # Update config/boot.rb from your current rails install rake rails:update:generate_dispatchers # Generate dispatcher files in RAILS_ROOT/public rake rails:update:javascripts # Update your javascripts from your current rails install rake rails:update:scripts # Add new scripts to the application script/ directory I don't recall if 2.0 had these, or at what point they were introduced. HTH -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Re: RegEx help to detect First and Last name
On Fri, Mar 5, 2010 at 10:06 PM, Allan Last li...@ruby-forum.com wrote: Thanks for the suggestions. I'm going to play around with this. On the most part, I'm doing detection for scenarios with two names, so names like Robert De Niro will not come up. I'm pretty sure, though that the actor would say he HAD two names, and his first name was Robert and his last name was De Niro -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Re: Why all columns of joined table get instantiated as String?
On Fri, Mar 5, 2010 at 9:07 AM, Jack Shanter li...@ruby-forum.com wrote: Thanks, Fred. I suppose I'll stick with views and conversions. Why not pages = Page.all(:include = :book) pages.first.book.year -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Re: undefined method `build' for nil:NilClass
On Fri, Mar 5, 2010 at 8:12 AM, mac care4u.jodh...@gmail.com wrote: 3) def new �...@content_master = ContentMaster.new �...@metadata = @content_master.metadata.build @metadata = @content_master.build_metadata -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] RegEx help to detect First and Last name
On Fri, Mar 5, 2010 at 12:16 PM, Hassan Schroeder hassan.schroe...@gmail.com wrote: On Thu, Mar 4, 2010 at 10:53 PM, Allan Last li...@ruby-forum.com wrote: I run into problems where the name is close to the beginning of the sentence: Having John Smith over for dinner. --- This will look at Having John Getting Jane Smith ready for school. --- This will look at Getting Jane Do you know how to do a RegEx where it will ignore the first word whenever three capitalized words are next to each other? Thanks! You know this is not something you're going to solve with regular expressions, though, right? :-) San Francisco's Jane Smith, quoted in Broder's Washington Post article, said ... You need a lot more heuristics than a simple RegEx to reliably find names in a block of text. Some other cases to consider John Phillip Sousa (or if you're a kid a heart John Jacob Jingelheimer Smith) not to mention Spanish names which can have MANY parts. Robert De Niro Jesus Mary and Joseph Surnames with origins in some languages don't start with a capital Michael Henry de Young - Dutch Wernher von Braun - German -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Re: Re: Why all columns of joined table get instantiated as String?
On Fri, Mar 5, 2010 at 2:12 PM, Jack Shanter li...@ruby-forum.com wrote: Rick Denatale wrote: Why not pages = Page.all(:include = :book) I usually need to filter by, let's say, a certain library: @pages = Page.all( :select = 'pages.id, pages.no', :joins = :book, :conditions = books.library_id = #{1} ) AR will generate: SELECT pages.id, pages.no FROM pages INNER JOIN books ON books.id = pages.book_id WHERE (books.library_id = 1) So the join has already been done. Wouldn't :include make a redundant query? Then just change the joins to include: Page.all( :include = :book, :conditions = [books.library_id = ?, 1] ) Which will both allow you to refer to the books fields in the where clause, and return an collection of object graphs rather than page object corrupted with fields they shouldn't have. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Re: Re: Works in Ruby but not in Rails More info
On Thu, Mar 4, 2010 at 5:42 AM, Michael Pavling pavl...@gmail.com wrote: On 4 March 2010 10:29, Neil Bye li...@ruby-forum.com wrote: You have a nil object when you didn't expect it! The error occurred while evaluating nil.login Extracted source (around line #2): 1: p id=story%= comment.content %/p 2: pSubmitted by:%=comment.user.login %/p You're being told that you have a nil object on line 2 when evaluating the login method. So user is nil - and I'd guess we'd expect it to be a User object... I can't see anywhere in the controller (CommentController I assume) that assigns a user to a comment, so that's a good place for you to start. Make sure somewhere does something along the lines of comment.user = current_user... even hard-code comment.user_id to a known value to check that when there *is* a user on the comment, the view displays correctly. Then you can go back and make sure the comment is being built properly. It might also be an ideal to add validates_presence_of :user to the comment model and either use save! or check the result of save when creating the comments. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] MatchData providing unexpected result
On Sun, Feb 28, 2010 at 12:16 PM, RichardOnRails richarddummymailbox58...@uscomputergurus.com wrote: Hi, Below are two tests of using MatchData. The first is essentially Hal Futon's taken from The Ruby Way, 2nd. ed. [Thanks, Hal]. In particular, m[0] returns the string being searched. The 2nd is my humble use. For mine, m[0] returns the search pattern, it seems, I can't anything in the code to account for this difference. I'm expecting the first kind of response in a Rails app I'm working on, but I'm getting the second kind of response. Any ideas? m[0] doesn't return the string being searched, it returns everything which the entire pattern matched. In the first case /(.+[aiu])(.+[aiu])(.+[aiu])(.+[aiu])/i entirely matches Fujiyama in the second case /noun/i only matches a portion of the string, so that's what is the value of m[0] -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Rails acts_as_* plugins, with parameters
On Thu, Feb 25, 2010 at 7:32 AM, Paul PH li...@ruby-forum.com wrote: Hi all, I'm trying to write a plugin which will allow me to specify: acts_as_item :option=:value i need to be able to access the :options=:value hash from instances of the model also. I've tried with class_eval in the plugin, but can't get it working. I'm calling acts_as_item(options), and that method can see the options passed from a model. Then inside the class_eval, I'm adding a method (def self.configuration) which returns the options hash. I thought from an instance, I'd be able to do instance.class.configuration which would then return said options hash. Any ideas? thanks for reading. module Item #called by active record for us def self.included(base) base.extend ClassMethods end module ClassMethods def acts_as_item(options = {}) configuration = {:option=:value} class_eval { include InstanceMethods def self.configuration I think you want this to be def configuration Since this is in a module extended by the class. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] website down?
It looks like somehow you don't have all of rails installed. What's in the vendor/rails directory on the server? You should have something like: vendor rails actionmailer actionpack activerecord activesupport railsties What version of rails? On Thu, Feb 25, 2010 at 1:48 PM, Johnny Patruno li...@ruby-forum.com wrote: Hi, I know it could be an annoying question for skilled developers but we have a major issue... this website ( http://www.swissdnabank.com ) worked fine til this afternoon, then suddenly appeared this error page... what could have happened? -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Active Record - Select by multiple days of week
On Tue, Feb 23, 2010 at 4:33 PM, sgallo1 sgal...@gmail.com wrote: Wondering what would be the best way to implement this. I need to store that an item occurs on a specific day of the week or everyday. Say in the model we have a title and a day of week. I was thinking doing a 0-7 in my model for the item representing the day of the week with zero being everyday. For a selection criteria say I wanted to search for every title starting on Monday, Wendsday and Friday where each day on the selection screen would be checkbox representing the days Monday - Sunday and Everyday (clicking everyday would remove the checkboxes should someone select everyday and a day of the week) What would the active record query look like to dynamically pass in the days of the week selected should say mon, wed and fri get selected given that what they selected is past to the controller in a days_of_week variable. I'm not totally tied to the idea of storing the day as a number so if anyone has any better implementations of this I'm listening. Something like # get weekdays_selected to be an array of the numbers corresponding to the checked boxes plus 0 # For example if you wanted to find events on Mondays and Wednesdays, weekdays_selected should be: # [0, 2, 3] Items.all(:conditions = [weekday IN ?, weekdays_selected]) or if you're using Rails3 Items.where(weekday IN ?, weekdays_selected) If it were me I might think about tweaking this a bit and use 7 instead of 0 for any day, since Ruby's Date and Time use 0 for Sunday through 6 for Saturday. Caveat, none of the above code has been tested, and I've only had two sips of coffee this morning. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Re: Re: Re: Passing paramter but without GET
On Mon, Feb 22, 2010 at 3:19 PM, Heinz Strunk li...@ruby-forum.com wrote: I tried map.connect '/actions/:action_id/add_date/:date', :controller = 'actions', action = 'add_date' instead of map.connect ':controller/:id/:action/:action_id' but that didn't work cause that's not what's not working. I need to know how the link_to has to look like so the link_to URL looks like: http://localhost:3000/actions/980190963/add_date/2010-02-23 Use a named route map.add_date_to_action '/actions/:action_id/add_date/:date', :controller = 'actions', action = 'add_date' And then: link_to Add, add_date_to_action_url(@action.id, Date.today.to_s) -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Re: how to validate uniqueness across multiple columns in ActiveRecord?
On Mon, Feb 22, 2010 at 4:54 PM, Grary grary.sti...@gmail.com wrote: Thanks Fred. What do you mean by 'use a unique index'? What I am concerned about is logical uniqueness, i.e., persist only data objects with a unique combination of attributes. So if I understand correctly, lets say there are two attributes a, and b You want to make sure that no two models have the same COMBINATION of values for a and b, so having two models with: a = 1, b = 2 a = 1, b = 3 would not be a conflict If that's the case then the standard validation class Widget ActiveRecord::Base validates_uniqueness_of :a, :b end wouldn't work since it tries to prevent saving two models with the same value of a, OR with the same value of b And even if that's not what you're trying to do, and you're ok with the example being a conflict, Fred's point is that validates_uniqueness_of doesn't guarantee uniqueness if two users try to save conflicting records simultaneously. The validation works by first trying to find a record with the value, and if it doesn't find it inserting the 'new' record, and this can fail due to a concurrency hole. To fill this hole requires leaning on the database server, and the way to do that in SQL is by having a unique index on the table which covers the column or columns you want to be unique. This assume you are using a database which supports it, e.g. MySql. To create an index you can create a migration which includes a statement like add_index :widgets, [:a, :b], :unique = true) Assuming that the table name for the model is 'widgets' Now if you do this, you also need to be aware that if you try to save a record with a uniqueness conflict the save will raise an ActiveRecord::StatementInvalid exception, which you'll need to rescue and do something like telling the user of the conflict so that he can resolve it. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Enabling debugger in initializers
On Sat, Feb 13, 2010 at 1:46 AM, Ralph Shnelvar li...@ruby-forum.com wrote: Is it possible to get the debugger to run when initializers are being executed? The -u option on script/server to turn on the debugger is too late, since it doesn't seem to bring the debugger in until after initializers run. but you should be able to do something like rdebug script/server which will give you control in the debugger at the beginning. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] no such file to load -- linguistics.rb
On Fri, Feb 12, 2010 at 12:08 AM, Saboor saboorahmeda...@gmail.com wrote: hi i want to convert no to words so using linguistics.rb; while using it linguistics.rb i am receiving an error no such file to load -- linguistics.rb i have installed gem for it linguistics 1.0.8 code= require 'linguistics.rb' Linguistics::use( :en ) any fix? Unless you are using Ruby 1.9 you need to require 'rubygems' in order to load gems. You can do this either in the code itself or via a command line argument to ruby $ ruby -e'require rubygems;p require linguistics.rb' -e:1:in `require': no such file to load -- linguistics.rb (LoadError) from -e:1 $ruby -rubygems -e'p require linguistics.rb' true $ruby -e'require rubygems;p require linguistics.rb' true -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Re: plural table names?
On Thu, Feb 11, 2010 at 9:47 AM, Jeff cohen.j...@gmail.com wrote: Definitely ignore as many conventions as you can, and thereby make development as hard as possible on yourself. Ah yes, Consternation over Convention! -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Session based Routing
On Thu, Feb 11, 2010 at 11:56 AM, Greg Donald gdon...@gmail.com wrote: On Thu, Feb 11, 2010 at 7:23 AM, LeonS leonard.stellbr...@gmail.com wrote: I'm developing a site with a Login on the frontpage, so when you logged in you will see another thing than if you are not logged in. Something like: %= render partial = session[:user_id] ? 'logged_in' : 'something_else' % The normal way to do this is to handle it at the controller level in a before filter set in the ApplicationController, used to check that the user is logged in, via the session, and/or a token, and or via basic http authentication depending on the requirements of the application, and redirects to the login url if not. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: Re: [Rails] undefined method join
On Thu, Feb 11, 2010 at 12:58 PM, JohnMerlino stoici...@aol.com wrote: So why does the example in rails guide work and not mine, where I tried to copy as close to it as possible? All I'm trying to do is update another table from a form. Thanks. If you show us the walkback, and not just the exception message, maybe somebody will have a better chance to help. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] What is the appserver for production that works best with Rails3?
On Thu, Feb 11, 2010 at 6:29 PM, Joshua Partogi joshua.part...@gmail.com wrote: Hi all, In development I used webrick, but I suppose I don't want to use that in production. With rails2 I would use mongrel or thin. But as far as I know, mongrel is no longer developed? So are we left to thin these days? Does thin plays nicely with Rails3? What is your latest experience on this? Thank you very much for the insights. For production I'd use Passenger (a.k.a. modrails) with Ruby 1.9. Should work fine with Rails3 since it drives the rack interface. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Re: some success at last, and some questions
On Tue, Feb 9, 2010 at 4:31 AM, Bigos ruby.obj...@googlemail.com wrote: On Feb 9, 9:24 am, Frederick Cheung frederick.che...@gmail.com wrote: On Feb 9, 9:20 am, Bigos ruby.obj...@googlemail.com wrote: So here are my questions: 1 Is it appropriate to put such code here? No. You don't really want any code in your view, other than the very bare minimum. Sounds like you want to put a l lot of this in a view helper Thanks for prompt reply, I don't want to put any more code than that. Just want a simple change of CSS style depending which page is being displayed at the moment. Well you already have WAY too much code in the view, and that code deals with stuff like urls/routing which really shouldn't be the business of a view. The way I approach the issue of highlighting the active tab (which it looks like is what this code is trying to do, would be to have a helper to generate the html, which uses either the controller name (if there's a one-one correspondence between controllers and tabs) or a current_tab instance variable set by the controller. And the helper should use path/url helpers rather than coding absolute uris. So something like this. First make sure that routes.rb has a sensible routing for the various urls. Just an example: map.home '/', :controller = 'welcome', :action = 'show' map.how_we_work '/how_we_work', :controller = 'welcome', :action = 'our_process' map.contact_us 'contact_us', :controller = 'contacts', :action = 'index' Note that these route are just for example purposes, I'd probably do it quite differently, but that's not relevant to the current problem. In fact, the whole point is that the routing is something which might well change over the life of the app, and that's one of the things which makes view code like your starting point fragile. Then in the controller(s) in the action methods which handle the various end points class WelcomeController ApplicationController def show @current_tab = 'Home page' end def our_process @current_tab = 'How we work' end end class ContactsController ApplicationController def index @current_tab = 'Contact Us' end end in a helper, probably application_helper.rb def tab_link(tab_name, target) link_to(tab_name, target, :class = tab_name == @current_tab ? 'current_tab' : 'jtab') end def navigation_bar [ ['Home page', home_path], ['How we work',how_we_work_path], ['Contact Us', contact_us_path ] ].map {|tab_name, target | tab_link(tab_name, target)}.join(\n) In the view: %= navigation_bar % Again this is probably not exactly the code I'd come up with, but it's close to what you started with and adheres much better to what the responsibilities of routes, controllers, and views should have in a Rails app. IMHO -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] RoR physical development environment advice
On Sat, Feb 6, 2010 at 11:17 PM, john h johnhoec...@gmail.com wrote: Hi Folks, I'm a RoR noob (and pretty much a progrmming noob) who has been working since 7am to get a development platform set up on win 7 so that I can follow the lynda.com ruby on rails essential training tutorials. It has been a pretty cruel process, and still incomplete. I just looked at the lynda.com site, and the Ruby on Rails tutorials all seem to have been released in 2007, with the one in question having been released in January of that year. So that means it HAS to be using Rails 1.x A lot of water has flowed under the Rails Bridge since then, it's probably a wise course to look for more up-to-date tutorials, one good place to start would be http://guides.rubyonrails.org/ But make sure you are following the current release version and not the edge version. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Design Pattern
On Wed, Feb 3, 2010 at 3:58 AM, eggie5 egg...@gmail.com wrote: Hi, I have a collection of arbitrary objects that have a date attribute. I want to display these objects by month. For example @things=Thing.all Now I want to display in a table all the things by month - how can I do this? the problem isn't making a table or anything it's just the logic for getting the min and max range for all the dates in things and then finding the monthes to use for the scale and etc. Please give suggestions. Unlike some of the other responders, I'm going to take your arbitray objects to mean that they aren't necessarily ActiveRecord models, and therefore SQL solutions don't apply. Assuming that each of these Ruby objects has a method date which returns either a Date, DateTime, or Time object then something like @things.group_by {|thing| thing.date.to_date.beginning_of_month } while return a hash whose keys are the dates which have at least one thing, and whose values are arrays of things whose dates fall within the month. If you know that the things all will return a Date from .date then you can leave out the to_date in the expression. def initialize(date) @date = date end attr_reader :date end = nil things = [Date.today, 2.days.from_now, 5.days.ago].map {|d| Thing.new(d)} = [#Thing:0x0101524828 @date=Wed, 03 Feb 2010, #Thing:0x01015247f0 @date=2010-02-05 14:06:22 -0500, #Thing:0x0101524780 @date=2010-01-29 14:06:22 -0500] things.group_by {|t| t.date.to_date.beginning_of_month} = { Mon, 01 Feb 2010=[#Thing:0x0101524828 @date=Wed, 03 Feb 2010, #Thing:0x01015247f0 @date=2010-02-05 14:06:22 -0500], Fri, 01 Jan 2010=[#Thing:0x0101524780 @date=2010-01-29 14:06:22 -0500] } HTH -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Suggestion: Merging Rails application templates with generator functionality
On Mon, Feb 1, 2010 at 6:11 AM, Kristian kmand...@gmail.com wrote: Been working a bit lately on implementing Rails app. templates and generators. It is clear there is a lot of overlap and that features from generators could be used in app. templates and vice versa. I will try to port some of the generator features such as the template function (executing an .erb file and saving the resulting content as a file in a specific location) to be used with app. templates, perhaps as an app. templates extension (gem?). What do you think? Is this already possible and convenient by other means? As I understand it, Rails 3 is making generators and app templates work on the same code base. http://caffeinedd.com/guides/331-making-generators-for-rails-3-with-thor http://benscofield.com/2009/09/application-templates-in-rails-3/ -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Re: View Helper Scope
On Mon, Feb 1, 2010 at 8:45 AM, Michael Schuerig mich...@schuerig.de wrote: On Monday 01 February 2010, Marnen Laibow-Koser wrote: Michael Schuerig wrote: On Sunday 31 January 2010, Marnen Laibow-Koser wrote: If you only include specific helper modules, you can have multiple methods with the same name, but different implementations. This can be useful in order to avoid inadvertently stepping on another method with the same name in an overcrowded helper namespace. Of course. No argument there. I just don't understand your procedural claim. Well, helper methods *are* procedural. All methods are procedural. No. Strictly speaking, helper methods ought to be called helper functions as they are not attached to specific objects. No, helper methods are indeed methods. They are defined in modules, and those modules are included into views by the controllers, and can be explicitly included by other classes. If this were not the case then the helpers couldn't reference view/controller instance variables, which they can. The OPs question was why duplicated method names weren't resolved according to some perceived inheritance hierarchy. The resolution just follows standard ruby semantics. 1. First look for a singleton method in the receiver object. 2. If that fails look for an instance method defined by any modules which the object extends, in the reverse chronological order of extension. 3, If that fails set the class to examine to the class of the object 4. look for an instance method in the class to examine 5. If that fails look for an instance method defined by any modules which the class to examine includes, in the reverse chronological order of inclusion. 6. If that fails and the class to be examine has a superclass, set the class to examine to that superclass and go to step 4, otherwise send a method_missing to the receiver object. Now normally, a controller will include the helper(s) associated with it's superclass (usually ApplicationController and therefore ApplicationHelper), and the helper associated with itself in that order. But this default can be change using the ActionController::Base#helper method (which in Rails 2.x is actually defined in the module ActionController::Helpers. It's not uncommon for a Rails app to invoke helper :all in its ApplicationController which includes all helpers in the app/helpers directory and it's subdirectories in the order they are enumerated by Dir.[] with a recursive glob argument. In this case whichever helper method with the name in question was defined by the last included module will win. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Re: View Helper Scope
On Mon, Feb 1, 2010 at 10:20 AM, Frederick Cheung frederick.che...@gmail.com wrote: On Feb 1, 3:11 pm, Rick DeNatale rick.denat...@gmail.com wrote: No, helper methods are indeed methods. They are defined in modules, and those modules are included into views by the controllers, and can be explicitly included by other classes. Aren't all 'functions' technically methods in ruby ? Of course. My point is that helpers are REALLY methods of the instance of view, have access to it's state, and all the other rights and privileges of an instance method. Yes, ruby 'functions' are really private instance methods which get defined in the Object class, and module functions (as in Module.module_function) are methods of an instance of Module, but helpers are not 'functions' in either of those senses. --- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Re: Getting Started needs Rails 3.0, but gem install rails installs Rails 2.3.8
On Mon, Feb 1, 2010 at 11:53 AM, Frederick Cheung frederick.che...@gmail.com wrote: On Feb 1, 4:34 pm, fearless_fool rdp...@gmail.com wrote: - The Guide should explain how to download Rails 3.0 (iff it is stable) - The Guide should offer a pointer to Rails 2.3.8 compatible examples - The Guide should be rolled back to Rails 2.3.8 until Rails 3.0 is the main version On the front page of guides.rails.info it says ' There are two different versions of the Guides site, and you should be sure to use the one that applies to your situation: Current Release version – based on Rails 2.3 Edge version – based on the current Rails master branch with links to both. This is true, but the UI design leaves a bit to be desired. When you click on either link the page doesn't change to show you which version you've selected. Actually I lied a little bit. The only difference is that if you click the Current Release Version link the title just above says Ruby on Rails guides and when you click on Edge Version it changes to: Ruby on Rails Guides Which I guess makes it perfectly clear G -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Re: Are class variables session specific?
On Sat, Jan 30, 2010 at 5:08 AM, Frederick Cheung frederick.che...@gmail.com wrote: On Jan 30, 7:25 am, Ralph Shnelvar li...@ruby-forum.com wrote: I'm trying to wrap my head around what information is session specific and what isn't. If I do User::x = 1 will User::x == 1 for all sessions on the same machine? I think it is the same on the same, but I'd like confirmation. It will be the same for all requests handled by that particular instances. If you have a pool of passenger/mongrel/thin/unicorn/etc instances then each one would have a different value. And different requests for the same session might well run on different instances, so see different values. Same problem with the suggestion to use thread local variables made by a responder to this thread. I'm pretty sure that the only way to deal with values which have to be seen between requests is to either put them in some persistent storage on the server (e.g. the DB, SQL or noSQL), or in the session and let the browser give it back to you. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Doint something with each field in form as it is entered
On Sat, Jan 30, 2010 at 2:02 PM, Ralph Shnelvar li...@ruby-forum.com wrote: Is there a callback or some mechanism that will allow me to modify a view once a field in a form is finished asumming that there are multiple fields in a form. As a silly example, let's say the bacground of the filed is white by default ... but once the user goes on to the next field, then make the background of that field red if the number of characters in the field is even. Well this would almost certainly have to be done in the browser using JavaScript so it's not really a Rails question. Most Rails apps use either the Prototype JavaScript framework (since that's what the ajax helpers use), although the modern trend seems to be to use jQuery (and Rails 3 will make changing JavaScript frameworks much easier). If you google for prototype field validation and jquery field validation you'll come up with serveral plugins for both frameworks. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] git clone locally
On Tue, Jan 19, 2010 at 1:38 AM, Easebus ease...@gmail.com wrote: Thanks all. I found out that I needed to use sudo before git in order for the -local option to work in my case. BTW, what is the most active git support group? I looked on Google group but couldn't find one. Thanks much. There IS a git users group on google groups: http://groups.google.com/group/git-users -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] belongs_to (polymorphic) or has_many (through)
On Tue, Jan 19, 2010 at 12:38 PM, tiekuhn nilsk...@gmail.com wrote: Hi, I'd be sooo happy I any of you could help me out with a problem I'm currently stuck with :-) ### Basic info ### I'm on Rails 2.3.5 and love using the formtastic formbuilder :-) ### What I'm working on ### I'm currently trying to build a little demo app where my friends and I are able to manage all the things we borrowed each other. (I know there are apps like this on the internet, I just wanted to built my own to get used to rails :-)). So wanted to build a form where I can enter: - the name of the thing I'm borrowing to someone - who I'm borrowing the thing to -- I set up the Models User name . (default hobo user model) Loan name:string reminder:date ### PROBLEM ### Now I wanted to set up 2 relations between the model. - Who is giving away the loan - Who borrows the loan -- What do you think would be the most clever way to set up these relations for my use case? ### Idea 1 ### Loan belongs_to :lender, :polymorphic = true belongs_to :borrower, :polymorphic = true User has_many :loans, :as = :lender has_many :loans, :as = :borrower -- Does this work anyway (User.loans would be ambiguous, right?) -- how could I create a form to create a new Loan and select the borrower from a select (the app would assign me as the lender in the controller or by hidden field I guess) ### Idea 2 ### Loan has_many :loan_assignments, :dependent = :destroy has_many :users, :through = :loan_assignments, :accessible = true User has_many :loan_assignments, :dependent = :destroy has_many :loans, :through = :loan_assignments -- How do I restrict the form, so I can only select 1 borrower in /loans/new ??? ### Idea 3 ### Loan belongs_to :lender, :class_name = User belongs_to :borrower, :class_name = User User has_many :lendings, :class_name = Loan, :foreign_key = :lender_id has_many :borrowings, :class_name = Loan, :foreign_key = :borrower_id -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Loading Model in Yaml
On Mon, Jan 18, 2010 at 2:04 AM, tispratik tispra...@gmail.com wrote: Am loading the model called Decode in my yaml file. When i run the rake db:seed, it runs fine in windows. But dont know why it fails in unix. Any ideas? params.yml % require 'Decode' i = 0 % Filter_Param%= i=i+1 %: id: %= i=i+1 % filter_param: chapter_status disp_value: Active internal_param: modul_status internal_value: %= Decode::CHAPTER_STATUS_ACTIVE % sort_order: 1 In Unix: rake aborted! no such file to load -- Decode Case sensivity in the file name? Most operating systems, unlike WIndows treat file names, Decode.rb and decode.rb as different. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Using find - beginner's advice
On Tue, Jan 12, 2010 at 1:03 PM, Philip Hallstrom phi...@pjkh.com wrote: On Jan 12, 2010, at 9:46 AM, Steve Castaneda wrote: Owners has_one :widget and Widgets belongs_to :owner. @owners = Owner.all(:conditions = 'widget_id IS NULL') Would do it. Assuming that it's correct to say that if widget_id is null they have no widget -- this wouldn't catch instances where say an owner *had* widget, the widget was removed and the owners widget_id wasn't set back to null. No, I don't think that this will work given the database schema described. Widget belongs_to :owner Owner has_one :widget means that the widgets table has an owner_id colum , the owners table doesn't have a widget_id field. The has_one relationship is really just a has_many which adds a limit of 1 to the query. @owners = Owner.all.reject{|o| o.widget.nil? } Would also do it. This has the drawback that the DB is going to return *all* the owners and then filter them in ruby. Won't be as speedy as the first option. This will work, but as you point out it can be inefficient if there are a lot of owners. While it's possible to get this down to a single SQL query with the given db design, using an outer join and a carefully crafted conditions clause, it might be simpler just to reverse the relationship, as long as there is really a 1-1 cardinality relationship, it could just as well be Owner belongs_to :widget Widget has_one :owner with the concommittant db table changes. Then @owners = Owner.all(:conditions = 'widget_id IS NULL') would work. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Re: User a owns resource x; don't let user b see user a's resources...
On Wed, Jan 13, 2010 at 8:02 AM, Eduard Martini eduard.mart...@gmail.com wrote: Don't take the user id from the url. For example, don't do this: url: /show_friends/5 code: Users.find(5).friends But do this: url: /show_friends code: current_user.friends where current_user is the currently auth user. You know who is logged in, don't need to pass his id around. And for the use case which the OP raised, which is the show action, it should be: def show friend = current_user.friends.find(params[:id]) end which scopes the find to the user's friends. Similar comment for other actions like edit and update -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Re: Remove a restful action from map.resources
On Sun, Jan 10, 2010 at 2:47 PM, pharrington xenogene...@gmail.com wrote: On Jan 10, 1:51 pm, Ale Ds li...@ruby-forum.com wrote: Hi, my question is about routing: is it possible to remove a restful action from map.resources ? if few words: I have a City model, and I've declared in routes.rb file: map.resources :users then I obtain ALL restful action, but I don't need neither delete and update action. Do you know some way to remove them ? Thank you, Alessandro -- Posted viahttp://www.ruby-forum.com/. As far as you know you can't. Sure you can: map.resources :users, :except = [:delete, :update] there's also an :only option -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Pure, OpenID-only (password not a choice) Authentication?
On Sat, Jan 9, 2010 at 5:32 AM, Audrey A Lee audrey.lee.is...@gmail.com wrote: Hello list, Are any of you using OpenID to register and authenticate your users? I have found 2 projects on github which mix Rails with OpenID: http://github.com/tsechingho/authlogic_bundle http://github.com/binarylogic/authlogic_openid Both projects seem suited for providing a choice to the end-user: - Vanilla password based authentication - OpenID based authentication I want to implement the use-case where the end-user is allowed only OpenID based authentication. Some end-users are completely confused by the idea of having 2 ways to authenticate. And even the smart ones bump into a problem. They register, and then return in a month and forget if they were using a password or OpenID. So, I want to make it easy for them. They use OpenID or nothing. Actually, I want to make it even simpler: Yahoo-OpenID or nothing. Anyway I did the obvious thing. I tried to remove Vanilla password based authentication from each of the above projects. I ended up with 2 piles of broken software. So my question is, do you know of any projects or Rails starter kits which implement OpenID-only authentication? No I don't. And I believe that the openid advocates don't recommend this. The problem is that if the user's open id server is unavailable for whatever reason, he/she can't log in. Providing a password option for authentications is the openid equivalent of a 'forgot my password' mechanism. Just some food for thought. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Re: [Rails] Re: fields_for
On Sat, Jan 9, 2010 at 9:19 PM, pepe p...@betterrpg.com wrote: I am just learning how to use 'fields_for' so forgive me if I sound like I don't know what I'm talking about. My understanding is that 'fields_for' will iterate through the collection, hence working with one element/object of the collection in each iteration. If I need an attribute from the element/object at each iteration, how would I know which element to access with @my_object.my_collection? I don't even know if there is an index I can use to get to the element I need as in @my_object.my_collection [my_index], hence allowing me to do something like: No fields_for doesn't do any iteration. It's used for setting up a scope for one or more form fields for a different object than the one which scopes an outer form_for From the doc: % form_for @person, :url = { :action = update } do |person_form| % First name: %= person_form.text_field :first_name % Last name : %= person_form.text_field :last_name % % fields_for :person do |permission_fields| % Admin?: %= permission_fields.check_box :admin % % end % % end % So just like form_for doesn't do any iteration, neither does fields_for. Since you haven't told us any more about what you want to do, I don't know how to help any further. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.