pw
2012-Jul-14 10:47 UTC
I have no idea how to write clear, confident front-end code for my rails app.
First and foremost: I am not a very experienced web-developer or developer for that matter. I''ve only spent about a year with Rails, however there is something I have noticed about my projects and would like to get off my chest. Please chime in and share your thoughts. The Model-part of things is clearly structured and well tested and as a result of that I have a lot of confidence in that code. In my opinion this is one positive effect of “Convention over Configuration”, even as a newcomer it didn’t take a lot of time till I learned via IRC or a Screen/Podcast: “Hey! This code belongs in the model”. Also there are a lot of discussions going on in the community (Jim Weirich, Avdi Grimm, James Edward Grey II and the rest of the Rogues, Gary Bernhardt and many more) about how to organize models/objects in Rails, which I find very helpful. As I move towards the view though, the messier my code becomes. It starts with the controller and a lot of instance variables as I tend to move away from RESTful-Rails. To be more specific: I merge the edit, show and new actions into one. Controllers are still tested though and therefore I am confident that they too, behave as expected. But the intersection between jQuery and CSS tends to be a real problem. One reason is that DOM elements (classes and ids) get mixed with jQuery''s Selectors and I haven’t found a way to decouple this behavior from the classes and ids. Another is I have no real clue where to put my JS, honestly. Currently it’s all in the application.js. Here my code also tends to be untested and as a result I have no confidence in the UI-Code, as soon as a class or id is renamed I have to manually test the whole page. (I understand that there are a lot of JS frameworks trying to solve these problems, but my apps don''t have a ton of JS (800-1000 LOC) and the introduction of a client-side framework might be overkill. I am also under the impression that these frameworks are still under heavy development and the community has not decided which one to use yet.) Now, these “problems” starting with the controller and ending with the view are a result of a motion towards “one-page” applications and away from the (in my understanding) Restful-Rails-apps. But it is obviously the way that a lot of us want to experience and build the web. I guess it boils down to this: I have no idea how to write clear, confident front-end code for my rails app. Could you help me? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/XZ338gPM3q8J. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en-US.
Robert Walker
2012-Jul-17 05:41 UTC
Re: I have no idea how to write clear, confident front-end code for my rails app.
pw wrote in post #1068883:> I have no idea how to write clear, confident front-end code for my rails > app. > > Could you help me?I''m really not sure what you''re expecting here. You''re asking no specific question that I can discern. For example at one point you state the following:> It starts with the controller and a lot of instance variables as I tend to moveaway from RESTful-Rails. Given Rails is designed around REST it''s no wonder you''re having trouble with the framework as you "move away" from its central design. You also mentioned having difficulties testing controller and view logic (as well as JavaScript). I think you''re probably right that a JS framework may be overkill. But, that has little to do with your difficulty in testing you''re code. There are tools and techniques available for testing all aspects of the MVC stack. Really any of the popular testing frameworks can handle most of your needs, whether it be Test::Unit, RSpec or Cucumber. For unit testing JavaScript there is a nice tool called Jasmine for that. http://pivotal.github.com/jasmine/ In any case I can''t really see you getting any of the answers you hope to receive from a forum such as this one. It''s far more likely that any "advice" you get by asking such open-ended and broad-scoped questions will serve to confuse you even further. My advice would be to find a mentor. Preferably someone local where you can sit down with him/her and review the solutions they''ve come up with. It might also be helpful to review some open source code that does similar things to what you want to achieve. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
pw
2012-Jul-18 10:33 UTC
Re: I have no idea how to write clear, confident front-end code for my rails app.
Thank you for your reply, I do realize the open-ended nature of the question, thought I should give it a shot anyway. I love the suggestion of a mentor, unfortunately there are no Rails or even Ruby groups in my area. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/TM8IYT8Z2TkJ. For more options, visit https://groups.google.com/groups/opt_out.
Victor Goff
2012-Jul-18 10:47 UTC
Re: Re: I have no idea how to write clear, confident front-end code for my rails app.
I couldn''t help but notice your message on the list. You don''t have to have a mentor necessarily in your area. I have been teaching and mentoring Ruby since 2008, and doing it all from remote. Now that Google Plus has hangouts that let you share a terminal easily, and voice and video and full desktop sharing if it is needed, along with DropBox, you can pair program and share code and do all of those things that you can do at a desk. There are other options besides those of course, one of which is screen on Linux or Mac, and potentially on Windows as well. So please don''t let that stop you. By the way, I am a mentor at RubyLearning.org you may have seen our blog at http://rubylearning.com/blog and our study notes at http://rubylearning.com Unfortunately, I don''t know Rails. But Ruby we can help you with. Warmest Regards, Victor H. Goff III 維克多 My GPlus Profile <http://bit.ly/rqK71A> Voice (307) 215-9107 On Wed, Jul 18, 2012 at 6:33 AM, pw <weissensteinerp-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thank you for your reply, I do realize the open-ended nature of the > question, > thought I should give it a shot anyway. > > I love the suggestion of a mentor, unfortunately there are no Rails or > even Ruby groups > in my area. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-talk/-/TM8IYT8Z2TkJ. > For more options, visit https://groups.google.com/groups/opt_out. > > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Gintautas Šimkus
2012-Jul-18 11:13 UTC
Re: Re: I have no idea how to write clear, confident front-end code for my rails app.
" To be more specific: I merge the edit, show and new actions into one. " Well just refrain from the urge to compact controllers code to the point of having unreadable, and most importantly, intertwined code (even for yourself, when you come back to that piece of code in a year). STICK to REST. Use redirects or explicit template rendering from a REST action, but NEW is NEW, and CREATE is CREATE. Abstract the same code into private/protected methods. Eventually you''ll come to an implementation that both looks awesome and is well structured, and easy to change (for instance let''s say you want to put 1 extra computation or whatnot into your NEW action, but only that (i.e. not CREATE). Then you got to rethink many actions and test them, branch logic and end with ugly code just 1 thinko from breaking the app. This is totally unnecessary work you are doing, and I guess you''ve realized that because you are asking these questions. I also suggest you diving into RSpec and BDD right off. Don''t just ''try'' it for a few hours, cause then you will probably just drop it. It takes practice to make it extremely useful; at first things go slow, but it pays out in the long run when you have 1000 specs describing behavior and you don''t even have to test stuff while developing, and test for Complete a (simple) project with BDD style. Or just at least write a spec for every bug you encounter while developing the project. You''ll soon enough witness the benefits for yourself. P.S. Some specs, especially view (template) specs seems like an overkill, but it is key for a reliable development IMO. Probably no need for a spec if you are presented with HTML mock, but I am talking about situations when you just have a mental image of what user would see. Then you describe it in specs. And while doing so you''ll often identify weak points of your UI. 2012/7/18 Victor Goff <keeperotphones-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> I couldn''t help but notice your message on the list. > > You don''t have to have a mentor necessarily in your area. I have been > teaching and mentoring Ruby since 2008, and doing it all from remote. > > Now that Google Plus has hangouts that let you share a terminal easily, > and voice and video and full desktop sharing if it is needed, along with > DropBox, you can pair program and share code and do all of those things > that you can do at a desk. > > There are other options besides those of course, one of which is screen on > Linux or Mac, and potentially on Windows as well. > > So please don''t let that stop you. > > By the way, I am a mentor at RubyLearning.org you may have seen our blog > at http://rubylearning.com/blog and our study notes at > http://rubylearning.com > > Unfortunately, I don''t know Rails. But Ruby we can help you with. > Warmest Regards, > > Victor H. Goff III > 維克多 > My GPlus Profile <http://bit.ly/rqK71A> > Voice (307) 215-9107 > > > > > On Wed, Jul 18, 2012 at 6:33 AM, pw <weissensteinerp-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> Thank you for your reply, I do realize the open-ended nature of the >> question, >> thought I should give it a shot anyway. >> >> I love the suggestion of a mentor, unfortunately there are no Rails or >> even Ruby groups >> in my area. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Talk" group. >> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To view this discussion on the web visit >> https://groups.google.com/d/msg/rubyonrails-talk/-/TM8IYT8Z2TkJ. >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit https://groups.google.com/groups/opt_out. > > >Pagarbiai, Gintautas -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Colin Law
2012-Jul-18 11:30 UTC
Re: I have no idea how to write clear, confident front-end code for my rails app.
On 14 July 2012 11:47, pw <weissensteinerp-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> ... > To be more specific: I merge the edit, show and new actions into one.If you find yourself repeating code in these in order to setup data that they all need then you can use before_filter to run that code. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.