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 move

away 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.

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.

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

Voice (307) 215-9107

"

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.