Re: [Rails] Splitting a string

2010-01-07 Thread Patrick Doyle
On Thu, Jan 7, 2010 at 10:10 AM, Pale Horse wrote: > Example A: "Example One" > > What I need is a string method to remove " One" from that string so the > result is just "Example". > > I'm sure this is very simple but I just require a swift response. How about "Example One".split? --wpd -- You

[Rails] When/why/should I unit test validations?

2009-12-24 Thread Patrick Doyle
I run into this question each time I add a validation to my model. Should I add a unit test for that validation? On the one hand, I've heard/read the philosophy: "Q: What should I test? A: Only the stuff you care about working". On the other hand I've heard/read, "You don't need to test methods

Re: [Rails] t.references usage

2009-12-21 Thread Patrick Doyle
On Mon, Dec 21, 2009 at 9:40 AM, Thufir wrote: > While I'm not currently using the whole rails environment, I may utilize > the framework in the future.  In the meantime, I'm not clear on the > syntax for establishing a foreign key relationship for an active record > association using "t.reference

[Rails] How to customize the default scaffold?

2009-12-10 Thread Patrick Doyle
I know the scaffold generator is really only useful for beginners and/or very the preliminary state of a project, but I find that I use it a lot (especially, since I am still a beginner). There are a couple of things I find myself tweaking (or wanting to tweak, but never getting around to tweaking

[Rails] Re: model.find(:id) and model.find(:all) giving different result

2009-10-26 Thread Patrick Doyle
find(:all, ...) returns an array. find(:first, ...), or equivalently, find_manufacturer(some_id) returns a single item. try: @manufacturers = Manufacturer.find(:all, :conditions => {:id => params[:id]}) @manufacturers[0].show_manufacturer_details. --wpd --~--~-~--~~~-

[Rails] Re: Has many through

2009-10-20 Thread Patrick Doyle
guestlists is plural. event.guestslists returns a list of Guestlist records. If you want all of the notes for all of the guestlists for a particular event, (as an array) you might try something like: event.guestlists.collect(&:notes).flatten A true Rubyista could probably tell you a much more

[Rails] Re: Wierd HTML rendering problem

2009-10-20 Thread Patrick Doyle
On Tue, Oct 20, 2009 at 11:03 AM, theambler wrote: > Any ideas? Can you validate the page (say, at http://validator.w3.org/)? When I've run into weird things like this, I have restarted by development server on port 80 and pointed the validator at the page on my development server just to see w

[Rails] Re: collection_select fails to work for "edit" but works great for "new"

2009-10-20 Thread Patrick Doyle
You don't show your Part model, but I suspect that it looks something like: class Part < ActiveRecord::Base belongs_to :category end This allows you to do something like: @part = Part.find(params[:id]) @category = @part.category Note the subtle difference between what I wrote and what you

[Rails] Re: Rails 2.3 Model.touch(:column) always also updates :updated_at???

2009-10-16 Thread Patrick Doyle
In the mean time, can you work around this issue with something like: Create a separate table with a 1:1 relationship to your current table Migrate the field you want to touch to the new table. Touch the field in that table, which will leave the updated_at field in your original table alone. You

[Rails] Re: Reinstantiate controller during functional testing

2009-10-15 Thread Patrick Doyle
On Thu, Oct 15, 2009 at 1:06 PM, Marnen Laibow-Koser wrote: > I wonder.  RSpec and Cucumber are good even for small, simple stuff. > You're falling into the trap of assuming that the Rails core team is > perfect. > :-) That may be the case. I prefer to think of it as assuming that the Rails co

[Rails] Re: Reinstantiate controller during functional testing

2009-10-15 Thread Patrick Doyle
On Thu, Oct 15, 2009 at 12:48 PM, Marnen Laibow-Koser wrote: > Patrick Doyle wrote: > True to a point.  Have you played around with anything else out there > (RSpec?)? Not yet... My applications and their associated tests have been trivial and mostly been used as a learning tool for m

[Rails] Re: Reinstantiate controller during functional testing

2009-10-15 Thread Patrick Doyle
On Thu, Oct 15, 2009 at 12:27 PM, Matt Jones wrote: > On Oct 14, 1:19 pm, Patrick Doyle wrote: >> >> The problem is, there is an instance variable in my controller that is >> set during the handling of the first #add_lot_to_assembly action.  It >> remains set for th

[Rails] Re: Create and error_messages

2009-10-15 Thread Patrick Doyle
2009/10/15 Pål Bergström : > > Pål Bergström wrote: >> How should a create look like in order to get error_messages being >> displayed, going back to new and show the error message? I can't get it >> working so I must miss something. > > Could it be that I have to "turn off" RESTful somewhere? No,

[Rails] Re: Create and error_messages

2009-10-15 Thread Patrick Doyle
2009/10/15 Pål Bergström : > How should a create look like in order to get error_messages being > displayed, going back to new and show the error message? I can't get it > working so I must miss something. If the create fails, the controller could/should (re)render the "new" view. The "new" view

[Rails] Reinstantiate controller during functional testing

2009-10-14 Thread Patrick Doyle
... ok, I may be going about this the wrong way, or perhaps, a less efficient way than is optimal, but I would like to test a little bit of AJAX on one of my web pages. When I test this by hand, I bring up the page which shows a select box, I select an item from the drop down list, see another se

[Rails] Re: YANQ (Yet Another Newbie Question): Ordered entries in a database

2009-10-09 Thread Patrick Doyle
On Fri, Oct 9, 2009 at 9:01 AM, Billee D. wrote: >> Is there a non-standard way to do this specific to Sqlite3, MySQL, etc... ? > > You can use a view: > > http://dev.mysql.com/doc/refman/5.0/en/create-view.html > >From what I've read, using #default_scope and adding an index to my db seem to be

[Rails] Re: Using AJAX to generate complex forms interactively - any guides?

2009-10-09 Thread Patrick Doyle
On Fri, Oct 9, 2009 at 12:34 AM, Sijo kg wrote: > >> "if �...@sub_categories == nil". > > Hi >   Check @sub_categories.blank? > I'm pretty sure that #blank? is supposed to be used to check if a parameter is present or, if present, is blank. I think the method you're looking for here is #empty?

[Rails] Re: YANQ (Yet Another Newbie Question): Ordered entries in a database

2009-10-08 Thread Patrick Doyle
On Thu, Oct 8, 2009 at 7:59 PM, Hassan Schroeder wrote: > On Thu, Oct 8, 2009 at 4:50 PM, Patrick Doyle wrote: >> Is there a standard (or better) Rails way to indicate the same thing? > > See: > <http://ryandaigle.com/articles/2008/11/18/what-s-new-in-edge-rails-defa

[Rails] YANQ (Yet Another Newbie Question): Ordered entries in a database

2009-10-08 Thread Patrick Doyle
I know this is kinda basic, but who else could I ask besides you folks? Is there a standard SQL way to indicate that the records in a database should always be returned sorted by a particular column? Is there a standard (or better) Rails way to indicate the same thing? Is there a non-standard w

[Rails] Re: Using AJAX to generate complex forms interactively - any guides?

2009-10-08 Thread Patrick Doyle
On Wed, Oct 7, 2009 at 5:29 PM, ct9a wrote: > > thank you. Just had a look at it. > > Whenever you load data into objects in the controller (which gets > received by the view), how do you stop the first element from being > selected by default when you load the page? > > In relation to the exampl

[Rails] Re: How to debug unit (and other) tests?

2009-10-07 Thread Patrick Doyle
On Wed, Oct 7, 2009 at 12:45 PM, Colin Law wrote: > 2009/10/7 Patrick Doyle : >> Are there good tips and resources for debugging unit tests? > > Have a look at the rails guide on debugging.  Particularly the section > on ruby-debug. > Thanks. That's what I was loo

[Rails] Re: How to debug unit (and other) tests?

2009-10-07 Thread Patrick Doyle
On Wed, Oct 7, 2009 at 11:33 AM, Marnen Laibow-Koser wrote: > Patrick Doyle wrote: >> Are there good tips and resources for debugging unit tests? > > Just call the debugger from within your app code, or from the test > itself.  When the "debug" statement

[Rails] How to debug unit (and other) tests?

2009-10-07 Thread Patrick Doyle
I'm sorry if this sounds like a totally newbie question, but... Are there good tips and resources for debugging unit tests? Currently, I just fire up script/console using the "test" environment and just poke around randomly until I hit upon some inspiration. But I think there should be a better

[Rails] Re: Using AJAX to generate complex forms interactively - any guides?

2009-10-07 Thread Patrick Doyle
I learned how to create dynamic select boxes by reading http://pullmonkey.com/2008/3/30/dynamic-select-boxes-ruby-on-rails/ --wpd --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post

[Rails] Re: What is the most efficient way to split a table into 2 g

2009-09-29 Thread Patrick Doyle
On Mon, Sep 28, 2009 at 6:07 PM, Marnen Laibow-Koser wrote: > Patrick Doyle wrote: >> I have the following: >> >> @lot = Lot.find(params[:id]) >> >> part_nums = Part.all(:conditions => ["id <> ?", @lot.part.id]) >> >> I guess

[Rails] Re: What is the most efficient way to split a table into 2 g

2009-09-29 Thread Patrick Doyle
On Mon, Sep 28, 2009 at 6:18 PM, Marnen Laibow-Koser wrote: > Frederick Cheung wrote: > [...] >>> That's going to iterate over all of the records. �twice! �in interpreted >>> code! >> >> partition will do it in one > > Hey, that's good to know! > > If you need to do the partitioning in the DB, y

[Rails] Re: What is the most efficient way to split a table into 2 groups?

2009-09-29 Thread Patrick Doyle
On Mon, Sep 28, 2009 at 5:42 PM, Frederick Cheung wrote: >> On Sep 28, 10:32 pm, Patrick Doyle wrote: > > partition will do it in one > Thanks Fred, that's exactly what I was looking for. > Try both, benchmark them - don't take some random person on the > intern

[Rails] What is the most efficient way to split a table into 2 groups?

2009-09-28 Thread Patrick Doyle
I have the following: @lot = Lot.find(params[:id]) part_nums = Part.all(:conditions => ["id <> ?", @lot.part.id]) I guess I should mention that Lot :belongs_to => :part I was looking at the log following the execution of these two statements and I saw something like this: Lot Load (0.4ms) SE

[Rails] Re: How to ensure two tables reference the same record in a

2009-09-28 Thread Patrick Doyle
> No need for send here: > > def part(*args, &block) >  lot.part(*args, block) # may need an if block_given? > end > I was thinking that I would have to use #send since there is so much Ruby magic wrapped inside ActiveRecord in order to map column names to object attributes, but a very simple test

[Rails] Re: How to ensure two tables reference the same record in a

2009-09-25 Thread Patrick Doyle
Wow, so now I can do: class Component < ActiveRecord::Base # Make component.part a shortcut for component.lot.part def part(*args) lot.send :part, args end end ...and do things like: <%= mycomponent.part.number %> ...instead of ... <%= mycomponent.lot.part.number %> nice! --wpd -

[Rails] Re: How to ensure two tables reference the same record in a

2009-09-25 Thread Patrick Doyle
On Fri, Sep 25, 2009 at 1:59 PM, Patrick Doyle wrote: > On Fri, Sep 25, 2009 at 1:55 PM, Marnen Laibow-Koser > wrote: >> Part has_many :components, :through => lots >> >> mypart.components >> >> Done! > > Light dawns on marble head. > > Of

[Rails] Re: How to ensure two tables reference the same record in a

2009-09-25 Thread Patrick Doyle
On Fri, Sep 25, 2009 at 1:55 PM, Marnen Laibow-Koser wrote: > Part has_many :components, :through => lots > > mypart.components > > Done! Light dawns on marble head. Of course! Sorry for the noise. --wpd --~--~-~--~~~---~--~~ You received this message because

[Rails] How to ensure two tables reference the same record in a third table?

2009-09-25 Thread Patrick Doyle
class Part < ActiveRecord::Base has_many :lots has_many :components # or, maybe not end class Lot < ActiveRecord::Base belongs_to :part has_many :components end class Component < ActiveRecord::Base belongs_to :part # or, maybe not belongs_to :lot end In my domain, a "lot" of "compon

[Rails] Re: How to use remote_form_tag?

2009-09-23 Thread Patrick Doyle
Just in case anybody is interested in this thread... here is what I got to work for me: <% form_remote_tag :url => "select_assembly", :update => "disposition" do %> <%= disposition_select_tag "use_part", @parts, @use_part %> <% if @use_part %> <%= disposition_select_tag "use_lot", @lots,

[Rails] Re: How to use remote_form_tag?

2009-09-23 Thread Patrick Doyle
Here is my best idea so far, which, unfortunately, doesn't work... <% form_remote_tag :url => "select_assembly", :update => "disposition", :html => {:id => 'xxx'} do %> <%= select_tag "use_part", options_for_select(@parts, @use_part), :onchange => "$('xxx').submit()" %> <% if @

[Rails] How to use remote_form_tag?

2009-09-23 Thread Patrick Doyle
I have a partial that gets rendered in response to a #link_to_remote call. What I want to do is to display a select box, when the user selects an item from that box, display a second select box, when the user selects an item from that box, display a link (or possibly a submit button) allowing the

[Rails] Re: how to truncate tables before seeding data?

2009-09-22 Thread Patrick Doyle
If you want to delete all of the data in all of the tables, and you are using sqlite3, you could just delete db/development.sqlite3 and then either rerun your migrations, or execute "rake db:schema:load". If you are using MySQL, then you could probably use PHPMyAdmin or the command line to delete

[Rails] AJAX and RESTful routes

2009-09-22 Thread Patrick Doyle
Is there a standard approach to the controller actions that exist solely to populate data do be shown in a view when using RESTful routing? I understand and almost appreciate the 7 actions that exist to implement the ideas of RESTful routes in RoR, but consider a select box whose contents change

[Rails] Re: how to truncate tables before seeding data?

2009-09-22 Thread Patrick Doyle
I read your post this morning and thought, "WOW! Rails has defined an approach for seeding data. That's great! I'll have to look into that." But I didn't have an answer for you. Then later this morning, I went looking for something I'd seen on Ryan Bates excellent Railscasts site (http://rail

[Rails] How to see HTTP requests as they are received?

2009-09-22 Thread Patrick Doyle
Hello Experts! I am debugging a problem with one of my controllers in my development environment and I would like to see the actual HTTP request as it comes in. Is there some option or configuration file for mongrel (which is what gets started from script/server) that will display or log the raw

[Rails] Re: Really stuck on nested resources

2009-09-18 Thread Patrick Doyle
Could this be a pluralization issue? Did you set up your models as: class Parent < ActiveRecord::Base has_many :children end class Parent < ActiveRecord::Base has_many :children belongs_to :parent end class Dog < ActiveRecord::Base has_many :dogs belongs_to :child end If so, then I w

[Rails] Re: How to (re)run validations on existing data

2009-09-17 Thread Patrick Doyle
On Thu, Sep 17, 2009 at 9:14 AM, Marnen Laibow-Koser wrote: > > Patrick Doyle wrote: >> Suppose one had a hypothetical situation in which records were entered >> into a database which were later determined to be invalid. > > Because they were invalid in the first place,

[Rails] How to (re)run validations on existing data

2009-09-17 Thread Patrick Doyle
Suppose one had a hypothetical situation in which records were entered into a database which were later determined to be invalid. In this supposedly hypothetical situation, the agile programmer might add validations to the models to ensure this doesn't, err, wouldn't happen again. Following that,

[Rails] Re: Recent Script.aculo.us tutorial

2009-09-16 Thread Patrick Doyle
On Wed, Sep 16, 2009 at 2:47 PM, Greg Donald wrote: > On Wed, Sep 16, 2009 at 12:35 PM, Patrick Doyle wrote: > > > Can anybody point me at a recent tutorial that might get me started down > > this path? > > Sounds like you just need to learn Javascript. Doesn'

[Rails] Recent Script.aculo.us tutorial

2009-09-16 Thread Patrick Doyle
I would like to add a visual effect to one of my web pages and in the stage where I don't know what I don't know. I've talked to my buddy Google about this and (s)he has pointed me at a number of different web pages that all seem to have 2006 dates on them. I can try looking at them more carefull

[Rails] Re: validates_uniqueness_of :scope => association

2009-09-15 Thread Patrick Doyle
On Tue, Sep 15, 2009 at 5:57 PM, Frederick Cheung < frederick.che...@gmail.com> wrote: > > > > Basically, I want to ensure that identifiers are unique for a given part. > > Well validates uniqueness of wants scope to be column, so give it one > (part_id) ! > > Fred > Oh... duh! (sheepishly creeps

[Rails] validates_uniqueness_of :scope => association

2009-09-15 Thread Patrick Doyle
(How?) Is it possible to use validates_uniqueness_of with a scope that is a belongs_to association? This is what I would like to do: class Lot < ActiveRecord::Base belongs_to :part, :include => true validates_uniqueness_of :identifier, :scope => :part end ...but (not surprisingly) when I run

[Rails] Re: Active Records - multiple connections question

2009-09-03 Thread Patrick Doyle
You could try forcing a garbage collection with something like GC.start (I think). You could try doing that after each connection, or after every N connections, if it takes too long. --wpd --~--~-~--~~~---~--~~ You received this message because you are subscribed

[Rails] script/plugin install vs git submodule add

2009-09-01 Thread Patrick Doyle
I've found several web pages that describe how to use git submodules to install plugins, but it seems that those pages are missing something (or more likely, I am) . In a nutshell, they advise replacing $ script/plugin install git://path_to_spiffy_plugin with $ git submodule add git://path_to_

[Rails] Re: Date precedence validation (ex. Round Trip travel dates)

2009-08-27 Thread Patrick Doyle
Why not convert each date to Ruby Time objects and compare those? --wpd --~--~-~--~~~---~--~~ 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

[Rails] Re: Do a set of records have the same value for one of the fields?

2009-08-27 Thread Patrick Doyle
>> records.map(&:description).all?(&:==) nice... I was trying to figure out something with #inject/#sum, but that looks great. --wpd --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To p

[Rails] Do a set of records have the same value for one of the fields?

2009-08-27 Thread Patrick Doyle
Hi Folks, I'm looking for an elegant Ruby one-liner... I have a set of records in my database that I want to check to see if the :description field is identical. And, because it's Thursday morning (where I live), I would like to do it as elegantly and as one-line-er-ly as I can Something like..

[Rails] Re: How to stop a user submitting the same data more than once.

2009-08-26 Thread Patrick Doyle
Is the user who caused the problem friendly or malicious? If (s)he is (or could be) malicious, then perhaps (s)he didn't use a browser to create three records in your database, but instead wrote some code to post three times in quick succession. I just added a "sleep 5" to my #create method and

[Rails] Re: Textbox input for an action: failed attempt

2009-08-26 Thread Patrick Doyle
I don't know how much this helps, but I've learned the hard way that, when I write <%= blah :blah, :blah do |x| %> <% end %> I get bizarre (and always incorrect) results. The reason is that <%= ... %> results in a string that gets inserted into your HTML stream, while <% ... %> results in some

[Rails] Testing the use of form_for to clone an existing record

2009-08-26 Thread Patrick Doyle
I wanted to be able to clone fields from one record into a new record, so I added a select box to allow the user to select the record from which (s)he wanted to clone (using AJAX to dynamically update the view when (s)he selects such a record). In my #new action, I check to see if the :clone_from

[Rails] Functional Testing with Ajax

2009-08-25 Thread Patrick Doyle
Hello Can anybody recommend a good tutorial for writing functional tests for pages that are updated dynamically? Thanks. --wpd --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to

[Rails] Functional testing with different data sets

2009-08-25 Thread Patrick Doyle
Hello, I just ran into a bug in my application in which the behavior differed depending on whether there was a single element in a particular table or multiple elements in the table. Right after I fixed the bug, I thought to myself, "I wonder how I could have structured a functional test to detec

[Rails] Rails 2.3.2 way to do "Item.find( :all, :select => 'DISTINCT fieldname' )"

2009-08-06 Thread Patrick Doyle
Is there a more modern way to do something like: distinct_items = Item.find( :all, :select => 'DISTINCT fieldname' ) I have found a number of circa 2007 web pages that all recommend the use of :select, and I can't find a :distinct option for #find, but I figured I'd ask. --wpd --~--~-~

[Rails] Re: How to structure a database table with arbitrary labels for the columns?

2009-07-30 Thread Patrick Doyle
On Thu, Jul 30, 2009 at 3:47 PM, cnk wrote: > database? The flexibility to just have data and not have it > constrained by a schema is what spreadsheets are good at. Ohhh... Great answer! I suspect I'll just gather the data into the table that I know exists now. I was asking because (as is typic

[Rails] How to structure a database table with arbitrary labels for the columns?

2009-07-30 Thread Patrick Doyle
I am starting to think about writing an RoR app to store some 2-D data. Most of the data are textual, although there could be a column of dates or a column of numbers here and there. The issue is: different data sets have different columns. Currently, the data are stored in spreadsheets. Many

[Rails] Re: How secure are sessions?

2009-07-29 Thread Patrick Doyle
On Wed, Jul 29, 2009 at 11:48 AM, Robert Walker wrote: > > Patrick Doyle wrote: >> OK, enough long winded babbling introduction.  The tutorials I've read >> about logging into an application all store the user ID in the >> session.  I presume that the "

[Rails] Re: How secure are sessions?

2009-07-29 Thread Patrick Doyle
On Wed, Jul 29, 2009 at 11:41 AM, Rick wrote: > > You could start here: http://www.rorsecurity.info/, download and read > the book. Thanks. I'll do that, although I've realized in hindsight that my question is not specific to RoR. It's much broader. But rorsecurity.info looks like a great plac

[Rails] How secure are sessions?

2009-07-29 Thread Patrick Doyle
I have read a number of different tutorials that talk about adding a login page to an application that all contain very similar wording: "Of course, you would log in over an SSL connection". And I understand the theory of HTTP and the theory of packet sniffing well enough to know that, if I type

[Rails] Re: Remember ids in forms (with association)

2009-07-29 Thread Patrick Doyle
Someday, I hope to know Rails well enough that answers to questions like this just roll off the tip of my tongue (or, in this case, the tips of my fingers as I type on the keyboard). For now, the best answer I can give you is to reference the web page where I learned how to use nested routes: htt

[Rails] Re: How to dynamically change stylesheets globally?

2009-07-16 Thread Patrick Doyle
On Thu, Jul 16, 2009 at 8:30 AM, Michael Schuerig wrote: > > On Thursday 16 July 2009, Patrick Doyle wrote: >> Are you saying that its possible to globally change the style rules >> programatically somehow? > > Yes: > > >   >    ... >     >     >  

[Rails] Re: How to dynamically change stylesheets globally?

2009-07-16 Thread Patrick Doyle
> Unless your stylesheets are prohibitively large, I suggest you don't > actually switch stylesheets. Instead, set the class of the BODY element > and and add the appropriate classes to your style rules. > > Michael Hmmm I'm inheriting the stylesheets from another project, so I don't know if t

[Rails] Re: How to dynamically change stylesheets globally?

2009-07-15 Thread Patrick Doyle
So, what's the difference between session[:large_fonts] and cookies[:large_fonts]? I had just about decided to keep the state in the session when I saw the cookies[:large_fonts] example. The one issue with keeping the state in the session is that it makes it much more difficult to bookmark the :

[Rails] Re: How to dynamically change stylesheets globally?

2009-07-15 Thread Patrick Doyle
Thanks... I wasn't aware of self.get_layout. But my issue isn't so much selecting a layout as it is passing the parameters around to help me decide which layout (or which stylesheet) I should use. I can manually append the options to every link_to and form_for, etc... link I have in my applicati

[Rails] How to dynamically change stylesheets globally?

2009-07-15 Thread Patrick Doyle
There, was that subject sufficiently obtuse to grab your attention? :-) I would like to have several different stylesheets for my application that may be selected dynamically as the user navigates through my site. I have seen this done in PHP by passing parameters to each page visited selecting

[Rails] Re: 5-second code syntax question

2009-02-05 Thread Patrick Doyle
Be careful here, depending on your user base of course. What will you do if {params[:id]} (I know, incorrect syntax), evaluates to "delete!" or something else. If you have a completely trustworthy user base (such as only you, or only your colleagues, whom you should trust implicitly, otherwise, w

[Rails] Re: Values should be filled for corresponding date, in a range.

2009-02-05 Thread Patrick Doyle
On Wed, Feb 4, 2009 at 9:31 PM, Shankar Ganesh < rails-mailing-l...@andreas-s.net> wrote: > > Hi , > >I'm newbie to Rails can someone help in this.I had struck here in my > application and actually i solved it using PHP but don't know how to do > in Rails. > I have table like this > --

[Rails] Re: Elements for a related Model in a Form

2009-02-02 Thread Patrick Doyle
On Sun, Feb 1, 2009 at 6:25 AM, Tomas Markauskas wrote: > > Hello, > > I can't figure out how to do this: > > I have a Post Model and it :has_and_belongs_to_many :tags. When I edit > a Post, I want to create checkboxes or a select field (with multiple > select choices), so I can add tags to a Pos

[Rails] Re: How to think in terms of MVC when designing a website.

2009-01-31 Thread Patrick Doyle
I think it is possible that you might be missing the OP's point. (Or, equally possible, I read a completely different question in the original post.) I think that Nebs would like to create a website with both static and dynamic pages that has a consistent look and feel. It sounds like (s)he woul

[Rails] Re: Creating records with file upload in migration

2009-01-27 Thread Patrick Doyle
On Tue, Jan 27, 2009 at 2:26 PM, Dan Smith wrote: > > Hi, > I have a migration which creates several records along with the table. > eg > Forum.create :title => "General Discussion", :description => "General > Chit-Chat" > > But I'd like to create a record which accepts an uploaded file, such as

[Rails] Re: Problem: using will_paginate with Ajax

2009-01-26 Thread Patrick Doyle
On Mon, Jan 26, 2009 at 3:53 AM, Ruhul Amin < rails-mailing-l...@andreas-s.net> wrote: > > Patrick Doyle wrote: > > In my controller, I have: > > > > respond_to do |format| > > format.html # index.html.erb > > format.xml { render :

[Rails] Re: Help using a rake task to add items to my database?

2009-01-25 Thread Patrick Doyle
> > What you're doing sounds right, most likely though you have a > validation that is keeping the model from saving. > > or, possibly a before_filter. --wpd --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on R

[Rails] Re: Dynamically generate a field option from dropdown selection

2009-01-22 Thread Patrick Doyle
On Thu, Jan 22, 2009 at 9:13 AM, Tony Tony wrote: > > Hi all, > > I'm having a hard time trying to find a good tutorial on how to generate > a field (with ajax) from a dropdown selection. > > For example: > > I have an app where you can select up to two tickets per person. Only if > the user sele

[Rails] Re: 3 use case and the index method

2009-01-21 Thread Patrick Doyle
On Wed, Jan 21, 2009 at 10:12 AM, Mohammad Abed < rails-mailing-l...@andreas-s.net> wrote: > > I wrote the code below which doesn't seem to work, but If I delete the > last if statement, it does work, obviously for the first two use cases > only. Is there a better way to write this code? In my rou

[Rails] Re: Having troubles saving a new model

2009-01-20 Thread Patrick Doyle
On Tue, Jan 20, 2009 at 8:51 PM, Darren Jeacocke < rails-mailing-l...@andreas-s.net> wrote: > > My model is being created but isn't saving. It's like it skips straight > past saving. Any ideas why it might do this? Updating works fine. > > def create >@volunteer = Volunteer.new(params[:volunt

[Rails] Re: Problem: using will_paginate with Ajax

2009-01-18 Thread Patrick Doyle
On Sat, Jan 17, 2009 at 3:05 AM, Ruhul Amin < rails-mailing-l...@andreas-s.net> wrote: > > I want to use pagination with ajax. I have used will_paginate then add > code to support ajax pagination. > I have tried with partial with when I use the code > in index.html.erb > > <%= render :partial =>

[Rails] Re: HTTP Basic Authentication permitting wrong passwords through

2009-01-18 Thread Patrick Doyle
On Sun, Jan 18, 2009 at 12:45 AM, Ryan Waldron wrote: > > I've run into a strange problem with HTTP Basic authentication. I've > observed this behavior on my dev box (connecting directly to mongrel) > and on an Apache+Passenger setup on my deployment machine. > > I'm doing the standard thing acc

[Rails] Re: running a ruby expression stored in a database

2009-01-16 Thread Patrick Doyle
> > So in a view: <%= eval code.upc %> > > *DANGER DANGER DANGER* you are running with scissors here. If an > attacker can get arbitrary code into your database, using eval like > this will execute that code in the context of your application. > > You may want to read up on Kernel#eval, Object#inst

[Rails] Re: problem with named_scope and test-spec?

2009-01-15 Thread Patrick Doyle
On Thu, Jan 15, 2009 at 1:29 PM, Tom M wrote: > > Patrick, > > Thanks... I checked again and the example I posted was a bit off of my > real example, which uses associations and scopes. According to the > docs: > > All \scopes are available as class methods on the ActiveRecord::Base > descendent

[Rails] Re: problem with named_scope and test-spec?

2009-01-15 Thread Patrick Doyle
On Thu, Jan 15, 2009 at 11:21 AM, Tom M wrote: > > I may be overlooking something, but it seems to me that it is a > problem if with this code... > > Class Blog < ActiveRecord::Base > named_scope :unseen, :conditions => "displayed IS NULL" > end > > this test fails... > > it "should give a list

[Rails] Re: What sort of business logic should go in a model?

2009-01-12 Thread Patrick Doyle
On Mon, Jan 12, 2009 at 9:03 PM, Frederick Cheung < frederick.che...@gmail.com> wrote: > On 13 Jan 2009, at 01:52, Patrick Doyle wrote: > > Post could easily have a can_delete? method that might look something > like > > def can_delete?(current_user) > user == current

[Rails] What sort of business logic should go in a model?

2009-01-12 Thread Patrick Doyle
Suppose I have a classic blog application augmented with something like restful authentication so that users must log in to create blog posts and to issue comments on other blog posts. I would like to give a user the option of deleting blog posts, but only those that (s)he has created. Do I put t

[Rails] Re: login redirects that maintain parameter data

2009-01-09 Thread Patrick Doyle
I would suggest taking a look at Ryan Bates screencast about restful authentication (http://railscasts.com/episodes/67), write a simple application or two using restful authentication, and then walk through the code to see how it all works. IIRC, it has support for doing just what you asked. --wp

[Rails] Re: Help figuring out problem with installing activesupport 2.2.2

2009-01-09 Thread Patrick Doyle
On Fri, Jan 9, 2009 at 2:24 PM, LRaiz wrote: > > BTW. I already installed rubygems-update 1.3.1 and run > update_rubygems. It did not help. > > Does that produce the same effect as $ gem update --system ? --wpd --~--~-~--~~~---~--~~ You received this message b

[Rails] Re: How can I set selected value on select_tag

2009-01-09 Thread Patrick Doyle
On Fri, Jan 9, 2009 at 4:04 AM, Zhao Yi wrote: > > This is my select_tag code: > > <%=select_tag 'project_version_select', > options_for_select(@project_versions)%> > > How can I set the selected value for this select box? > Look at the documentation for #options_for_select (see http://www.railsbr

[Rails] Re: Calling System on winows batch file

2009-01-06 Thread Patrick Doyle
On Tue, Jan 6, 2009 at 11:07 AM, Ryan Mckenzie < rails-mailing-l...@andreas-s.net> wrote: > > Hello everyone, > > I'm using InstantRails 2.0 on a Windows XP 32 bit system. > > I'm developing a Rails application where I would like to execute a .bat > file > > I've had a look around and this piece o

[Rails] Re: New cheat sheet: Jump Start Credit Card Processing in Ruby

2009-01-06 Thread Patrick Doyle
Hi Amy, Without having looked at your cheat sheet yet, nor at any code that might be out there for validating credit card numbers, can I put in a request to eliminate one of my (many, I'm sure) pet peeves... Did/can you address the issue of allowing the end user to put spaces in credit card number

[Rails] Re: Testing a POST request with correct param

2009-01-02 Thread Patrick Doyle
On Fri, Jan 2, 2009 at 2:53 PM, Vahagn Hayrapetyan < rails-mailing-l...@andreas-s.net> wrote: > > Hi guys and thanks a lot. > > post 'account/forgot', :user => {:email => 'j...@example.com'} > > is the deal. Patrick, if you could figure this out by putting print > statements in your controller you

[Rails] Re: HTML question...

2009-01-02 Thread Patrick Doyle
> > I was able to get formless inputs to pass validation (as XHTML 1.0 > strict or 1.1) at w3.org by putting them inside block elements like > div or table. > > > I've poked around a little looking to see what others have done, and I > could > > embed a checkmark image in my page, or I could embed

[Rails] HTML question...

2009-01-02 Thread Patrick Doyle
if you are offended by HTML questions on this list, please feel free to flame me off list. I would like to display a boolean value in my #index view as a checkbox that is checked when true and blank when not true. Is there some markup that can do this? Is it "legal" to embed an tag outside the

[Rails] Re: Testing a POST request with correct param

2009-01-01 Thread Patrick Doyle
On Thu, Jan 1, 2009 at 5:25 PM, Vahagn Hayrapetyan < rails-mailing-l...@andreas-s.net> wrote: > > Hi,- > > I'm wondering how to test POSTing something to an action from a form. I > am testing an action named "forgot" in my account_controller.rb. It > takes an email address as a parameter and does

[Rails] Re: Where is #put functional test method documented?

2008-12-31 Thread Patrick Doyle
> > users(:quentin) is instantiating the user based on your users.yml fixture. > Instead, you'll want to query the database for the user. > Yeah, that dawned on me as I wrote my email. But at that point I still wanted to find a better way to search the documentation. RailsBrain looks like a great

[Rails] Where is #put functional test method documented?

2008-12-31 Thread Patrick Doyle
I am trying to figure out why the following test case doesn't work: def test_should_allow_admin_to_become_non_admin put :update, :id => users(:quentin).id, :quentin => {:admin => false} assert users(:quentin).admin == false assert_redirected_to users_url end For some reason, the "

[Rails] Use of #h method in a controller

2008-12-30 Thread Patrick Doyle
I have rails-2.2.2 installed on 2 different computers and routinely switch back and forth between the two of them. I just wrote some code today on my desktop in which I invoked the #h method inside a controller (because I wanted to sanitize a string prior to saving it in an instance variable). Whe

[Rails] Re: Arguments Error

2008-12-30 Thread Patrick Doyle
> > > CartItem#initialze > > -- expects 0 arguments, you passed 1 argument in via CartItem#new > > > I'm not really sure what do do with that -- what should I change? Are > you saying only my CartItem#initialze is wrong? > Probably. You could always add a parameter to your CartItem#initialize meth

[Rails] Re: Arguments Error

2008-12-30 Thread Patrick Doyle
Your error message is: wrong number of arguments (1 for 0) That means that somewhere, you are calling a method that doesn't expect any arguments and you are passing an argument to it. The stack trace give you a clue: ArgumentError in StoreController#add_to_cart app/models/cart.rb:13:in `initia

  1   2   >