Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Strong Sauce
Jul 2, 2003

You know I am not really your father.





So I'm trying to get into programming 2.1 however a lot of material is either for rails 1.2/1.4 or some older version of rails. Is there a site that discusses the changes between previous version of Rails and what Rails is at the moment?

Adbot
ADBOT LOVES YOU

Strong Sauce
Jul 2, 2003

You know I am not really your father.





My company is trying to transfer a Rails app over from MySQL to an Oracle database. Unfortunately due to the way Rails creates table names, there is a table name that is 37 characters in length. Oracle only allows for 30 character object names.

Renaming the table / renaming the class object is currently out of the question since it is part of an open source project.

Is there anyway in Rails to specify that when table X is being referenced it should actually look at table Y rather than the rails converted name for table X?

Strong Sauce
Jul 2, 2003

You know I am not really your father.





Fangs404 posted:

I posted this on StackOverflow, but I haven't really had a response, so I figured I'd ask here. This problem has just really stumped me.

I'm maintaining an ancient RoR site that we're in the process of rewriting in Django. The site was written by someone else when Rails was in its infancy, and no one kept it updated until I got to it. A night or two ago, the server went down, I suspect due to a MySQL update. In the process of trying to fix it, we broke it, and now mongrel won't start. I see this in the mongrel log:

code:

In `config/environment.rb`, we have `RAILS_GEM_VERSION = '1.2.3' unless defined? RAILS_GEM_VERSION` which I thought would force Rails 1.2.3. Also, here's the output of `gem list`:
Thanks for any and all help!


Well if its possible that RAILS_GEM_VERSION is already defined as 3.0, then it won't set it to 1.2.3.

Also try running the Rails app through Webrick and see if its actually Mongrel or a Rails problem. This looks like a Rails/Gem issue.

Strong Sauce
Jul 2, 2003

You know I am not really your father.





Physical posted:

Is there something that I don't know that prevents me from assigning a value to a key in a hash.each loop?

code:
     #ok so we have our list of locations, now find the staff resources that have this id that are used by the dept in the plan
     @plan.departments.each do |dep|
        #loop through the staffings to find staffings with the location we want
        dep.staff.each do |staff|
          #now cross reference this current staffing's.loc_id with the list we have previously
          data.each do |k, v|
            # "location id thing " + staff.location_id.to_s                 
            if k.to_i == staff.location_id.to_i 
              v = Hash.new()
              v[dep.id.to_s] = staff
              %> <%= v.inspect + "data inspect #{data.inspect}"%>     <br /> <br />    <%      
            end                            
          end
        end        
     end
When I inspect the data of v, it looks good. But the inspection on data (the owner of v) shows nothing. What gives?
Do you know that k represents the hash key, with v representing its related hash value?

First you are manipulating on a local object, v, so when you exit the scope of the block its just going to be erased.

Second, I don't know what the keys in data are since I can't see any input. But your loop is going to erase every single value in the hash and then create a hash as the new value wherein it contains the department's id correlating with the staff, but will subsequently overwrite that hash value everytime a staff has that department id (assuming you could even manipulate local variables). Without being able to see the actual data structures for each object, this seems really unstructured.

Lamont Cranston posted:

Just setting v won't do it; you'll have to do data[k] = (your new v).

(Though something tells me you could probably do this with inject instead. I'm not super familiar with the ins and outs but you might want to take a look.)

inject is essentially a reduce, how is that going to help him here? I am guessing you're referring to mapping?

Strong Sauce
Jul 2, 2003

You know I am not really your father.





Lamont Cranston posted:

Well yes, but map returns an array. I was thinking he could do something like
code:
data.inject({}) do |hash, (k,v) | 
    #manipulate v however you want
    hash[k] = v
    hash
end
It at least avoids the problem of modifying the structure as your iterating over it.

Ah yes I kept thinking that the object returns as an array of hashes and not a hash. Still your solution doesn't actually modify `data`, it just returns a copy such that data is still not changed.

Strong Sauce
Jul 2, 2003

You know I am not really your father.





So we are suppose to pay him money to "fix" Rails in Mac OSX because he/they made it way too complicated?

Edit: Oh I see he's making a Mac app. Now the complaints about, "does Yehuda Katz know ObjC?" make more sense

Strong Sauce fucked around with this message at 01:42 on Mar 29, 2012

Strong Sauce
Jul 2, 2003

You know I am not really your father.





Smol posted:

You mean this?

Apple has made an 'official version' based off his stuff

http://kennethreitz.com/xcode-gcc-and-homebrew.html
http://developer.apple.com/downloads

Look for Command Line Tools for XCode

Strong Sauce
Jul 2, 2003

You know I am not really your father.





So I have 2 model types, Leagues and Players. Leagues can have Players, and Players can be in different Leagues.

You can add players and leagues separately, but I'm trying to assign an already created player to the current league. Before I would just do League.find(params[:league_id]).players.create(params[:player]) to add players to a league, but that method doesn't help me much for existing players.

Essentially what I want to do is just add into the join table that player with :player_id is now also in league :league_id. But I don't want a new entry in the player table.

I haven't done Rails in a while so I'm blanking out here. Any help?

Strong Sauce
Jul 2, 2003

You know I am not really your father.





8ender posted:

code:
Player.find[:player_id].leagues << League.find[:league_id]
Does that do what you need?

For the most part, although I changed it as Player.find(params[:player_id]).leagues << League.find(params[:league_id])

This worked, however now I run into another problem where Rails is not pointing to the correct route when I just want to delete the player from the league and not the player itself. Here is my routes table

code:
  delete 'leagues/:league_id/players/:id' => 'players#drop_from_league'
  post 'leagues/:league_id/players/' => 'players#create_league_player'
  resources :players
  resources :leagues do
    resources :players
  end
However when I run a rake routes, it duplicates the 'leagues/:league_id/players/:id' route
code:
---->              DELETE /leagues/:league_id/players/:id(.:format)      players#drop_from_league
                   POST   /leagues/:league_id/players(.:format)          players#create_league_player
           players GET    /players(.:format)                             players#index
                   POST   /players(.:format)                             players#create
        new_player GET    /players/new(.:format)                         players#new
       edit_player GET    /players/:id/edit(.:format)                    players#edit
            player GET    /players/:id(.:format)                         players#show
                   PUT    /players/:id(.:format)                         players#update
                   DELETE /players/:id(.:format)                         players#destroy
    league_players GET    /leagues/:league_id/players(.:format)          players#index
                   POST   /leagues/:league_id/players(.:format)          players#create
 new_league_player GET    /leagues/:league_id/players/new(.:format)      players#new
edit_league_player GET    /leagues/:league_id/players/:id/edit(.:format) players#edit
     league_player GET    /leagues/:league_id/players/:id(.:format)      players#show
                   PUT    /leagues/:league_id/players/:id(.:format)      players#update
---->              DELETE /leagues/:league_id/players/:id(.:format)      players#destroy
           leagues GET    /leagues(.:format)                             leagues#index
                   POST   /leagues(.:format)                             leagues#create
        new_league GET    /leagues/new(.:format)                         leagues#new
       edit_league GET    /leagues/:id/edit(.:format)                    leagues#edit
            league GET    /leagues/:id(.:format)                         leagues#show
                   PUT    /leagues/:id(.:format)                         leagues#update
                   DELETE /leagues/:id(.:format)                         leagues#destroy
              root        /                                              leagues#index
For some reason Rails is not overriding the DELETE /leagues/:league_id/players/:id(.:format), I may end up just creating a leagues_players controller to handle this stuff but does anyone know why Rails isn't overriding the route?

Strong Sauce
Jul 2, 2003

You know I am not really your father.





Yeah that's probably going to be the best solution. Still odd that Rails won't override the route though.

Strong Sauce
Jul 2, 2003

You know I am not really your father.





BonzoESC posted:

Routes don't "override" until they're evaluated at request time. When you DELETE that route, what action does it route to?

When I say override, I meant I specify a different route in routes.rb. When I run rake routes it's suppose to generate what the proper routes should be, and it seems to duplicate the same route. The other route I overrode, "post 'leagues/:league_id/players/' => 'players#create_league_player'" right underneath the DELETE route doesn't show up subsequently down the route path. However the DELETE route still shows up when it's suppose to be overridden.

Right now the route is still using ,"players#destroy" rather than "player#drop_from_league"

Strong Sauce
Jul 2, 2003

You know I am not really your father.





BonzoESC posted:

Did you try moving your drop_from_league declaration below the resources?

You can also suppress the default delete: http://guides.rubyonrails.org/routing.html#restricting-the-routes-created

So moving it below the resources didn't work, but excluding destroy method works! Thanks! Still odd though.

Adbot
ADBOT LOVES YOU

Strong Sauce
Jul 2, 2003

You know I am not really your father.





etcetera08 posted:

Not Rails-related, but since we don't have a Ruby thread.. I am having a weird thing where a
Ruby code:
require 'lastfm'
is giving me a "stack level too deep" error. Any ideas what's happening/why? I figure it's something simple I'm too stupid to see.

edit: if I do it in irb it gives me the same error and then says "Maybe IRB bug!!" :confused:

Which versions of lastfm and dependency gems are you using? Usually when that error occurs it is some kind of infinite recursion problem but that probably won't help you solve this problem.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply