Forum: Ruby on Rails stray questions

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Peter K. (Guest)
on 2008-10-15 01:08
Hi,

I've been googling and going through the forum, and I can't find the
answers so some stray questions.

A) If I have a render :partial is there a way to get rid of the trailing
newline?  <%- and -%> don't work.  Is the <br> an essential part of the
partial?

B) People say that the mysql tables get kinda messy sometimes and that
they
need to be reinitialized every once in a while.  Frankly, that kind of
talk scares me.  But what are the steps for reinitializing?

I have a problem where I added the has_many and belongs_to lines fairly
late in the game, and I am worried that somehow the scaffolding isn't
paying attention to them.  I have an object that has_many As and
has_many Bs.  It gives me no problem with the As, but when it tries to
find the Bs, give an error.

The error says:

uninitialized constant SpreadType::Abstractleg

I don't have any irritating pluralization or nothin.

I am running on Debian Linux.


3. I also get a scary error when I try to install the ruby-gems
debugging package.  Should I just switch OSes?  What is the VERY BEST OS
for doing ruby work?
Brian H. (Guest)
on 2008-10-15 01:19
(Received via mailing list)
See inline - I'll do my best to answer.

On Tue, Oct 14, 2008 at 4:08 PM, Peter K. <
removed_email_address@domain.invalid> wrote:

>
> Hi,
>
> I've been googling and going through the forum, and I can't find the
> answers so some stray questions.
>
> A) If I have a render :partial is there a way to get rid of the trailing
> newline?  <%- and -%> don't work.  Is the <br> an essential part of the
> partial?
>

trainling newline? like in your source code? or when you look at the
page?

>
> B) People say that the mysql tables get kinda messy sometimes and that
> they
> need to be reinitialized every once in a while.  Frankly, that kind of
> talk scares me.  But what are the steps for reinitializing?


I have no idea. Hasn't really been a problem here. Sounds like FUD.
However
you don't have to use MySQL.
You can use PostgreSQL, Oracle, MS Sql Server, whatever works best for
you.

>
> I have a problem where I added the has_many and belongs_to lines fairly
> late in the game, and I am worried that somehow the scaffolding isn't
> paying attention to them.


Scaffolding doesn't care about associations, and it's really not meant
to be
anything but a learning tool.


>  I have an object that has_many As and
> has_many Bs.  It gives me no problem with the As, but when it tries to
> find the Bs, give an error.
>
> The error says:
>
> uninitialized constant SpreadType::Abstractleg
>
> I don't have any irritating pluralization or nothin.
>

Show your code - both models with names and associations, and also your
database table names and field names for both.

Generally, if project has_many :tasks, and task belongs_to :project,
then
the tasks table would have a project_id column. The belongs_to
declaration
goes in the model whose table contains the foreign key.


>
> I am running on Debian Linux.
>
>
> 3. I also get a scary error when I try to install the ruby-gems
> debugging package.  Should I just switch OSes?  What is the VERY BEST OS
> for doing ruby work?


Debian is a fine OS, but I don't know how you installed things. Its
packages
for Ruby might be out of date. Ubuntu is a good distro for development.
I've
used Ubuntu, Windows, and Mac, and I prefer the Mac OS for Rails
development. Not going to get into the reasons because I don't want to
start
a holy war. But given that your installation has recent versions of Ruby
(ruby -v should report 1.8.4 or higher, preferably something in 1.8.6 or
so)
then you should be fine.
Peter K. (Guest)
on 2008-10-15 01:51
>
> trainling newline? like in your source code? or when you look at the
> page?
>

On the page.  I guess what I am trying to do is have an update in a
division using a partial, with multiple divisions on the same line.


    render :update do |page|
        page[:test].replace_html :partial => 'pretty'
        page[:test2].replace_html :partial => 'reptiles'
          end



A friend of mine who is a mid-level rails developer thinks it might be
impossible to avoid the breaks.


>
> Show your code - both models with names and associations, and also your
> database table names and field names for both.
>



Here is the parent

class SpreadType < ActiveRecord::Base

   has_many :spreads
   has_many :customer_subscriptions
   has_many :ghostlegs
   has_many :abstractlegs

  def index

  end
   def self.find_spread_names

    find (:all)
  end
end

Here is the child that works:

class CustomerSubscription < ActiveRecord::Base
  belongs_to :customer
  belongs_to :underlying
  belongs_to :spread_type
end


Here is the child that doesn't work

class Ghostlegs < ActiveRecord::Base
  belongs_to :spread_type
end


Here is the creation code for the child that doesn't work:

class CreateGhostlegs < ActiveRecord::Migration
  def self.up
    create_table :ghostlegs do |t|
      t.decimal :daystoexpire
      t.decimal :distancefromunderlying
      t.decimal :abstractratio
      t.integer :corp
      t.integer :spread_type_id

      t.timestamps
    end
  end

  def self.down
    drop_table :ghostlegs
  end
end


And here is the migration code for the parent

class CreateSpreadTypes < ActiveRecord::Migration
  def self.up
    create_table :spread_types do |t|
      t.string :name

      t.timestamps
    end
  end

  def self.down
    drop_table :spread_types
  end
end

So maybe the underscore in the table name is what's confusing things?
Or is that just FUD logic?  Why does it work for one and not the other?
Shouldn't it just generate the queries?
Peter K. (Guest)
on 2008-10-15 02:08
And here is the index file


 <% for spread_type in SpreadType.find_spread_names%>
    <%= spread_type.name %>

    <%

    # this loop works

    for customer_subscription in spread_type.customer_subscriptions
       %>  <%= customer_subscription.customer_id %>
       <%
    end

  # this loop does not work

  #  for ghostleg in spread_type.ghostlegs
  #
  #  end
%>
    <br>
    <br>

    <% end %>
Frederick C. (Guest)
on 2008-10-15 02:16
(Received via mailing list)
On Oct 14, 10:51 pm, Peter K. <removed_email_address@domain.invalid>
wrote:
>
> class SpreadType < ActiveRecord::Base
>
>    has_many :spreads
>    has_many :customer_subscriptions
>    has_many :ghostlegs
>    has_many :abstractlegs

[snip]

> class Ghostlegs < ActiveRecord::Base
>   belongs_to :spread_type
> end
>

has_many :ghostlegs will be looking for a class class Ghostleg in
ghostleg.rb (similarly for abstractlegs)

Fred
Hassan S. (Guest)
on 2008-10-15 02:18
(Received via mailing list)
On Tue, Oct 14, 2008 at 2:51 PM, Peter K.
<removed_email_address@domain.invalid> wrote:

> On the page.  I guess what I am trying to do is have an update in a
> division using a partial, with multiple divisions on the same line.

If you're talking about a <div> tag, it's a block-level element. If you
want multiple divs side-by-side, you'll need to use the appropriate
CSS to position them that way.

> A friend of mine who is a mid-level rails developer thinks it might be
> impossible to avoid the breaks.

Rails does wonderful stuff, but it doesn't absolve *web* developers
from the need to know HTML and CSS.

FWIW,
--
Hassan S. ------------------------ removed_email_address@domain.invalid
Peter K. (Guest)
on 2008-10-15 03:02
Thank you fred:  That was it.

I had created it with the plural, and then was treating it as though I
had created it with the singular.

If you're ever in Chicago, I'll buy you lunch.
Peter K. (Guest)
on 2008-10-15 03:03
And thanks for the reality check, Hassan & Brian.

This really is a very helpful forum.  Thanks...
This topic is locked and can not be replied to.