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
KoRMaK
Jul 31, 2012



Is there a way to stop pending migrations from being run when I do rake db:seed or a way to run my own .rb files using rake?

KoRMaK fucked around with this message at 17:46 on Mar 1, 2013

Adbot
ADBOT LOVES YOU

KoRMaK
Jul 31, 2012



I have three questions:

1) I want to put a :limit clause on a relationship using a variable from the same class, like this (but it doesn't work).
Ruby code:
class Account < ActiveRecord::Base
  has_many :things, :limit => self.things_limit
end
2) How would I override a relationship so that I can add in my own customizations
Ruby code:
class Account < ActiveRecord::Base
  has_many :things

  def things
    things.limit(5) #use the original things relationship and limit the return count, for example
  end
end
3) How would I override a model's find or all commands to only return the first X count of records (Thing is a model)
Ruby code:
Thing.all #would return only the first X count of records

KoRMaK
Jul 31, 2012



A MIRACLE posted:

is `things_limit` a class method or an instance method? I think this might only work with class methods.
I have a confession: I still don't know how to tell the difference between the two after 1yr+ RoR development :eng99: things_limit is a column on the Account model.

I'm still taking in and processing the other couple of comments from you guys, thanks for the replies.

KoRMaK
Jul 31, 2012



I am building a file attachment system. I know there are gems out there that do this, but I'm doing it by hand. Things are going well, I have successfully saved the data into the database (yes, into the DB) and successfully retrieved it and delivering it to the user via web browser.

My question is how do I read that file back into an object that I can then do file.content_type on? I'm running into wierd problems where ruby complains that it is a string and not a file or something.

Ruby code:
    file_image = params[:attachment][:file_data].read
    file = StringIO.new(file_image)
    
    Rails.logger.info("file content type #{params[:attachment][:file_data].content_type} file.content_type #{file.content_type}") #file.content_type gives an error

KoRMaK
Jul 31, 2012



I actually don't have any compelling evidence to use to convince the team against it, so I am complicit.

Even if I do get evidence against it, I'd still like to know how to solve my problem as a learning exercise.

KoRMaK
Jul 31, 2012



This is killing me: I have a file upload in a modal that I want to submit via js but once I add the file to the form the form submits as HTML and not js. I've been tryin to find and explanation of what is going on but nothing really explains this process beyond "magic iframe" I've tred watching the form event listeners and I are no change between the modal submitting with or without a file. Can someone point me to a guide or even a debugging tip for how to see what is going on?

E: screw it, I'll use someone else solution https://github.com/JangoSteve/remotipart worked in like less than a minute. I guess if I want to know what is going on I can explore its code

KoRMaK fucked around with this message at 20:43 on Apr 10, 2013

KoRMaK
Jul 31, 2012



How do I specifiy the namespace (not sure what to call it in ruby or rails, I'm using it as if this were java or C#) of a variable I am using? I have a local variable that is getting in the way of a similar one in a module. Is there a way I can delineate between the two?

I have had the same problem with a definition in the application helper override a model's scope definition.

Similar problem, I have overridden I18n.t in my application helper but when I try to call it from the application helper file it uses the default I18n.t version instead of the one I wrote. Doing ApplicationHelper.t gets me the right one, but it loses the context of my current_account variable which I need t to be aware of.

KoRMaK fucked around with this message at 16:56 on Apr 23, 2013

KoRMaK
Jul 31, 2012



I want to override the I18n::translate method for my whole app. Why? Because the default scaffolded views use the f.label method and that calls translate and I want translate to conform to our special locale system. Normally it pulls the labels from the en.yml file under helpers.label.model.field

I need to also have it check another location.

KoRMaK
Jul 31, 2012



Cocoa Crispies posted:

It depends on the app server you use, and if your Rails stack is loading Rack::Lock.

The long version is Unicorn uses multiple UNIX processes to handle parallel requests, Rainbows handles multiple requests in a single process with a variety of configurable techniques, Passenger uses multiple processes, Puma uses threads, and if you're using Webrick in production kill yourself.
I can't tell if you are being serious or not. Those names.

KoRMaK
Jul 31, 2012



I'm confused. Use Jquery's ajax or better yet add :remote => true to your form and allow the controller to respond to js requests.

KoRMaK
Jul 31, 2012



How would I dynamically add an after filter based on the conditional of whether an instance method exists?

I am making a module that attachs to controllers and I want to add an after filter to a method only If said method exists

KoRMaK
Jul 31, 2012



I would think that should work, but the class doesn't have the method in its class methods at te time the module gets run. So it's like the method doesn't exist for me to put a filter on.

KoRMaK fucked around with this message at 19:22 on Jun 12, 2013

KoRMaK
Jul 31, 2012



Why not?
It will be better this way than editing 30 files to conform.

KoRMaK fucked around with this message at 19:37 on Jun 12, 2013

KoRMaK
Jul 31, 2012



C'mon Don't logic some sense into me.

I sill think it be useful to add filters from a module.

Wait, adding a filter on that function inside the controller doesn't work either. I should go read up on filters.

E: wtf filters only get run on the methods that are called during routing? I added my before filter to edit, instea of a function that gets called by edit, and it started to work. I guess I had a fundamental misunderstanding of when filters are run.

KoRMaK fucked around with this message at 23:06 on Jun 12, 2013

KoRMaK
Jul 31, 2012



Is there an editor or eclipse plugin that will open the other 2 files of a ror object when I open 1?

I want to open the beer form view and have the model and controller open in editor windows for it automatically.

I am now in the realm of shaving off repetitive tasks that take seconds because of their cost over a career-time. And I am lazy. I mean efficient.

KoRMaK
Jul 31, 2012



Cocoa Crispies posted:

It's not "ror" unless you're a recruiter, it's "Rails." Objects only usually have one file. Just because the scaffold generator makes files with similar names doesn't mean they have to be related.

Don't bother microoptimizing your workflow when you barely know what's going on; it'll save seconds but cost hours.
What is this? I use short hand to represent my ideas and I get a reply that implies I don't know what's going on?

Rails object in my post meant a rails scaffolded set of views a controller and a model centered around one name working in conjunction with each other.

I'd still want the option for the model and controller to open up when I open a view when appropriate.

KoRMaK fucked around with this message at 18:02 on Jun 13, 2013

KoRMaK
Jul 31, 2012



shdwdmg posted:

A bit late to the party, but realistically speaking I am looking for a career change. I have some programming experience from HS, but opted for a stupid Liberal Arts Degree that has offered dismal opportunities.

What would I have to do to be taken serious when I start to look for a job? or Should I not even bother at this point?
Like the visual effects industry, programming jobs can be landed by solid portfolios. Namely ones that interact with a DB.

KoRMaK
Jul 31, 2012



That's how you do it. I've recently upgraded our file with a similar parent chaining with added consideration if the parent isn't attached yet.

KoRMaK
Jul 31, 2012



I have two objects/tables, Persons and feed_entries. A person can have multiple feed_entries. I want to set the default_scope for Persons so that it orders DESC by the "last_updated" method which is defined below on person.rb
Ruby code:
def last_updated
    last_feed = feed_entries.order("created_at DESC").first.created_at rescue nil
    if (last_feed == nil) || (updated_at > last_feed)
      last_feed = updated_at 
    end
    last_feed
  end
Here is the best default_scope I could come up with, but it's wrong because it sorts by both columns. I want it to sort by whichever one is more recent, as demonstrated by last_updated.
Ruby code:
default_scope joins("LEFT JOIN feed_entries ON feed_entries.person_id = persons.id").order('feed_entries.created_at DESC, persons.updated_at DESC').group('persons.id')
I've tried using the last_updated method in the scope with a lambda but it says that "Class does not have a last_updated method" so I guess using it in the scope is out? So here is some psudeocode to try and convey as best as i can what I would like to be able to do
Ruby code:
default_scope order(last_updated DESC)

KoRMaK fucked around with this message at 22:48 on Jun 27, 2013

KoRMaK
Jul 31, 2012



Yes that makes so much sense. Way more rails than whatever I was envisioning.

KoRMaK
Jul 31, 2012



Has anyone had to deal with devise's password reset in a multi tenantcy environment? Devise is only looking for users by email, I need email and account_id in my user load query. I'm going through the devise library and feels like I'm getting close but there has got to be someone else that has had this issue.

I'm currently overriding the devise password controllers create method but by the time it gets to user.find first by auth conditions it has forgotten the account id I am passing in.

KoRMaK
Jul 31, 2012



Molten Llama posted:

How'd you set Devise up in your initializer? If you haven't already tweaked your config.authentication_keys and config.request_keys, start there and the rest should fall into place a lot more quickly and obviously.
Only noticed the authentication_keys and not the request_keys. Thanks I'll check that out.

KoRMaK
Jul 31, 2012



I have a namespace in my routes. Pages in that namespace are not having the application.js compiled for them. What are things I should be considering when when it comes to namespaced routes and the asset pipeline?

KoRMaK
Jul 31, 2012



The thing you are looking for does not exist in the params hash.

KoRMaK
Jul 31, 2012



raej posted:

Am I setting this whole form up wrong then?

It's a view for Beer which displays all the info on a beer. The form is for Cellared_Beer which is a physical instance of a beer a user has. The idea is to have a form on the Beer page for a user to add to their cellar (Cellared_Beer) based on adding Year, Size, and Quantity and taking the beer (which is the page you're on) and the user (current_user)
You must be because the params you pasted don't contain what you think they should. Also, that is alot of stuff to paste.

Here's an example of what my params look like on a form submit:
Ruby code:

Started PUT "/contacts/4" for 127.0.1.1 at 2013-07-16 16:21:32 -0400
Processing by ContactsController#update as HTML
  Parameters: {"utf8"=>"&#10003;", "authenticity_token"=>"7CK5Ns6XZ6EdvteONVJ1BPmdcP/PSbBx/GXL9YsvYmw=", 
"contact"=>{"first_name"=>"aaa", 
"last_name"=>"aaaa", 
"job_title"=>"eee", 
"department"=>"", 
"location_id"=>"", 
"work_email"=>"", 
"work_phone"=>"", 
"home_phone"=>"", 
"mobile_phone"=>"", 
"street_address"=>"", 
"city"=>"", 
"state"=>"AL", 
"postal_code"=>"", 
"country"=>"US",
 "tags"=>""}, "commit"=>"Save Changes", "id"=>"4"}

KoRMaK
Jul 31, 2012



We usually put ours in a migration so that when it gets to production we just run it. It's been tested in 2 or 3 environments before it gets to there and it has worked reliably.

e: I guess when I use it, it's a little different than what you are intending. But I'd give it a try.

KoRMaK
Jul 31, 2012



Instead of writing that as SQL I would have written it as a ruby loop.

e: inside of the migration. Like this

Ruby code:
class AddClassToItems < ActiveRecord::Migration
  def change
    add_column :items, :class, :integer
    
    #also create settings for these fields
    g = Guide.create(:section => "items", :field_name => "class")      
    s = Setting.create( :account_id => -1, :field_guide => g, :order => 10)

  end
end

KoRMaK fucked around with this message at 17:04 on Jul 17, 2013

KoRMaK
Jul 31, 2012



How do you switch the version on api.rubyonrails.org? I need to look at an older version. Right now its stuck at 4

KoRMaK
Jul 31, 2012



Molten Llama posted:

Tack on v and the version you'd like, e.g. http://api.rubyonrails.org/v3.2.13/.

I don't know what the hell happened to the switcher.
Haha I love this loving community.

I integrated SAML SSO today with Onelogin's kit. It wasn't that bad.

KoRMaK
Jul 31, 2012



Somehow Eclipse just knows where to find the info for content assist.

I'm guessing it uses my rvm gem settings (I'm on windows) to figure out where the gem library is. I'd like to switch this to a different directory which resides on a network drive. Has anyone had experience with this?

KoRMaK
Jul 31, 2012



I want to host a portfolio app thats just a small demo of an idea on the Internet for as cheap as possible. It seems like heroku might have a free option. Am I understanding that correctly?

KoRMaK fucked around with this message at 05:41 on Sep 15, 2013

KoRMaK
Jul 31, 2012



kayakyakr posted:

e: ^^^ github pages are also good for static apps. It's http://nestacms.com/ on the back end if i'm not mistaken.
Is this in regards to my question? My app isn't going to be static.

KoRMaK
Jul 31, 2012



Just deployed to heroku. Things are going ok, but when I created the app locally it was for mysql. Now I am trying to switch to postgreSQL. The heroku documentation says my database.yml file gets overwritten with the right info, but it doesn't seem to be working.

code:
       could not connect to server: Connection refused
       Is the server running on host "127.0.0.1" and accepting
       TCP/IP connections on port 5432?
I'm not sure what it is talking about there, since heroku controls the database. What am I not doing to get this setup right?

KoRMaK
Jul 31, 2012



Oh My Science posted:

https://devcenter.heroku.com/articles/rails-asset-pipeline#troubleshooting

Scroll down to the trouble shooting section. I believe this answers your question.
Yea that was precisely what I needed! Thank you so much. http://rails.liquid-software.com/

The backgrounds for the other slides in the carousel bootstrap layout don't load. I'm not sure whats up with that.

KoRMaK
Jul 31, 2012



I learned the importance of "require jquery_ujs". I thought it was jquery_uis which would be a redundant include. The it dawned on me "ujs = unobstrusive javascript." It's got what remote forms crave.

I spent an hour trying to figure out why my :remote => true form submit's were refusing to submit as js.

KoRMaK
Jul 31, 2012



I'm starting my first app from scratch. I have about 2 years in on another project that I inherited after it was setup with a custom config. There isn't really a problem, but I notice a difference when I scaffold. With my new app the models have all their variables mentioned via attr_accessible. The other app doesn't do this. The only time it does is for when something gets added to the account model. My guess is that the account model was made before the gem or config option that controls this. Can anyone suggest what gem/option controls this?

KoRMaK
Jul 31, 2012



Ruby 1.9.2, Rails 3.2.13. They both have that in common. Strong Parameters doesn't look familiar. The older project inherits a proprietary setup called Rails Saas kit so maybe its from that.

KoRMaK fucked around with this message at 01:10 on Oct 3, 2013

KoRMaK
Jul 31, 2012



But why does one do it and not the other.

KoRMaK
Jul 31, 2012



In Ruby, I have a ASCII-8bit stream that contains a xls workbook. I want to open the workbook via the Workbook gem, but it requires a file. Is there a way I can read the stream into a file object without actually writing it to disk? This link seems close to what I am trying http://stackoverflow.com/questions/5931263/memory-streams-in-ruby

e: I tried it and it almost works. The Workbook gem tries to do a rewind on it, and I get an "Illegal Seek" error.

https://github.com/zdavatz/spreadsheet/blob/master/lib/spreadsheet/excel/reader.rb#L1198

KoRMaK fucked around with this message at 21:02 on Nov 8, 2013

Adbot
ADBOT LOVES YOU

KoRMaK
Jul 31, 2012



Soup in a Bag posted:

If you want to read the entire stream in and then use it as if it were a file, check out StringIO. It responds to #rewind and all the other File/IO-ish methods.
I will try that. Thank you.

Now I have a public staging/development area and a production are on heroku. Heroku offers a nice easy way to manage which app you are managing. I needed to get my DB up and it just requires adding -app APPNAME at the end of the commands.

I have another problem with an app I've already deployed to heroku that I am creating a new instance of and for some reason it fails at the assets:precompile step. Here's the push log I get

code:
rake aborted!
Invalid CSS after "  padding": expected ";", was ": 10px;"
  (in /media/sf_clunker/app/assets/stylesheets/application.css)
(sass):5655

So somehwere in sass.css or sass.css.sass or whatever there is some invalid css. However, I don't have access to that file, it's part of the sass-rails gem. I'm not sure where to go next to fix it.

e: Fixed! There was a comma where a semi-colon should have been in bootstrap.css.

When I run rake assets:precompile locally I get this

quote:

Text file busy - (/media/sf_clunker/tmp/cache/sass/1764c37ed8cf48e1638694abf11caad17c086877/gritter.css.scssc20131110-2125-a7ip2g, /media/sf_clunker/tmp/cache/sass/1764c37ed8cf48e1638694abf11caad17c086877/gritter.css.scssc)

Text file busy? :confused:

KoRMaK fucked around with this message at 05:41 on Nov 11, 2013

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