Hi all, I accidentally generated a scaffold called reference, not realizing references was apparently a reserved word in MySQL. I thought I could get away with it, since the scaffold itself seemed to be working, but now I''m getting an error that suggests Rails doesn''t like this scaffold name. I''d like to rename it to ref. Is it as simple as a search-replace, or will I encounter other problems? What''s the easiest solution? Here''s the code, in case anyone''s interested (in a show view) <% @genes_phenotypes_references.each do |phenotype_reference| %> <tr> <td><%= link_to phenotype_reference.phenotype.long_desc, phenotype_reference.phenotype %></td> <td>?</td> <td><%= link_to phenotype_reference.reference %></td> </tr> <% end %> genes_phenotypes_references refers to a join table (also a model). The current view is for gene, so I''m trying to have it print a list of links to associated phenotypes and the journal article that associates the gene and the phenotype. Printing the phenotype link works just fine, but when I try to print the phenotype_reference.reference, it gives me a link to the current gene show view, (e.g., genes/1), instead of the reference show view (e.g., references/2). Many thanks. Cheers, John Woods The University of Texas at Austin Marcotte Lab | Center for Systems and Synthetic Biology
2009/6/24 John Woods <john.woods-+ksaPUZU+wsI+954vlgkHg@public.gmane.org>:> > Hi all, > > I accidentally generated a scaffold called reference, not realizing > references was apparently a reserved word in MySQL. I thought I could > get away with it, since the scaffold itself seemed to be working, but > now I''m getting an error that suggests Rails doesn''t like this > scaffold name. > > I''d like to rename it to ref. Is it as simple as a search-replace, or > will I encounter other problems? What''s the easiest solution? >It should be as simple as changing all uses of the text ''reference'' to ''ref'' and ''Reference'' to ''Ref'' plus renaming the files and folders. That is assuming you have not used the text ''reference'' anywhere else of course. I would advise committing to your source control system first and then if it is a disaster for some unforeseen reason you can just revert. Colin
Thanks so much. I wish there was some kind of protection against creating scaffolds with reserved words. It''s frustrating. Anyway, thank you for the help! On Jun 25, 4:26 am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> 2009/6/24 John Woods <john.wo...-+ksaPUZU+wsI+954vlgkHg@public.gmane.org>: > > > > > Hi all, > > > I accidentally generated a scaffold called reference, not realizing > >referenceswas apparently a reserved word in MySQL. I thought I could > > get away with it, since the scaffold itself seemed to be working, but > > now I''m getting an error that suggests Rails doesn''t like this > > scaffold name. > > > I''d like to rename it to ref. Is it as simple as a search-replace, or > > will I encounter other problems? What''s the easiest solution? > > It should be as simple as changing all uses of the text ''reference'' to > ''ref'' and ''Reference'' to ''Ref'' plus renaming the files and folders. > That is assuming you have not used the text ''reference'' anywhere else > of course. I would advise committing to your source control system > first and then if it is a disaster for some unforeseen reason you can > just revert. > > Colin
2009/6/25 John Woods <john.woods-+ksaPUZU+wsI+954vlgkHg@public.gmane.org>:> > I wish there was some kind of protection against > creating scaffolds with reserved words. It''s frustrating. >Can anyone point us at a list of reserved words in RoR that we should not use for models etc? I have fallen over this myself a couple of times and it can be difficult to identify that the problem is a name clash as the errors can be particularly opaque. Colin
http://wiki.rubyonrails.org/rails/pages/ReservedWords On Jun 25, 2009, at 5:32 PM, Colin Law wrote:> > 2009/6/25 John Woods <john.woods-+ksaPUZU+wsI+954vlgkHg@public.gmane.org>: >> >> I wish there was some kind of protection against >> creating scaffolds with reserved words. It''s frustrating. >> > > Can anyone point us at a list of reserved words in RoR that we should > not use for models etc? I have fallen over this myself a couple of > times and it can be difficult to identify that the problem is a name > clash as the errors can be particularly opaque. > > Colin > > >Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org
2009/6/26 Rob Biedenharn <Rob-GBZH0y1GwQfnZcttdmLDtcI/UQi/AW5J@public.gmane.org>:> > http://wiki.rubyonrails.org/rails/pages/ReservedWords >Great, thanks Rob, it does have a couple of words that I had trouble with, in the ''Other names reported to have caused trouble'' but I notice that ''reference'' is not in there. John are you sure that this was your problem. I suppose the proof is in whether renaming fixed it. Colin
I think the problem is that it''s a MySQL reserved word rather than Rails. Perhaps if different DB software was used it wouldn''t be a problem? I''m not experienced enough to say one way or another. On Jun 26, 10:31 am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> 2009/6/26 Rob Biedenharn <R...-GBZH0y1GwQfnZcttdmLDtcI/UQi/AW5J@public.gmane.org>: > > > > >http://wiki.rubyonrails.org/rails/pages/ReservedWords > > Great, thanks Rob, it does have a couple of words that I had trouble > with, in the ''Other names reported to have caused trouble'' but I > notice that ''reference'' is not in there. John are you sure that this > was your problem. I suppose the proof is in whether renaming fixed > it. > > Colin
John Woods wrote:> I think the problem is that it''s a MySQL reserved word rather than > Rails.I thought the Rails DB adapters quoted identifiers precisely so name clashes of this sort wouldn''t occur on the DB side.> Perhaps if different DB software was used it wouldn''t be a > problem? I''m not experienced enough to say one way or another.I doubt that the issue is on the DB side, but if is, I don''t think switching will do it. I think "references" as a keyword is in the SQL standard, so it''s probably reserved in every SQL DBMS that supports foreign keys. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.
I ran into this exact problem with a php app a little while ago and you get some very odd errors that are not very useful (from what I recall they were something like, "problems with your sql at ''select * from references'' " which had me looking at the right area, but for the wrong thing.) Carl On Jun 26, 10:22 am, Marnen Laibow-Koser <rails-mailing-l...@andreas- s.net> wrote:> John Woods wrote: > > I think the problem is that it''s a MySQL reserved word rather than > > Rails. > > I thought the Rails DB adapters quoted identifiers precisely so name > clashes of this sort wouldn''t occur on the DB side. > > > Perhaps if different DB software was used it wouldn''t be a > > problem? I''m not experienced enough to say one way or another. > > I doubt that the issue is on the DB side, but if is, I don''t think > switching will do it. I think "references" as a keyword is in the SQL > standard, so it''s probably reserved in every SQL DBMS that supports > foreign keys. > > Best, > -- > Marnen Laibow-Koserhttp://www.marnen.org > mar...-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > -- > Posted viahttp://www.ruby-forum.com/.
2009/6/27 Carl <nexusrpg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> > I ran into this exact problem with a php app a little while ago and > you get some very odd errors that are not very useful (from what I > recall they were something like, "problems with your sql at ''select * > from references'' " which had me looking at the right area, but for the > wrong thing.)This should not happen in rails however as it should be something like select * from `references` Colin