|
manero posted:Look for a local Ruby or Rails user group -- I organize the MN Ruby user group, and it's an awesome way to learn and network with people. This is a good idea. I know Austin has one that is filled with companies looking for Rails people. They do monthly meetings with two presentations where the first is geared toward rails beginners.
|
# ¿ Jun 23, 2013 21:56 |
|
|
# ¿ Apr 27, 2024 07:23 |
|
mmachine posted:So question is, how do I get the Book CanCan permissions defined already in my ability.rb to descend to child record(s) of the Book model? CanCan documentation reads like this should happen based on my native model definitions for the app, but that doesn't seem to be the case. Do I also need to define relationships within CanCan's Ability model or what? If so, is there a decent example someone can provide? How are you assigning to the pages class? If you aren't assigning via the book class, then it probably won't pick up the CanCan ability. I'm not sure if just doing book.pages.create will be enough to assign through books.
|
# ¿ Jun 25, 2013 02:15 |
|
mmachine posted:I'm assigning page classes for my application via the core model definitions for my app. That relationship has been in place for a while now, and works no problem. The CanCan implementation is pretty recent, which is why I'm kind of confused as to where I'm not re-affirming these relationships for CanCan. Sorry, I was wrong on how CanCan is implemented. New set of questions about your implementation: Are you using shallow routes (/pages/:id) or deep routes (/books/:book_id/pages/:id)? Outside of the load_and_authorize_resource block, how are you using CanCan? One note in my searches that I ran across: to use load_and_authorize, CanCan needs some sort of searching done on its ability. Your ability file could theoretically be designed as code:
|
# ¿ Jun 25, 2013 14:18 |
|
Time Zones in any language are a huge pain in the rear end. If you have a particular zone you want the time in, you can use code:
|
# ¿ Jul 9, 2013 21:17 |
|
soullessshoe posted:Regarding the timezones: the offset is coming from client side, being saved to a cookie, then read server-side. Ok, so my understanding might be too simple, but how about outputting date to string, parsing it server side, and taking what you get in ruby? With some manipulation it would give you the right zone without worrying about DST. JS: code:
code:
|
# ¿ Jul 9, 2013 23:56 |
|
New is a view-only route. The create is triggered by POSTing the index route, ie athlete_training_plans_path. The route helper you should be using shows on the left side of the route output and is the last one listed above. Create (POST) is athlete_training_plans, Update (PUT) and destroy (DELETE) are both on athlete_training_plan. New and Edit just get the forms, you don't post back to them.
|
# ¿ Jul 10, 2013 21:19 |
|
KoRMaK posted: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? Are they on a different layout? As long as they're in the same layout, they should be including application. Otherwise, make sure whatever layout they're in is including application.js. The asset pipeline doesn't really care much about routes. Newbsylberry posted:
Selected just the code that's causing you issues. edit_athlete_training_plan_path is expecting an athlete id and a training plan id. Apparently it's not smart enough to pull those off of the object, but you can. code:
|
# ¿ Jul 12, 2013 18:28 |
|
Lexicon posted:Wondering if you guys have any thoughts on migrating a table from being in MySQL to some sort of non-relational form? Our app has a table with several million rows, and is growing rapidly. One of the columns is a hash that we manipulate/store various elements in that don't otherwise belong as columns, but is serialized as JSON. I enjoy Mongoid as an ORM. Does a good job and is pretty easy to move over to for those used to relational db's. I don't know how migrating to it would go. Are you sure you shouldn't just refactor your current relational database? A meta column is usually not a good idea and when your table is going to grow to to millions of rows, that means you've got other things going on.
|
# ¿ Jul 12, 2013 22:49 |
|
Obsurveyor posted:Development machine with identical staging and production machines. Dev and staging servers are virtual machines. Development happens on dev machine. Seperate development and master trees. Development branches get merged to development tree when tests pass and then pushed to staging server with capistrano for testing/preview/etc. Once the code is ready, it gets merged into the master tree and put into production. Staging server also lets the marketing person create content without making it available to the public. This is probably the safest, most "correct" process. For most of the stuff I do, I've gotten into the habit of testing locally and pushing straight to the production server. *shrug* It is what it is. theodop posted:Do people typically use an IDE with git integration as their main platform, and then when it comes time to affect changes copy the files to the dev environment on the server, run the migrations, and then test, and if it's all good repeat the process for live? I think most people use command line git and then either capistrano or an environment like heroku where a remote repository lives on the production server and promoting to production is just a matter of pushing to it. If you're working with rails, get comfortable with terminals and your productivity will go way up.
|
# ¿ Jul 16, 2013 14:36 |
|
KoRMaK posted:Instead of writing that as SQL I would have written it as a ruby loop. Unless it's a very small amount of data that you are migrating, don't do this. Write SQL to do mass inserts and decrease your downtime. Also, I would suggest writing local classes to the migration to handle things that you may need. This way, if you ever change the classes in the codebase in the future, your migration will still work. MyClass.reset_column_information will reload the tables. Having to restart the server shouldn't be a huge issue because you're going to be running this migration in a Capistrano update task, right? Right?!
|
# ¿ Jul 17, 2013 23:48 |
|
Newbsylberry posted:I can't seem to figure this out, it seems like it should be working correctly. training_plan_params is a method: As you pointed out, training_plan_params is a method. You want: code:
e: I was looking at the state of running background tasks and such. Right now it looks like the top two options for running anything separate the request thread are delayed job and resque, correct? Would I be daft if I made a gem that used thread pooling and ran background items (example: sending mails) in threads attached to the server instance? kayakyakr fucked around with this message at 23:45 on Jul 18, 2013 |
# ¿ Jul 18, 2013 23:42 |
|
Safe and Secure! posted:Is there anything I can do, or any reason for me, to try prevent users from entering dangerous stuff as, say, usernames and email addresses in my Rails 4 app? I know there's a sanitize helper for the views, and I guess I could just run input through that before creating a model, but I'm interested in validations for this. What are you trying to protect from? Injection attacks? Setting values that they aren't supposed to be accessing? Any model changes (ie Model.create, Model.update) sanitize their values on setting them. The ARQI where method also sanitizes the values coming in. The "rails way" is fairly strong against injection attacks, just as long as you go through the sanitized methods. If you're worried about mass assignment problems, this is the new way to do it in rails 4: http://api.rubyonrails.org/classes/ActionController/StrongParameters.html You should validate, but I prefer to keep validation to business logic. Unless there's a particular attack or vulnerability that you're worried about, I'd suggest the same. In your case, this would be validating that it is a valid email and validating the uniqueness of the username and email.
|
# ¿ Jul 22, 2013 08:48 |
|
Safe and Secure! posted:I was thinking primarily of preventing someone from sticking script tags in a username field, but I'd like to protect against whatever is feasible for me to be protecting from before sticking stuff into my database. pretty much. Use any one of a million standard email regex queries that are on the net, but don't worry too much about having to sanitize every value that comes in, as long as you're using rails' standard methods to put that data in place. Though if you want to insult people trying simple injection attacks, that would be a good use of pre-checking.
|
# ¿ Jul 22, 2013 15:28 |
|
Smol posted:That's great if you can send an test email to the user (e.g. a registration confirmation email). If not, I'll be more careful about it. Won't use any regex to do the validation though. how are you being more careful, per se?
|
# ¿ Jul 25, 2013 16:30 |
|
manero posted:Guys, email-based activation is really easy to do. I avoid confirmation emails because it kills conversion. Especially when you're trying to get less technical people to follow through. Ugh, the non-technicals.
|
# ¿ Jul 29, 2013 01:51 |
|
manero posted:Edit: Then again, validating all the comments of a giant thread is probably not the best idea. But if it's just on thread create, it might not be too bad since there would only be 1 comment to validate.
|
# ¿ Jul 31, 2013 15:25 |
|
QPZIL posted:The problem: when I go to the signup page (/signup) directly, it works fine. When I get to it via a "link_to" on my front page, none of the Javascript works. Is there some Ajax thing going on? Should I be using something other than $(document).ready to initialize my script? It sounds like you're using turbolinks, and you can't use document.ready with that. See: https://github.com/rails/turbolinks/#events Also, not that it's much different, but I've always preferred to do my on-load as code:
code:
kayakyakr fucked around with this message at 15:30 on Aug 8, 2013 |
# ¿ Aug 8, 2013 15:28 |
|
Safe and Secure! posted:Yeah, I'm using that - I'm just taking the :page_number from the URL and handing it to will_paginate. I'm just not sure if I really should be using route parameters for this instead of a query string. No, query strings aren't frowned upon. You can make "nice" URLs and be happy, but for something like a forum... it's not worth it.
|
# ¿ Aug 9, 2013 05:57 |
|
DreadCthulhu posted:Define simple? Simple for whom, for the backend or the client? For yourself. Also the client, but mostly for yourself.
|
# ¿ Aug 17, 2013 00:00 |
|
I've gone over to Rspec, with Rspec-given, Shoulda, and FactoryGirl. When I test. That's still my greatest weakness as a programmer.
|
# ¿ Aug 18, 2013 03:06 |
|
Cocoa Crispies posted:It's very very high level integration testing: I use it as a to-do list that checks itself off. I've heard that you should write scenarios in a way that you could use the same set of scenarios for HTML, iOS, and Android versions of an application. When I was writing heavy cucumber tests, I was going with the style of writing very generic, basic commands similar to what you have written and then making the step definitions more complex. My biggest problem with cucumber is that it's an awful idea to use for testing a heavy javascript front end. It can do it, but good lord it takes a long time. Our (moderately complex) web app took in the order of an hour to run the test suite. Granted a lot of that could have been the terrible decision to use ExtJS.
|
# ¿ Aug 19, 2013 23:25 |
|
Peristalsis posted:I have three questions, but there's a wall o' text first. I would suggest making a standard rails app but instead of (or in addition to) html.erb files, write json.jbuilder views. Makes a pretty good web service endpoint. You can use basic auth + https and cookies to do that or you could implement an api key/secret thing. You might look into seeing if anyone else has implemented a jsonp renderer on top of jbuilder.
|
# ¿ Aug 20, 2013 18:28 |
|
Peristalsis posted:It's in addition to, but I'm inclined to stick with XML for the first version, if only because one of the people writing the client code isn't a programmer. He's more likely to be familiar with XML than with JSON. I'm also not sure he's going to like shoe-horning curl commands into his R scripts, but I guess he'll have to get over it. I found info on RCurl for him, so at least he shouldn't have to shell out to the OS to make it work. Eventually, I'd like to allow both approaches (XML and JSON), probably through different Rails routes. For XML use Builder: https://github.com/jimweirich/builder Don't use routing tricks, use the format parameter. Example: /users => html /users.json => json /users.xml => xml Rails knows, via respond_to/respond_with which views to render for each. Support all of the API languages in one shot and be happy. Use standard form posts and url params for bringing data in.
|
# ¿ Aug 20, 2013 20:52 |
|
Peristalsis posted:Edit: I've probably been unclear - for the most part, I'll be reading the XML, and parsing it. I might pass back query results in XML, as well, but my main problem is passing the client's XML into my code and parsing it. oh, gross. Umm, I'm still a fan of taking in data in a standard post body rather than encoded as an XML field. But there is middleware for that: https://github.com/rails/actionpack-xml_parser
|
# ¿ Aug 20, 2013 22:49 |
|
Deus Rex posted:Anyone have thoughts on JBuilder vs. RABL for building a JSON API? I'm building an Angular app with a Rails backend and I don't think hacking around as_json is going to cut it as I've done in the past. jbuilder is sorta the culmination of all of those that came before it. I really prefer jbuilder.
|
# ¿ Aug 21, 2013 03:52 |
|
Pollyanna posted:I'm having trouble installing recent versions of Ruby onto my OSX computer. I tried using the RVM, but it somehow managed to mess up whatever version I was using at the time. What's the most newbie-friendly recommended way to install Ruby, Rails, and whatever? RVM is supposed to be the easiest. You install RVM, install a ruby, then run code:
http://railsinstaller.org/en#osx
|
# ¿ Aug 21, 2013 18:27 |
|
I hated rubymine. Way more than you could ever need and java-based so it's performance was horrible.
|
# ¿ Aug 21, 2013 19:23 |
|
Smol posted:I hope that you're not seriously as a Ruby developer complaining about Java performance. Java GUI performance on Linux machines using any sane upper memory limit is pretty terrible. Maybe on mac, rubymine runs better? I dunno, to me it was pretty crap. Sil posted:tldr+warning: rails noob(?) not sure what I know, what to do next. Reading through that, you're absolutely entry level rails. You have more experience with Rails than the last guy I hired. If you understand programming and understand how to get things done, you'll be ok. Pollyanna posted:Right, I forgot. So how do people make games and applications in Ruby, then? Is everything just run from the terminal? Mostly run from terminal or started as a server. It is possible to write desktop apps in ruby, though. Ruby Toolbox is a great place to look up what sort of things people have come up with. https://www.ruby-toolbox.com/categories/game_libraries https://www.ruby-toolbox.com/categories/packaging_to_executables https://www.ruby-toolbox.com/categories/GUI_Frameworks
|
# ¿ Aug 21, 2013 23:52 |
|
chumpchous posted:Question: I had a bug in my application that was causing the DB to lock up when a form got double posted. I switched to postgres and fixed some issues, but I've never actually managed to replicate the bug. The post is submitted via JSON, and I've tried just sending multiple JSON posts but it wont happen. I've also tried manually clicking the button really fast but that doesn't do it either. Still though, users are managing to pull it off. Any tips? Were you using sqlite? Were you using a multi-instance server like unicorn? If so, that was your problem.
|
# ¿ Aug 23, 2013 19:29 |
|
chumpchous posted:Yeah I was using SQLite, and now I'm using postgres, so the problem is fixed. I just want to know how to test for the error, because I can't replicate it (on a server using an SQLite db). The problem is sqlite is single threaded. It works until someone hits the database at the same time as someone else. If you were using unicorn, this would happen any time two requests are submitted at the same time. You can't really test for the error, you just have to know that if you're using sqlite, you can only use one server process at a time.
|
# ¿ Aug 23, 2013 21:21 |
|
EAT THE EGGS RICOLA posted:Are there any decent ruby gems for doing decent visualizations, in the form of graphs/charts/maps/anything? I have a bunch of varied datasets that I've been asked to make interesting with, and all of my code that works with the api is ruby-based so I'd like to just carry on with that. There isn't really one. I was working on making one, but haven't fully gemified it yet. Ran out of time. e: this is awful code and you should by no means copy it because it breaks about 20 standard rails conventions, but this makes a pretty nice line chart: https://github.com/talho/epi_full/blob/master/app/views/svg/line.svg.erb
|
# ¿ Aug 24, 2013 21:48 |
|
For building XML responses, you could always use erb. create a view named action.xml.erb and write XML as if you were writing an HTML view. This doesn't work as well if you're trying to send XML to a different webservice
|
# ¿ Aug 26, 2013 19:07 |
|
Baron Dirigible posted:(Edit: I think I understand now, but just to be certain: with a belongs_to: through: I need to create another model in Rails, but with has_and_belongs_to: I just need to create a join table in the migrate file / directly in mySQL?) You are correct. habtm does not have an associated model while hmt does. Baron Dirigible posted:Secondly, is there a good resource out there for how to use an existing MySQL database with Rails? Everything I've seen assumes I'm setting up and migrating from scratch, but I have the database already set up and populated and just need to know how much of the structure I need to declare for Rails. rake db:schema:dump will create a schema from the database. You'll have to create all the models manually.
|
# ¿ Sep 1, 2013 17:16 |
|
Peristalsis posted:I was confused about this recently, too. habtm is a bit of that Rails magic that you must know about to use. You have to create a table in both cases, and that table must include id's from both sides of the relation. The difference is that habtm doesn't have an id for itself and there is no model for it. I'd say that hmt doesn't use a join table because that table represents something else in your database other than just a join between the two tables. If the join between the two has no context (ie the only thing you'll ever be doing is joining the two) then the proper relationship to use is habtm. The join table is not really a reminder thing, it's necessary to make the habtm work
|
# ¿ Sep 1, 2013 23:51 |
|
Cocoa Crispies posted:This is, of course, never true unless it's the simplest throwaway project. Assigning a name, model, and behavior to the relationship between two entities not only provides for future extensibility, but it helps you understand and reason about the relationship better. I disagree, but that's probably because I wrote SQL in my past life.
|
# ¿ Sep 2, 2013 07:02 |
|
I've been using amazon's elastic beanstalk, another service that you can get free (for a year). It's ok. I mean, it's pretty poo poo because it's amazon micro, but it's ok and not hard to deploy to.
|
# ¿ Sep 6, 2013 05:27 |
|
Sub Par posted:I'm building a simple search form and trying to determine if this approach is safe from an SQL injection point of view: That should be ok. The cleaner will clean the full string out. If you get anything more complex than that, you should really look into integrating sphinx. Peristalsis posted:Oh, and one more question. Did you reload owner1 between creating your new product object? Otherwise, it'll probably just cache the last products lookup. Are you use the product object is saving and are you sure that's the proper id?
|
# ¿ Sep 9, 2013 23:19 |
|
Sub Par posted:Thanks. I plan to, once I can spend some money. what are you hosting on? we successfully ran sphinx + thinking_sphinx (rails gem) side-by-side with unicorn on a single virtual server.
|
# ¿ Sep 10, 2013 00:55 |
|
Sub Par posted:I have a proof of concept type thing up on Heroku and am just trying to drum up interest in the idea. If I can get my friends on board and put up a small amount of cash I am going to go with a VPS, but Heroku for now. Not worth even the $12/mo for the sphinx-based add-ons right now for my ~600 users. ~600 users is not bad for a proof of concept on heroku. I know a lot of people hate it, but you could get a 2 core, 40 GB VPS on digital ocean for $20/month.
|
# ¿ Sep 10, 2013 03:07 |
|
|
# ¿ Apr 27, 2024 07:23 |
|
I learned how to use capistrano not too long ago so setting up a new environment from scratch with that is two commands and about 10 minutes. ignore the other horrible code in this project, this is a simple capistrano deploy script: https://github.com/Yakrware/sum_times/blob/master/config/deploy.rb plus https://github.com/Yakrware/sum_times/blob/master/config/deploy/production.rb.example in others I've got it installing requirements in the setup and you can script it to set up nginx or whatever you need.
|
# ¿ Sep 11, 2013 02:53 |