Recent Posts by jcoffman

Subscribe to Recent Posts by jcoffman 19 posts found

Jul 1, 2008
Avatar jcoffman 19 posts

Topic: General Ruby/Rails Discussion / RESTful resouces & many-many 2: more complicated

UPDATE: I did what I said last, which was to make approvers and projects nested resources on companies. It works and I’m quite happy with it. It simplified a couple things. I also changed from has_many+through to HABTM. Its RESTful and I think the user interaction will make more sense too.

Thanks Jeff.

 
Jun 30, 2008
Avatar jcoffman 19 posts

Topic: General Ruby/Rails Discussion / RESTful resouces & many-many 2: more complicated

hmm… I could probably change to create the project from the company. I hadn’t thought of it in that way. It would simplify my problem.. and possibly also simplify the UI. I could do the same thing for Approvers also since they too belong to a company.

Those would then make sense as nested resource on Companies, which is not a bad idea..

map.resources :companies, :member => { :enable => :put } do |companies|
  companies.resource :approver
  companies.resource :project
end

I’m not exactly sure about the implementation after that but the resource and url of that makes sense to me. I’m gonna guess I need to use that before_filter approach you mentioned above.

 
Jun 30, 2008
Avatar jcoffman 19 posts

Topic: General Ruby/Rails Discussion / RESTful resouces & many-many 2: more complicated

Close enough… I’ll try to use it as a nested resource. /projects/5/approvers is valid ..sort of.. When editing/creating a project, the user picks the company it belongs to. The app then updates/populates the available choices for approvers that belong to the selected company. Lastly, the user can pick which approvers have authority on that project. I’m probably just bad at explaining this.

I think I can bend the nested resource approach to fit my needs. Thanks.

 
Jun 30, 2008
Avatar jcoffman 19 posts

Topic: General Ruby/Rails Discussion / RESTful resouces & many-many 2: more complicated

I decided to try a custom route as in this railscast: http://railscasts.com/episodes/35

Only I’m getting an error trying to use the named path because it is confused between that and the Show request; both are GETS. Anyway, I’m thinking the custom routes stuff has changed since this railscast.

 
Jun 30, 2008
Avatar jcoffman 19 posts

Topic: General Ruby/Rails Discussion / RESTful resouces & many-many 2: more complicated

I’ve thought about this some more. In order to keep it RESTful, I need a new controller for fetching the list of Approvers by company. I just don’t know how to name it without using a verb word in the controller name. Maybe CompanyProjectApprover?

 
Jun 28, 2008
Avatar jcoffman 19 posts

Topic: General Ruby/Rails Discussion / RESTful resouces & many-many 2: more complicated

its restricted so approvers must belong to the same company as the project. I figured I would handle that in code; which means if they change company, I’ll need to make sure I remove approvers that don’t belong. That’s an old problem that i’ve handle a lot in vb & .net.

clarifying…. What throws me off about this is REST. I am not strong enough with it (or ruby/rails) to know how to handle. If I throw REST out the window, I can handle this. I’d really like to learn and grow and stick with REST.

 
Jun 27, 2008
Avatar jcoffman 19 posts

Topic: General Ruby/Rails Discussion / RESTful resouces & many-many 2: more complicated

Yeah, Approvers belong to companies.

ie:

class Company
  has_many: Approver
  has_many: Project
end class
class Approver
  belongs_to: Company #table has company_id attribute
  has_many: Project; though: ProjectApprover
end class
class Project
  belongs_to: Company #table has company_id attribute
  has_many: Approver; though: ProjectApprover
end class
class ProjectApprover
  belongs_to: Project
  belongs_to: Approver
end class

Is that clearer? I think the tricky part is that a user can edit the Project and change the company it belongs to. Based on that, they need to be able to select Approvers for that project. (weird, I know)

 
Jun 27, 2008
Avatar jcoffman 19 posts

Topic: General Ruby/Rails Discussion / RESTful resouces & many-many 2: more complicated

I know it’s not a standard REST method (not one of the magic 7), but would a url like this be considered RESTful:

/projectapprovers/99/list_by_company

or

/projects/99/list_by_company

The “99” in the above url’s being the company_id; the output rendering the list of approvers for that company. I dunno but it doesn’t seem clear or well-related to the resource in either URL. The end user won’t see this url in their browser, but I’m trying to stick with a consistent methodology.

 
Jun 27, 2008
Avatar jcoffman 19 posts

Topic: General Ruby/Rails Discussion / RESTful resouces & many-many 2: more complicated

I was hoping the earlier thread on REST and many-many would be the answer I was looking for, but it didn’t quite address my situation. (Or I’m just dense) I have a many to many with a twist.

The main models are Company, Project, and Approver (one who approves project activities)

Goes like this:

Company has many Project and Approver

Approver belongs to Company

Project belongs to Company

There will be a many-many relationship between project and approver. When the user creates/edits a project, he can pick the company it belongs to. Based on that he should be able to select which approvers are assigned to that project. So there is a many to many between Project and Approver, but is dependent on an editable project attribute of company_id.

I’ve called the many-many model: ProjectApprover (creative, huh?) So we also have this meta:

ProjectApprover belongs to Project and Approver

Project has many Approver thru ProjectApprover

Approver has many Project thru ProjectApprover

How in the world do I make this RESTful? Remember, the user picks the project’s company and then picks the approvers for that project based on the selected company.

thanks -j

 
Jan 11, 2008
Avatar jcoffman 19 posts

Topic: Rails on Windows / rake db:migrate

i changed my approach and it worked out… just generated that scaffolding and starting building from there. thanks for the offer though.

 
Dec 19, 2007
Avatar jcoffman 19 posts

Topic: Rails on Windows / rake db:migrate

This happens to be on windows, but I don’t know if it matters. I have a rails app I’m using to teach myself.. I setup a couple migration files to create, then add a column to a table.

I then pulled that code over to another machine, which does have mysql and the right database on it. However, when I run rake db:migrate, I get the below message. It appears that its not running v1 of the migration before trying v2. I thought rake db:migrate was smart enough to rollup to the current version… am I wrong?

(in C:/Dev/dbtutor) 2 User: migrating ======================================================== —add_column(:users, :email_address, :string) rake aborted! Mysql::Error: #42S02Table ‘testdb.users’ doesn’t exist: ALTER TABLE `users` ADD `email_add ress` varchar(255)

(See full trace by running task with—trace)

 
Dec 18, 2007
Avatar jcoffman 19 posts

Topic: Vent / Any thoughts on Merb?

I want to point out the knocks on ASP.Net should really be directed at ASP.Net webforms. ASP.Net and .Net aren’t really the problem so much as WebForms are. The Castle Project’s MonoRail, inspired by rails, is a replacement for WebForms which is leagues better than WebForms. Of course, it still doesn’t give you the nice framework integrated tools like migrations and mvc code gen with unit test support.

MonoRail makes web development on .Net much better, but not to the degree that ror does.

I haven’t looked at MS MVC yet. still not rails though.

 
Sep 20, 2007
Avatar jcoffman 19 posts

Topic: General Ruby/Rails Discussion / rails on linux

Hi all

I’m just learning ruby & rails, but I’ve been using linux for a while now. I won’t claim to be an expert, but if there are any linux related rails questions I’ll do my best to help.

Speaking of that, is anyone here developing rails on linux?

-j

 
Sep 19, 2007
Avatar jcoffman 19 posts

Topic: General Ruby/Rails Discussion / sending email with rails

HA! got it… sorry for the comment spam. I had the ActionMailer settings in the wrong place in environment.rb. I had to set them at the end of the file; realized they were inside the |config| loop.

Also, sendmail needed to be set to relay mail.

Here are directions and settings after that..

for sendmail: edit /etc/mail/sendmail.mc

change from

dnl define(`SMART_HOST’, `smtp.your.provider’)dnl

to

define(`SMART_HOST’, `smtp.west.cox.net’)dnl

then (as root)

/sbin/service sendmail restart

/sbin/chkconfig sendmail on

my environment.rb settings at the end of the file: ActionMailer::Base.delivery_method = :smtp ActionMailer::Base.raise_delivery_errors = true

ActionMailer::Base.server_settings = {

:address => "smtp.west.cox.net",
:port => 25,
:domain => "localhost.com"

}

 
Sep 19, 2007
Avatar jcoffman 19 posts

Topic: General Ruby/Rails Discussion / sending email with rails

OK, realized I hadn’t restarted webrick, so I did that and got this:

$ ./script/server webrick => Booting WEBrick… /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:266:in `load_missing_constant’: uninitialized constant ActionMailer (NameError) from /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:452:in `const_missing’ from /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:464:in `const_missing’ from ./script/../config/../config/environment.rb:15 from /usr/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/initializer.rb:41:in `run’ from ./script/../config/../config/environment.rb:13 from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require’ from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’ from /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require’ ... 8 levels… from /usr/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/server.rb:39 from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require’ from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’ from ./script/server:3

make sense to anyone?

 
Sep 19, 2007
Avatar jcoffman 19 posts

Topic: General Ruby/Rails Discussion / sending email with rails

sendmail was not running. that’s part of the problem. but not all. I started it, and tried setting ActionMailer delivery to sendmail and the to smtp, but neither worked. I set delivery errors to true, but the log shows the message was processed correctly.

I had to configure sendmail to use the cox smtp server.. still not working, but still working on it.

 
Sep 18, 2007
Avatar jcoffman 19 posts

Topic: General Ruby/Rails Discussion / sending email with rails

I’ll check what smtp server is or isn’t running when I get a chance tonight. I’ll also try sending an email via command line to make sure, then try my ruby code again.

I’ll also update this thread with results, in case it helps anyone else.

-j

 
Sep 18, 2007
Avatar jcoffman 19 posts

Topic: General Ruby/Rails Discussion / sending email with rails

I am a dotnet dev who is teaching myself ruby/rails, and its going well for the most part.

I have one hiccup that I can’t seem to find a right answer to, and that is sending email. I’m doing this on a Fedora linux box, and there might be something I need to setup for it to work. (I think sendmail is off.)

Does anyone have a solution to sending email with rails? any tips for doing it on linux?

Thanks, -j

 
Aug 29, 2007
Avatar jcoffman 19 posts

Topic: General Ruby/Rails Discussion / conversion stories

Hi, I didn’t see another thread about this so.. I was browsing around to see how/why others convert to rails, and what their experience has been.