|
Arachnamus posted:Does your exe ever actually exit? The web server will hang until the `read` completes. No, it doesn't exit, it waits for user input. An example simple program would be a series of couts in a console like so: "Welcome to Rav's City Generator!" "What is the population of this settlement?" ">" Then it waits for a cin from the console, an inputted number. I thought the IO bit was supposed to print out all the couts, then take in the cins for the program. The programs are all just a series of cin/couts like this. Can ruby do this kind of thing (on windows)? Edit: Tried it out on programs that don't require input, they just open and spit out a ton of info. Those 'connect' and spit out the proper info. It seems that if it requires any kind of input, it hangs, which makes this whole thing impossible unless I know a better way to do it.
|
# ? May 26, 2014 04:39 |
|
|
# ? Jun 3, 2024 22:52 |
|
Ravendas posted:No, it doesn't exit, it waits for user input. An example simple program would be a series of couts in a console like so: IO.popen also takes a block with a single argument, which links to stdin/stdout on in the child process. If your program is waiting on input, write whatever is necessary, then read the results. code:
This is bar coding and I don't have access to a windows machine anyway, but it seems like this is something you'd want.
|
# ? May 26, 2014 06:16 |
|
Ravendas posted:No, it doesn't exit, it waits for user input. An example simple program would be a series of couts in a console like so: The question is less whether Ruby can do it, more whether HTTP can do it. The answer is "not really". The distinction is that you're moving from a stateful interactive environment (a console) to a stateless transactional environment (HTTP). Rack/Sinatra/Rails (and most web servers) are designed around the principle of taking user input via HTTP parameters, running some code to generate an output, then sending that output back to the user. The user (or browser) should be sending their input to your exe in the HTTP params, which you can then feed into the exe to get your output, which you then return to the user. "The Journey Fraternity"'s code suggestion would help with this, but remember this is sequential code that needs to execute and close before the user will see anything, at which point the request is done and you start over again. You don't get any back-and-forth with a vanilla HTTP request. If you want to simulate an interactive terminal on the web, I'd recommend looking into websockets and using a non-HTTP backend as an endpoint for it. There's probably libraries out there for doing console-like stuff on the web. Jaded Burnout fucked around with this message at 11:30 on May 26, 2014 |
# ? May 26, 2014 11:06 |
|
Thanks for the help. It looks like I've got some more reading and googling to do.
|
# ? May 26, 2014 19:20 |
|
OP is a bit out of date, so apologies if this should be common knowledge now. Are there any good resources for people who know Ruby and want to move from Sinatra to Rails? I don't actually have Sinatra experience, but I've used the crap out of Perl's Dancer, which is a clone of Sinatra. I've also got Ruby, just want to dip into the Rails side of things for a new job. I've got Rails In Action 3 & 4 from Manning, which is probably where I'll go if there's nothing better. I've also got a Code Academy subscription that I keep forgetting to cancel, so I could do the Rails for Zombie courses if they're worthwhile. I'm not looking for handholding through the entire process of developing a web app. I want to get up to speed on how to best use Rails. Something like Eloquent Ruby or Well Grounded Rubyist, but for Rails.
|
# ? May 27, 2014 14:43 |
|
EVGA Longoria posted:I'm not looking for handholding through the entire process of developing a web app. I want to get up to speed on how to best use Rails. Something like Eloquent Ruby or Well Grounded Rubyist, but for Rails. You can already program for the web, you might just need a goal and something to hit for reference. Make a Twitter clone, first anonymous, then add users, following, profile pages, and image uploads, in that order.
|
# ? May 27, 2014 21:13 |
|
EVGA Longoria posted:I'm not looking for handholding through the entire process of developing a web app. I want to get up to speed on how to best use Rails. Something like Eloquent Ruby or Well Grounded Rubyist, but for Rails. The Rails 4 Way sounds to be more like what you want. There is also a version for 3 if thats what you are using.
|
# ? May 27, 2014 22:20 |
|
MrDoDo posted:The Rails 4 Way sounds to be more like what you want. There is also a version for 3 if thats what you are using. I'm a web (C# and mvc.net) and mobile developer but I'd like to get into Rails. Would I be better off with a more beginner oriented book? I'm confident in my ability to learn a new language and framework, especially one as well documented as this.
|
# ? May 28, 2014 02:31 |
|
Doh004 posted:I'm a web (C# and mvc.net) and mobile developer but I'd like to get into Rails. Would I be better off with a more beginner oriented book? I'm confident in my ability to learn a new language and framework, especially one as well documented as this. Nah, hop in and go for it using the guides/api docs if you are confident.
|
# ? May 28, 2014 06:16 |
|
Cocoa Crispies posted:You can already program for the web, you might just need a goal and something to hit for reference. Make a Twitter clone, first anonymous, then add users, following, profile pages, and image uploads, in that order. Good idea, and I might end up doing this in the long run. This is roughly what Rails for Zombies does, for reference. MrDoDo posted:The Rails 4 Way sounds to be more like what you want. There is also a version for 3 if thats what you are using. Took a look and it does look to be what I was looking for, thanks. Picked it up and will read it soon.
|
# ? May 28, 2014 14:50 |
|
MrDoDo posted:The Rails 4 Way sounds to be more like what you want. There is also a version for 3 if thats what you are using. I would also like to thank you for this recommendation. It's exactly the kind of book I was looking for.
|
# ? May 30, 2014 03:24 |
|
So say I have a form (using the SimpleForm gem):pre:<%= simple_form_for @person do |f| %> <%= f.input :first_name %> <%= f.input :last_name %> <% end %>
|
# ? Jun 4, 2014 17:13 |
|
mmachine posted:So say I have a form (using the SimpleForm gem): might not be the cleanest looking or most ideal, but the first answer that comes to mind is: Ruby code:
|
# ? Jun 4, 2014 17:51 |
|
kayakyakr posted:might not be the cleanest looking or most ideal, but the first answer that comes to mind is: That is definitely the right idea. The issue I was having is that I was dealing with unlimited nested resources, so I needed to sniff those individually -- just using @person wasn't enough. I did pretty much exactly what you outlined, just like this: Ruby code:
|
# ? Jun 4, 2014 18:40 |
|
Say I have two models Stage - has_many milestones Milestone - belongs_to stage - has a due_date Given that various Stages may overlap (ie the range of its milestones' due_date), what's the best way to retrieve the Stages in order of its earliest milestone? I could do it with ruby but trying to build the right SQL query for it eludes me on this little sleep
|
# ? Jun 5, 2014 20:24 |
|
code:
|
# ? Jun 5, 2014 20:48 |
|
Pardot posted:
That looks close but it's coming back ordered by id, change the schema to insert into stages (id, name) values (2, 'a'), (1, 'b'), (3, 'c'); and you get code:
|
# ? Jun 5, 2014 22:20 |
|
add order by first_date asc to the end
|
# ? Jun 5, 2014 22:45 |
|
Pardot posted:add order by first_date asc to the end I was going to say I tried that but looking at it again I was writing first_milestones. Ugh. Thanks, man.
|
# ? Jun 5, 2014 22:54 |
|
mmachine posted:That is definitely the right idea. The issue I was having is that I was dealing with unlimited nested resources, so I needed to sniff those individually -- just using @person wasn't enough. I did pretty much exactly what you outlined, just like this: If you need to do a lot of this it might be worth subclassing whatever form builder SimpleForm uses and adding a method on it so you can do something like <%= f.input_or_p_tag :first_name %> It would keep your views cleaner and make it easy to make changes across the board down the road if you needed to.
|
# ? Jun 6, 2014 00:59 |
|
So I am working on Facebook login for my new rails project. I have a working setup, but don't know if I missed any security issues. How'd I do? Routes: code:
code:
code:
|
# ? Jun 6, 2014 17:59 |
|
I'm doing the Rails tutorial right now...how do you keep track of all the different gems and frameworks and everything you need to use? I mean, yeah, Gemfiles, but how do you remember what needs to be in the Gemfile? What's the usual procedure if I want to start a new app right from scratch? Is there a canonical list of gems required or something?
|
# ? Jun 13, 2014 02:54 |
|
Pollyanna posted:I'm doing the Rails tutorial right now...how do you keep track of all the different gems and frameworks and everything you need to use? I mean, yeah, Gemfiles, but how do you remember what needs to be in the Gemfile? What's the usual procedure if I want to start a new app right from scratch? Is there a canonical list of gems required or something? You get a gemfile that describes what you need when you generate an application?
|
# ? Jun 13, 2014 03:04 |
|
Pollyanna posted:I'm doing the Rails tutorial right now...how do you keep track of all the different gems and frameworks and everything you need to use? I mean, yeah, Gemfiles, but how do you remember what needs to be in the Gemfile? What's the usual procedure if I want to start a new app right from scratch? Is there a canonical list of gems required or something?
|
# ? Jun 13, 2014 03:12 |
|
Pollyanna posted:I'm doing the Rails tutorial right now...how do you keep track of all the different gems and frameworks and everything you need to use? I mean, yeah, Gemfiles, but how do you remember what needs to be in the Gemfile? What's the usual procedure if I want to start a new app right from scratch? Is there a canonical list of gems required or something? How do you remember the ingredients to a recipe? Start with one that's written down by someone else (like the one Rails generates for you with a new application), and over time as you make changes based on your needs and preferences you'll find you know it from scratch.
|
# ? Jun 13, 2014 10:11 |
|
Right, I think I get it...but then the Rails tutorial goes through setting up authentication and factories and stuff from scratch. Am I basically gonna be replicating the Rails tutorial every time I want to set up something with authentication and a database?
|
# ? Jun 13, 2014 15:18 |
|
Pollyanna posted:Right, I think I get it...but then the Rails tutorial goes through setting up authentication and factories and stuff from scratch. Am I basically gonna be replicating the Rails tutorial every time I want to set up something with authentication and a database? Only in the sense that yes, you're going to have to actually write your application. Eventually you figure out what gems best handle common tasks (like authentication) for you, and maybe even write a few of your own to encapsulate anything you find yourself writing over and over again.
|
# ? Jun 13, 2014 15:27 |
|
Well yeah, I understand that I'll have to write something myself. But I'm a programmer, so I'm lazy, and I wanna focus on the unique parts of my application rather than "okay, here's how we validate an email, here's how we make a private method to hash a remember token...". Finding gems that help seems to be the solution.
|
# ? Jun 13, 2014 15:33 |
|
Pollyanna posted:Well yeah, I understand that I'll have to write something myself. But I'm a programmer, so I'm lazy, and I wanna focus on the unique parts of my application rather than "okay, here's how we validate an email, here's how we make a private method to hash a remember token...". Finding gems that help seems to be the solution. Don't mean to be, "hey google it", but google is a good source to look up those gems. Also https://www.ruby-toolbox.com/ is a great place to search as well.
|
# ? Jun 13, 2014 15:37 |
|
Pollyanna posted:Well yeah, I understand that I'll have to write something myself. But I'm a programmer, so I'm lazy, and I wanna focus on the unique parts of my application rather than "okay, here's how we validate an email, here's how we make a private method to hash a remember token...". Finding gems that help seems to be the solution.
|
# ? Jun 13, 2014 15:38 |
|
I don't mean to ask you to tell me what to do, but I was wondering to what extent I needed to be familiar with the underpinnings of Rails, like it goes through in the tutorial. Not that I don't appreciate the familiarity and I'm certainly learning, but I wanna focus on the parts of the application that are least likely to already have an implementation.
|
# ? Jun 13, 2014 15:45 |
|
You don't strictly need to be familiar with the underpinnings of Rails, but it'll be a hell of a lot easier to swap out convention for something that works better (or even customize one of those existing implementations) if you are. Debugging's also easier if you have half a clue what's supposed to be happening. 99% of the Rails questions on Stack Overflow wouldn't be asked if the poster had taken the time to understand how anything they were using worked. The people who rag on Rails for having "too much magic" tend to be the people who never learned (a) how it works or (b) Ruby. It's very easy to mindlessly crap out half a site and suddenly realize you're now way beyond your depth. Rails has either a gentle learning curve or an arduous learning 90-degree-angle depending on how you approach it. Or to quote the Devise authentication framework (one of the first places people end up very out of their depth): quote:If you are building your first Rails application, we recommend you to not use Devise. Devise requires a good understanding of the Rails Framework. In such cases, we advise you to start a simple authentication system from scratch, today we have two resources: Molten Llama fucked around with this message at 16:06 on Jun 13, 2014 |
# ? Jun 13, 2014 16:04 |
|
My one major tip: learn where your gem libs are and dig around in them. Sometimes the documentation is on the github site, but if you get into the code you'll see all sorts of helpful comments. I had to do this with attr_encrypted when we realized that it wasn't using IV and Salt. Someone forked it, made the improvement, and then it was merged back into attr_encrypted but no documentation talked about it. I eventually got into the library and started doing searches for keywords and found what I needed. The other thing I did was made my own helper function, I extended serialize to has_many_serialized and now I can use that in my models. I was helped out by looking at how serialize is defined (seen here https://github.com/rails/rails/blob...erialization.rb ) Changing topics, I just had to wrestle with rails to get it to update one column. Doing the following resulted in no changes being sent to the db Ruby code:
Ruby code:
|
# ? Jun 13, 2014 16:32 |
|
KoRMaK posted:My one major tip: learn where your gem libs are and dig around in them. Sometimes the documentation is on the github site, but if you get into the code you'll see all sorts of helpful comments. I had to do this with attr_encrypted when we realized that it wasn't using IV and Salt. Someone forked it, made the improvement, and then it was merged back into attr_encrypted but no documentation talked about it. I eventually got into the library and started doing searches for keywords and found what I needed. You'd want to call "title_will_change!" at the top of my_function unless the character was the same. Ruby code:
|
# ? Jun 13, 2014 16:59 |
|
The Journey Fraternity posted:You'd want to call "title_will_change!" at the top of my_function unless the character was the same.
|
# ? Jun 13, 2014 17:16 |
|
KoRMaK posted:Oh, okay. Thanks! Also, why? Is _title and @my_thing.title the same object in memory? I thought doing _title = @my_thing.title would create a new instance of the string. And when I set @my_thing.title = _title it would see that there was a different string set. When you're doing assignment in Ruby, it's by reference- two names pointing to the same thing. Ruby code:
If you straight-up need copies and you know you do, look at Object#dup and Object#clone.
|
# ? Jun 13, 2014 18:30 |
|
The Journey Fraternity posted:When you're doing assignment in Ruby, it's by reference- two names pointing to the same thing. Ruby code:
|
# ? Jun 13, 2014 21:40 |
|
KoRMaK posted:That explains it and is really important to know. So I could have done the following Yes, though `my_thing.title.dup` is a better option.
|
# ? Jun 13, 2014 22:19 |
|
Are there any recommended plugins for Rails dev in Sublime? I saw a couple regarding snippets and partials, but both of them were kinda mediocre. Plus, I'd like to have something that automatically detects if I make an .html.erb file and treats it as such.
|
# ? Jun 14, 2014 13:17 |
|
|
# ? Jun 3, 2024 22:52 |
You might want to look into Rubymine for an IDE. I'm technically faster in VIM but being able to run your specs inline is really handy for workflow.
|
|
# ? Jun 16, 2014 15:59 |