From merb at dusty.name Thu Jul 12 00:42:29 2007 From: merb at dusty.name (Dusty Doris) Date: Thu, 12 Jul 2007 00:42:29 -0400 Subject: routing question Message-ID: I am going to be building a project and have been considering giving a go at merb for it. I don't necessarily need a speed increase and rails would certainly serve my needs well. However, it just looks so clean, I have to try it out. I also don't really use (know) all the extra rails stuff much, so I really just want activerecord and an MVC pattern. Perfect! So, one of my requirements is usually to have a separate admin interface. What would be the recommended way to do this using merb? eg: r.resources :posts # for the public r.resources :admin_posts # for the admin section It would be nice to simply have a namespace, such as in rails where I'd so something like: r.resources :posts, :path_prefix => "admin", :controller => "admin/products", :name_prefix => "admin" However, it doesn't look like to me like merb is setup for anything like that right now. How are current users doing this kind of routing? Is there a reason against this that I haven't thought of or listened to yet? Perhaps a better way? Thanks for your opinions. -Dusty Doris From has.sox at gmail.com Fri Jul 13 03:22:54 2007 From: has.sox at gmail.com (Daniel N) Date: Fri, 13 Jul 2007 17:22:54 +1000 Subject: Regexp Question - Merb::Router Message-ID: <2fff50390707130022g141ce344o2896205eb0079169@mail.gmail.com> Hi, I'm looking through the Merb::Routing code and I've found a regexp that I can't figure out how it works. Merb::Router::SECTION_REGEXP #=> /(?::([a-z*_]+))/ It takes a route definition string, like "/products/:model/:id" and extracts the "model" string on the first pass, and later the "id" string. Can anyone shed some light on what the ?:: part does? I haven't found it in any of the documentation for Ruby Regexps that I've found. Cheers Daniel -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/merb-devel/attachments/20070713/a37111cb/attachment.html From alexkwolfe at gmail.com Fri Jul 13 10:24:38 2007 From: alexkwolfe at gmail.com (Alex Wolfe) Date: Fri, 13 Jul 2007 09:24:38 -0500 Subject: Regexp Question - Merb::Router In-Reply-To: <2fff50390707130022g141ce344o2896205eb0079169@mail.gmail.com> References: <2fff50390707130022g141ce344o2896205eb0079169@mail.gmail.com> Message-ID: <8C06581B-A4FD-427E-865E-22BF8CD93A88@gmail.com> ?: is used inside parentheses to indicate that they shouldn't be used as a match group. The second colon is used here as a literal. On Jul 13, 2007, at 2:22 AM, Daniel N wrote: > Hi, > > I'm looking through the Merb::Routing code and I've found a regexp > that I can't figure out how it works. > > Merb::Router::SECTION_REGEXP #=> /(?::([a-z*_]+))/ > > It takes a route definition string, like "/products/:model/:id" > and extracts the "model" string on the first pass, and later the > "id" string. > > Can anyone shed some light on what the > ?:: > part does? I haven't found it in any of the documentation for Ruby > Regexps that I've found. > > Cheers > Daniel > > _______________________________________________ > Merb-devel mailing list > Merb-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/merb-devel From merb at dusty.name Sat Jul 14 21:07:57 2007 From: merb at dusty.name (Dusty Doris) Date: Sat, 14 Jul 2007 21:07:57 -0400 Subject: errors_for Message-ID: Been playing with merb. One of the helpers I liked in rails was on form validations. Found this was real easy to port over, so I thought I'd share. It doesn't highlight the field with the error, but it gives that same nice little div on top. Say I had an articles controller def create @article = Article.new(params[:article]) @article.save! redirect article_path(@article) rescue render :action => 'new' end I would catch the activerecord exception there with the rescue Then in global_helper.rb, I add the error_messages_for method. This is taken from rails and stripped of some of its pieces like content_tag and pluralize. I'm sure more of it could be cleaned up if you wanted to. def error_messages_for(*params) options = params.last.is_a?(Hash) ? params.pop.symbolize_keys : {} objects = params.collect {|object_name| instance_variable_get("@#{object_name}") }.compact count = objects.inject(0) {|sum, object| sum + object.errors.count } unless count.zero? html = {} [:id, :class].each do |key| if options.include?(key) value = options[key] html[key] = value unless value.blank? else html[key] = 'errorExplanation' end end header_message = "Errors prohibited this #{(options[:object_name] || params.first).to_s.gsub('_', ' ')} from being saved" error_messages = objects.map {|object| object.errors.full_messages.map {|msg| "
  • #{msg}
  • " } } "

    #{header_message}

    There were problems with the following fields:

      #{error_messages}
    " else '' end end in your _form.herb, you simply call error_messages_for <%= error_messages_for 'article' %>
    Title
    <%= control_for @article, :title, :text %>
    Intro
    <%= control_for @article, :intro, :textarea, :rows => 10, :cols => 50 %>
    Body
    <%= control_for @article, :body, :textarea, :rows => 20, :cols => 50 %>
    When you try to save something that fails validation, you get your nice error div.

    Errors prohibited this article from being saved

    There were problems with the following fields:

    • Title can't be blank
    fun. From has.sox at gmail.com Wed Jul 18 05:59:53 2007 From: has.sox at gmail.com (Daniel N) Date: Wed, 18 Jul 2007 19:59:53 +1000 Subject: Hash.from_xml Message-ID: <2fff50390707180259l1cb3a10bw4a12afac672a2f22@mail.gmail.com> Hi, I've started looking at ticket 90and there are a couple of situations that the current implementation doesn't cater for. 1. Tag Attributes are wiped out. - Content #=> { "tag1" => "Content" } - I think it should return - {"tag1" => { "attr1" => '1', "__content__" => "Content" } 2. Mixed content can throw an error or get clobbered - Content is Clobbered #=> Raises a Private error called on array gsub - Content is #=> Clobbered. Returns {"tag1"=>"Content "} - Feels like it should return - {"tag1"=>"Content <em>is</em>Clobbered" } Is the current behaviour what is required or should these inconsitencies be fixed? Cheers Daniel -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/merb-devel/attachments/20070718/2a033ac5/attachment.html From has.sox at gmail.com Wed Jul 18 06:13:51 2007 From: has.sox at gmail.com (Daniel N) Date: Wed, 18 Jul 2007 20:13:51 +1000 Subject: Hash.from_xml In-Reply-To: <2fff50390707180259l1cb3a10bw4a12afac672a2f22@mail.gmail.com> References: <2fff50390707180259l1cb3a10bw4a12afac672a2f22@mail.gmail.com> Message-ID: <2fff50390707180313q112c5bd6w4a48b88f9e5947f9@mail.gmail.com> On 7/18/07, Daniel N wrote: > > Hi, > > I've started looking at ticket 90and there are a couple of situations that the current implementation doesn't > cater for. > > > 1. Tag Attributes are wiped out. > - Content #=> { "tag1" => "Content" } > - I think it should return > - {"tag1" => { "attr1" => '1', "__content__" => "Content" } > > Seems I was a bit hasty with my conclusion on this one. I still don't think it is correct though. Content results in {"tag1"=>{"strong"=>"Content", "attr"=>"1"}} So it seems that you can only have attributes in an element that does not have a child text element. I also tried this ContentMixed Content and got {"tag1"=>"Mixed Content"} Just to confirm. Any thoughts on what it should be? Cheers Daniel > 1. Mixed content can throw an error or get clobbered > - Content is Clobbered #=> Raises a > Private error called on array gsub > - Content is #=> Clobbered. Returns > {"tag1"=>"Content "} > - Feels like it should return > - {"tag1"=>"Content <em>is</em>Clobbered" } > > > Is the current behaviour what is required or should these inconsitencies > be fixed? > > Cheers > Daniel > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/merb-devel/attachments/20070718/6507da5b/attachment-0001.html From has.sox at gmail.com Wed Jul 18 07:09:23 2007 From: has.sox at gmail.com (Daniel N) Date: Wed, 18 Jul 2007 21:09:23 +1000 Subject: Hash.from_xml In-Reply-To: <2fff50390707180259l1cb3a10bw4a12afac672a2f22@mail.gmail.com> References: <2fff50390707180259l1cb3a10bw4a12afac672a2f22@mail.gmail.com> Message-ID: <2fff50390707180409h4d28280bx7f2b8d4a55813e45@mail.gmail.com> On 7/18/07, Daniel N wrote: > > Hi, > > I've started looking at ticket 90and there are a couple of situations that the current implementation doesn't > cater for. > > > 1. Tag Attributes are wiped out. > - Content #=> { "tag1" => "Content" } > - I think it should return > - {"tag1" => { "attr1" => '1', "__content__" => "Content" } > 2. Mixed content can throw an error or get clobbered > - Content is Clobbered #=> Raises a > Private error called on array gsub > - Content is #=> Clobbered. Returns > {"tag1"=>"Content "} > - Feels like it should return > - {"tag1"=>"Content <em>is</em>Clobbered" } > > Perhaps Content is Clobbered should return { "tag1" => "Content is Clobbered" } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/merb-devel/attachments/20070718/44323236/attachment.html From merb at dusty.name Thu Jul 19 02:23:57 2007 From: merb at dusty.name (Dusty Doris) Date: Thu, 19 Jul 2007 02:23:57 -0400 Subject: Merb::Controller#url Usage Message-ID: I have a question about the usage of Merb::Controller#url. When I have nested resources, requesting the new action works differently than I expected. I was wondering what the intended usage is. For example: Say I have r.resources :articles do |article| article.resources :article_attachments end irb(main):002:0> show_routes [:articles, "/articles"] [:article_attachments, "/articles/:article_id/article_attachments"] [:article_attachment, "/articles/:article_id/article_attachments/:id"] [:edit_article_attachment, "/articles/:article_id/article_attachments/:id/edit"] [:new_article_attachment, "/articles/:article_id/article_attachments/new"] [:custom_new_article_attachment, "/articles/:article_id/article_attachments/new/:action"] [:article, "/articles/:id"] [:edit_article, "/articles/:id/edit"] [:new_article, "/articles/new"] [:custom_new_article, "/articles/new/:action"] => nil If I find an article: irb(main):003:0> article = Article.find(1) => #nil, "updated_at"=>"2007-07-18 21:31:35", "title"=>"asdf", "body"=>nil, "id"=>"1", "article_attachments_count"=>"2", "published_at"=>nil, "created_at"=>"2007-07-18 21:31:35"}> And an attachment of that article: irb(main):004:0> attachment = article.article_attachments.find(1) => #"asdf", "updated_at"=>"2007-07-18 21:38:08", "public"=>"t", "id"=>"1", "filename"=>"asdf", "article_id"=>"1", "position"=>"1", "created_at"=>"2007-07-18 21:38:08"}> My expectation was that I would pass the object I want to evaluate to the url method. This works when I use edit_article_attachment. (note I added some debug puts statements in there before and after the SECTION_REGEXP sub) irb(main):005:0> url(:edit_article_attachment,attachment) --path before: /articles/:article_id/article_attachments/:id/edit --path after: /articles/1/article_attachments/1/edit => "/articles/1/article_attachments/1/edit" However, when having a new form on the page, I typically create the new action with an empty instance of that model. irb(main):006:0> new_attachment = article.article_attachments.new => #nil, "updated_at"=>nil, "public"=>true, "filename"=>nil, "article_id"=>nil, "position"=>nil, "created_at"=>nil}, @new_record=true> But, that model doesn't yet have the article_id attached to it, so the url generation fails. irb(main):007:0> url(:new_article_attachment,new_attachment) --path before: /articles/:article_id/article_attachments/new --path after: /articles//article_attachments/new => "/articles//article_attachments/new" My expectation was that you should send the object that it is nested from, (before I realized what that regex match was doing). But I see that its looking for association id, rather than just the id, so that also fails. irb(main):008:0> url(:new_article_attachment,article) --path before: /articles/:article_id/article_attachments/new --path after: /articles//article_attachments/new => "/articles//article_attachments/new" However, an easy work around is to simply pass it a hash with the correct information in it. irb(main):009:0> url(:new_article_attachment,{:article_id => article.id}) --path before: /articles/:article_id/article_attachments/new --path after: /articles/1/article_attachments/new => "/articles/1/article_attachments/new" Is that the intended behavior? Thanks! Dusty Doris From ez at engineyard.com Thu Jul 19 14:01:22 2007 From: ez at engineyard.com (Ezra Zygmuntowicz) Date: Thu, 19 Jul 2007 11:01:22 -0700 Subject: Merb::Controller#url Usage In-Reply-To: References: Message-ID: <9C32ECA8-FBCB-4906-A218-1CBA49A228C1@engineyard.com> Dusty- The route generation is not fully baked yet. At this point you pass in a hash to fill in the missing parts of the routes. I'm open for suggestions about how this should work though. Cheers- -Ezra On Jul 18, 2007, at 11:23 PM, Dusty Doris wrote: > I have a question about the usage of Merb::Controller#url. When I > have nested resources, requesting the new action works differently > than I expected. I was wondering what the intended usage is. > > For example: > > Say I have > > r.resources :articles do |article| > article.resources :article_attachments > end > > irb(main):002:0> show_routes > > [:articles, "/articles"] > [:article_attachments, "/articles/:article_id/article_attachments"] > [:article_attachment, "/articles/:article_id/article_attachments/:id"] > [:edit_article_attachment, "/articles/:article_id/ > article_attachments/:id/edit"] > [:new_article_attachment, "/articles/:article_id/ > article_attachments/new"] > [:custom_new_article_attachment, > "/articles/:article_id/article_attachments/new/:action"] > [:article, "/articles/:id"] > [:edit_article, "/articles/:id/edit"] > [:new_article, "/articles/new"] > [:custom_new_article, "/articles/new/:action"] > => nil > > If I find an article: > > irb(main):003:0> article = Article.find(1) > > => #nil, > "updated_at"=>"2007-07-18 21:31:35", "title"=>"asdf", "body"=>nil, > "id"=>"1", "article_attachments_count"=>"2", "published_at"=>nil, > "created_at"=>"2007-07-18 21:31:35"}> > > And an attachment of that article: > irb(main):004:0> attachment = article.article_attachments.find(1) > > => #"asdf", > "updated_at"=>"2007-07-18 21:38:08", "public"=>"t", "id"=>"1", > "filename"=>"asdf", "article_id"=>"1", "position"=>"1", > "created_at"=>"2007-07-18 21:38:08"}> > > My expectation was that I would pass the object I want to evaluate to > the url method. This works when I use edit_article_attachment. (note > I added some debug puts statements in there before and after the > SECTION_REGEXP sub) > > irb(main):005:0> url(:edit_article_attachment,attachment) > > --path before: /articles/:article_id/article_attachments/:id/edit > --path after: /articles/1/article_attachments/1/edit > > => "/articles/1/article_attachments/1/edit" > > However, when having a new form on the page, I typically create the > new action with an empty instance of that model. > > irb(main):006:0> new_attachment = article.article_attachments.new > > => #nil, > "updated_at"=>nil, "public"=>true, "filename"=>nil, "article_id"=>nil, > "position"=>nil, "created_at"=>nil}, @new_record=true> > > But, that model doesn't yet have the article_id attached to it, so the > url generation fails. > > irb(main):007:0> url(:new_article_attachment,new_attachment) > > --path before: /articles/:article_id/article_attachments/new > --path after: /articles//article_attachments/new > > => "/articles//article_attachments/new" > > My expectation was that you should send the object that it is nested > from, (before I realized what that regex match was doing). But I see > that its looking for association id, rather than just the id, so that > also fails. > > irb(main):008:0> url(:new_article_attachment,article) > > --path before: /articles/:article_id/article_attachments/new > --path after: /articles//article_attachments/new > > => "/articles//article_attachments/new" > > However, an easy work around is to simply pass it a hash with the > correct information in it. > > irb(main):009:0> url(:new_article_attachment,{:article_id => > article.id}) > > --path before: /articles/:article_id/article_attachments/new > --path after: /articles/1/article_attachments/new > > => "/articles/1/article_attachments/new" > > Is that the intended behavior? > > > Thanks! > > Dusty Doris > _______________________________________________ > Merb-devel mailing list > Merb-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/merb-devel -- Ezra Zygmuntowicz -- Founder & Ruby Hacker -- ez at engineyard.com -- Engine Yard, Serious Rails Hosting -- (866) 518-YARD (9273) From merb at dusty.name Fri Jul 20 11:10:04 2007 From: merb at dusty.name (Dusty Doris) Date: Fri, 20 Jul 2007 11:10:04 -0400 Subject: Merb::Controller#url Usage In-Reply-To: <9C32ECA8-FBCB-4906-A218-1CBA49A228C1@engineyard.com> References: <9C32ECA8-FBCB-4906-A218-1CBA49A228C1@engineyard.com> Message-ID: I've thought about it and I don't have any objections to the current method. It keeps the code lean since you don't need to decide if the url is part of a nested resource. Its really not too much extra work to send the needed hash, and one could always create a helper if they wanted something else. If I come up with any other ideas, I'll be sure to send it this way to see what you guys think. Perhaps I'll submit a patch for some code documentation? Maybe a simple commented out explanation to go above the method? I'll take a look at some other comments and try to model those. Would that be welcome? Is the process for that to create a ticket in trac? Thanks On 7/19/07, Ezra Zygmuntowicz wrote: > Dusty- > > The route generation is not fully baked yet. At this point you pass > in a hash to fill in the missing parts of the routes. I'm open for > suggestions about how this should work though. > > Cheers- > -Ezra > > On Jul 18, 2007, at 11:23 PM, Dusty Doris wrote: > > > I have a question about the usage of Merb::Controller#url. When I > > have nested resources, requesting the new action works differently > > than I expected. I was wondering what the intended usage is. > > > > For example: > > > > Say I have > > > > r.resources :articles do |article| > > article.resources :article_attachments > > end > > > > irb(main):002:0> show_routes > > > > [:articles, "/articles"] > > [:article_attachments, "/articles/:article_id/article_attachments"] > > [:article_attachment, "/articles/:article_id/article_attachments/:id"] > > [:edit_article_attachment, "/articles/:article_id/ > > article_attachments/:id/edit"] > > [:new_article_attachment, "/articles/:article_id/ > > article_attachments/new"] > > [:custom_new_article_attachment, > > "/articles/:article_id/article_attachments/new/:action"] > > [:article, "/articles/:id"] > > [:edit_article, "/articles/:id/edit"] > > [:new_article, "/articles/new"] > > [:custom_new_article, "/articles/new/:action"] > > => nil > > > > If I find an article: > > > > irb(main):003:0> article = Article.find(1) > > > > => #nil, > > "updated_at"=>"2007-07-18 21:31:35", "title"=>"asdf", "body"=>nil, > > "id"=>"1", "article_attachments_count"=>"2", "published_at"=>nil, > > "created_at"=>"2007-07-18 21:31:35"}> > > > > And an attachment of that article: > > irb(main):004:0> attachment = article.article_attachments.find(1) > > > > => #"asdf", > > "updated_at"=>"2007-07-18 21:38:08", "public"=>"t", "id"=>"1", > > "filename"=>"asdf", "article_id"=>"1", "position"=>"1", > > "created_at"=>"2007-07-18 21:38:08"}> > > > > My expectation was that I would pass the object I want to evaluate to > > the url method. This works when I use edit_article_attachment. (note > > I added some debug puts statements in there before and after the > > SECTION_REGEXP sub) > > > > irb(main):005:0> url(:edit_article_attachment,attachment) > > > > --path before: /articles/:article_id/article_attachments/:id/edit > > --path after: /articles/1/article_attachments/1/edit > > > > => "/articles/1/article_attachments/1/edit" > > > > However, when having a new form on the page, I typically create the > > new action with an empty instance of that model. > > > > irb(main):006:0> new_attachment = article.article_attachments.new > > > > => #nil, > > "updated_at"=>nil, "public"=>true, "filename"=>nil, "article_id"=>nil, > > "position"=>nil, "created_at"=>nil}, @new_record=true> > > > > But, that model doesn't yet have the article_id attached to it, so the > > url generation fails. > > > > irb(main):007:0> url(:new_article_attachment,new_attachment) > > > > --path before: /articles/:article_id/article_attachments/new > > --path after: /articles//article_attachments/new > > > > => "/articles//article_attachments/new" > > > > My expectation was that you should send the object that it is nested > > from, (before I realized what that regex match was doing). But I see > > that its looking for association id, rather than just the id, so that > > also fails. > > > > irb(main):008:0> url(:new_article_attachment,article) > > > > --path before: /articles/:article_id/article_attachments/new > > --path after: /articles//article_attachments/new > > > > => "/articles//article_attachments/new" > > > > However, an easy work around is to simply pass it a hash with the > > correct information in it. > > > > irb(main):009:0> url(:new_article_attachment,{:article_id => > > article.id}) > > > > --path before: /articles/:article_id/article_attachments/new > > --path after: /articles/1/article_attachments/new > > > > => "/articles/1/article_attachments/new" > > > > Is that the intended behavior? > > > > > > Thanks! > > > > Dusty Doris > > _______________________________________________ > > Merb-devel mailing list > > Merb-devel at rubyforge.org > > http://rubyforge.org/mailman/listinfo/merb-devel > > -- Ezra Zygmuntowicz > -- Founder & Ruby Hacker > -- ez at engineyard.com > -- Engine Yard, Serious Rails Hosting > -- (866) 518-YARD (9273) > > > From scaudill at gmail.com Sat Jul 21 15:15:04 2007 From: scaudill at gmail.com (Stephen Caudill) Date: Sat, 21 Jul 2007 15:15:04 -0400 Subject: Merb::Controller#url Usage In-Reply-To: References: <9C32ECA8-FBCB-4906-A218-1CBA49A228C1@engineyard.com> Message-ID: On Jul 20, 2007, at 11:10 AM, Dusty Doris wrote: > If I come up with any other ideas, I'll be sure to send it this way to > see what you guys think. Perhaps I'll submit a patch for some code > documentation? Maybe a simple commented out explanation to go above > the method? I'll take a look at some other comments and try to model > those. Would that be welcome? Is the process for that to create a > ticket in trac? > > Thanks Please do submit a patch! They're very welcome, and yes, the proper way to submit it would be by creating a new ticket in trac. Cheers, Stephen From martindemello at gmail.com Fri Jul 27 08:37:31 2007 From: martindemello at gmail.com (Martin DeMello) Date: Fri, 27 Jul 2007 18:07:31 +0530 Subject: locals within a partial Message-ID: How do you access something you've passed to a partial in the locals hash? <% for file in @file_list %> <%= render_no_layout :template => "/shared/_file", :locals => { :file => file } %> <% end %> but when rendering the shared/_file.rhtml template it complains about missing local variable or method 'file' martin From ez at engineyard.com Fri Jul 27 16:45:29 2007 From: ez at engineyard.com (Ezra Zygmuntowicz) Date: Fri, 27 Jul 2007 13:45:29 -0700 Subject: locals within a partial In-Reply-To: References: Message-ID: <482CA64F-AD8A-43EF-9FC2-AF827814FF29@engineyard.com> On Jul 27, 2007, at 5:37 AM, Martin DeMello wrote: > How do you access something you've passed to a partial in the > locals hash? > > <% for file in @file_list %> > > <%= render_no_layout :template => "/shared/_file", > :locals => { :file => file } %> > > <% end %> > > but when rendering the shared/_file.rhtml template it complains about > missing local variable or > method 'file' > > martin Hi Martin- Use the partial() method to render partials or render :partial => > <% for file in @file_list %> > > <%= render :partial => "/shared/file", > :locals => { :file => file } %> > > <% end %> Cheers- -- Ezra Zygmuntowicz -- Founder & Ruby Hacker -- ez at engineyard.com -- Engine Yard, Serious Rails Hosting -- (866) 518-YARD (9273) From matt at aimonetti.net Fri Jul 27 18:35:05 2007 From: matt at aimonetti.net (Matt Aimonetti) Date: Fri, 27 Jul 2007 15:35:05 -0700 Subject: need help with Merb? Message-ID: <20fefa50707271535h74f9ed8fxcaf019e0f6434e16@mail.gmail.com> Ezra, I'm sure you are really busy and can't spend too much working on Merb. Please let us know how we can help you. If the plugin architecture is stable, would you be interested in some of us porting few rails plugins over (such as attachment_fu) ? Or is there anything else we could do during our free hacking time? Thanks, -Matt -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/merb-devel/attachments/20070727/4811c5c4/attachment-0001.html From ez at engineyard.com Fri Jul 27 19:11:57 2007 From: ez at engineyard.com (Ezra Zygmuntowicz) Date: Fri, 27 Jul 2007 16:11:57 -0700 Subject: need help with Merb? In-Reply-To: <20fefa50707271535h74f9ed8fxcaf019e0f6434e16@mail.gmail.com> References: <20fefa50707271535h74f9ed8fxcaf019e0f6434e16@mail.gmail.com> Message-ID: <539A8C46-F486-4183-B44C-0BD4F78259E2@engineyard.com> On Jul 27, 2007, at 3:35 PM, Matt Aimonetti wrote: > Ezra, > > I'm sure you are really busy and can't spend too much working on > Merb. Please let us know how we can help you. > If the plugin architecture is stable, would you be interested in > some of us porting few rails plugins over (such as attachment_fu) ? > Or is there anything else we could do during our free hacking time? > > Thanks, > > -Matt Hey Matt- I have been super busy that last few weeks. But I am giving a talk on merb at the ruby hoedown in a few weeks and really want to push out a 0.4 release by then. The things outstanding for 0.4 release are: * test harness in new generated merb apps with helpers for testing merb without starting a server. * more docs * work on mrblog so I can launch it on merbivore.com * always nice to get more specs for core framework. * better app initialization code * pin down plugin arch I'm hoping to knock out some of these things this weekend. But if anyone wants to help work on these things I welcome it. ALso look at the trac for [Help Wanted] tickets, there are a few in place looking for someone to send patches ;) Cheers- -- Ezra Zygmuntowicz -- Founder & Ruby Hacker -- ez at engineyard.com -- Engine Yard, Serious Rails Hosting -- (866) 518-YARD (9273) From mattaimonetti at gmail.com Sat Jul 28 22:22:14 2007 From: mattaimonetti at gmail.com (Matt Aimonetti) Date: Sat, 28 Jul 2007 19:22:14 -0700 Subject: Merb test harness Message-ID: Ezra, * test harness in new generated merb apps with helpers for testing merb without starting a server. * pin down plugin arch Seems to me that these two tasks go together unless you want to have rspec built in Merb. Regarding the test harness, my understanding is that: - a developer should be able to easily write specs against a merb application. - a developer should not need to start a merb server to test his/her app - a developer should be able to generate a Model and its examples - a developer should be able to generate a Controller and its examples - a developer should be able to generate a view and its examples - a developer should be able to use merb built in example helpers (mock a request..) - a merb plugin developer should be able to test his/her plugin Is that correct? Do you mind if we create a list of user stories, assign priorities (critical, essential, nonessential) and try to get things done? Or do you prefer to just work on it and we'll see later on? ;) -Matt On 7/27/07, Ezra Zygmuntowicz wrote: > > On Jul 27, 2007, at 3:35 PM, Matt Aimonetti wrote: > > > Ezra, > > > > I'm sure you are really busy and can't spend too much working on > > Merb. Please let us know how we can help you. > > If the plugin architecture is stable, would you be interested in > > some of us porting few rails plugins over (such as attachment_fu) ? > > Or is there anything else we could do during our free hacking time? > > > > Thanks, > > > > -Matt > > Hey Matt- > > I have been super busy that last few weeks. But I am giving a talk > on merb at the ruby hoedown in a few weeks and really want to push > out a 0.4 release by then. > > The things outstanding for 0.4 release are: > > * test harness in new generated merb apps with helpers for testing > merb without starting a server. > * more docs > * work on mrblog so I can launch it on merbivore.com > * always nice to get more specs for core framework. > * better app initialization code > * pin down plugin arch > > I'm hoping to knock out some of these things this weekend. But if > anyone wants to help work on these things I welcome it. > > ALso look at the trac for [Help Wanted] tickets, there are a few in > place looking for someone to send patches ;) > > > Cheers- > -- Ezra Zygmuntowicz > -- Founder & Ruby Hacker > -- ez at engineyard.com > -- Engine Yard, Serious Rails Hosting > -- (866) 518-YARD (9273) > > > -- m|a agile development -------- (760) 536-4425 Skype: mattdesktop GTalk: mattaimonetti at gmail.com blog: http://railsontherun.com From ez at engineyard.com Sun Jul 29 00:35:09 2007 From: ez at engineyard.com (Ezra Zygmuntowicz) Date: Sat, 28 Jul 2007 21:35:09 -0700 Subject: Merb test harness In-Reply-To: References: Message-ID: Matt- Chris and I did some work today on refactoring merb to be more testable. We will be doing some more work tomorrow. You should hop on irc.freenode.net in #merb and discuss stuff with us in there. Its failry active for bouncing around ideas. If you wanted to work on model,controller and view generators I think that would be great. Hopefully we will nail down the test interfaces tomorrow and we can go from there. Cheers- -Ezra On Jul 28, 2007, at 7:22 PM, Matt Aimonetti wrote: > Ezra, > > * test harness in new generated merb apps with helpers for testing > merb without starting a server. > * pin down plugin arch > > Seems to me that these two tasks go together unless you want to have > rspec built in Merb. > > Regarding the test harness, my understanding is that: > > - a developer should be able to easily write specs against a merb > application. > - a developer should not need to start a merb server to test his/ > her app > > - a developer should be able to generate a Model and its examples > - a developer should be able to generate a Controller and its examples > - a developer should be able to generate a view and its examples > - a developer should be able to use merb built in example helpers > (mock a request..) > > - a merb plugin developer should be able to test his/her plugin > > Is that correct? Do you mind if we create a list of user stories, > assign priorities (critical, essential, nonessential) and try to get > things done? Or do you prefer to just work on it and we'll see later > on? ;) > > -Matt > > > On 7/27/07, Ezra Zygmuntowicz wrote: >> >> On Jul 27, 2007, at 3:35 PM, Matt Aimonetti wrote: >> >>> Ezra, >>> >>> I'm sure you are really busy and can't spend too much working on >>> Merb. Please let us know how we can help you. >>> If the plugin architecture is stable, would you be interested in >>> some of us porting few rails plugins over (such as attachment_fu) ? >>> Or is there anything else we could do during our free hacking time? >>> >>> Thanks, >>> >>> -Matt >> >> Hey Matt- >> >> I have been super busy that last few weeks. But I am >> giving a talk >> on merb at the ruby hoedown in a few weeks and really want to push >> out a 0.4 release by then. >> >> The things outstanding for 0.4 release are: >> >> * test harness in new generated merb apps with helpers for testing >> merb without starting a server. >> * more docs >> * work on mrblog so I can launch it on merbivore.com >> * always nice to get more specs for core framework. >> * better app initialization code >> * pin down plugin arch >> >> I'm hoping to knock out some of these things this weekend. >> But if >> anyone wants to help work on these things I welcome it. >> >> ALso look at the trac for [Help Wanted] tickets, there are >> a few in >> place looking for someone to send patches ;) >> >> >> Cheers- >> -- Ezra Zygmuntowicz >> -- Founder & Ruby Hacker >> -- ez at engineyard.com >> -- Engine Yard, Serious Rails Hosting >> -- (866) 518-YARD (9273) >> >> >> > > > > -- > m|a agile development > -------- > (760) 536-4425 > Skype: mattdesktop > GTalk: mattaimonetti at gmail.com > blog: http://railsontherun.com > _______________________________________________ > Merb-devel mailing list > Merb-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/merb-devel -- Ezra Zygmuntowicz -- Founder & Ruby Hacker -- ez at engineyard.com -- Engine Yard, Serious Rails Hosting -- (866) 518-YARD (9273) From chris at octopod.info Sun Jul 29 07:54:25 2007 From: chris at octopod.info (Chris McGrath) Date: Sun, 29 Jul 2007 12:54:25 +0100 Subject: Merb test harness In-Reply-To: References: Message-ID: On 29 Jul 2007, at 03:22, Matt Aimonetti wrote: > Ezra, > > * test harness in new generated merb apps with helpers for testing > merb without starting a server. > * pin down plugin arch > > Seems to me that these two tasks go together unless you want to have > rspec built in Merb. > I'd prefer app testing to be testing framework agnostic, with merb providing as much infrastructure as it can, but no more for xxx_on_merb plugins to use. I'd hope that these plugins might end up living in the merb repo too. I'd also like there to be no explicit dependencies on ActiveRecord in a merb app unless you want them there. I've some app ideas for which AR is overkill and something like ruby-sequel would be a better fit. So I think generating a new merb app should have at least two steps: 1. Generate the merb app & app level tests 2. Generate the DB layer access code & db layer tests The merb repo could contain the basic app & AR stuff as that's there already and other DB layers could either be done as plugins or added to the main repo in time. I think we'd need a separate app generator from merb -g, though that could stay and be re-wired to create a Merb/AR app via the new generator. > Regarding the test harness, my understanding is that: > > - a developer should be able to easily write specs against a merb > application. > - a developer should not need to start a merb server to test his/ > her app > Agreed > - a developer should be able to generate a Model and its examples Yes, but this shouldn't be hardwired to an AR model > - a developer should be able to generate a Controller and its examples > - a developer should be able to generate a view and its examples Yep, I'd include a Mailer here too > - a developer should be able to use merb built in example helpers > (mock a request..) > Yep, as Ezra mentioned in his reply we did some work to help with this yesterday. Controller instantiation and env/param parsing are now separate, so a test can create a controller, mock it, then fire off the request. We moved the Merb::MockRequest into the framework yesterday, so this can be removed from the xxx_on_merb plugins. Let me know if this causes any problems (it shouldn't, it's essentially the same code anywhere I look). I'm wondering whether the test methods, get, post etc. can be part of the framework too, or whether rspec and test/spec will do things differently enough to require specific versions. I don't know a lot about rspec and nothing about it's internals so I'm not sure here. > - a merb plugin developer should be able to test his/her plugin > Sounds good > Is that correct? Do you mind if we create a list of user stories, > assign priorities (critical, essential, nonessential) and try to get > things done? Or do you prefer to just work on it and we'll see later > on? ;) > Stories are good, code is better :) I think having some high level statements about what merb will and will not do/provide for plugins and testing frameworks agreed would be a good start and stories would be one way of getting to them. > -Matt > Cheers, Chris (octopod in #merb) From chris at octopod.info Sun Jul 29 09:30:13 2007 From: chris at octopod.info (Chris McGrath) Date: Sun, 29 Jul 2007 14:30:13 +0100 Subject: Merb test harness In-Reply-To: References: Message-ID: <6D357019-0866-48F6-877B-393DDAF659F7@octopod.info> On 29 Jul 2007, at 12:54, Chris McGrath wrote: > Stories are good, code is better :) I think having some high level > statements about what merb will and will not do/provide for plugins > and testing frameworks agreed would be a good start and stories would > be one way of getting to them. Replying to my own mail :) I've had a look at the rspec_on_rails plugin in mrblog (is this the right place?) and test_spec_on_rails from it's repo. My initial impressions are there are several things merb should do for a test harness: 1. Load the test database 2. Load the app files 3. Provide a FakeRequest 4. Provide MultiPart functionality This seems to be the common stuff between the two plugins at the moment. 1 & 2 are concerned with merb initialization and i'm unsure what the best way of handling this is. re 3 & 4. I called the FakeRequest MockRequest yesterday, this is a bad name as it's not a mock :). I'd like to add in a Merb::Test namespace and have Merb::Test::FakeRequest and Merb::Test::MultiPart for the plugins to use. Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/merb-devel/attachments/20070729/1fca8975/attachment.html From merb at dan-gottlieb.com Sun Jul 29 12:05:34 2007 From: merb at dan-gottlieb.com (Dan Gottlieb) Date: Sun, 29 Jul 2007 12:05:34 -0400 Subject: fcgi? Message-ID: Hi, I've been looking for a light weight alternative to rails for a few small projects, and just came across merb, which looks perfect. The only issue is that merb seems to be tied to mongrel, and I have to deploy to our internal infrastructure which uses FastCGI. How difficult would it be for me to modify merb to support a fcgi interface (actually a rack interface - rack is middleware that standardizes web requests between cgi, fcgi, mongrel, webrick, etc.)? Is the merb code base very tightly coupled with Mongrel? Any suggestions on where to start digging? Thanks, Dan From mattaimonetti at gmail.com Sun Jul 29 13:29:58 2007 From: mattaimonetti at gmail.com (Matt Aimonetti) Date: Sun, 29 Jul 2007 10:29:58 -0700 Subject: fcgi? In-Reply-To: References: Message-ID: One of the major benefit of Merb is that it doesn't use CGI :) the other is that it uses Mongrel :p Camping http://redhanded.hobix.com/bits/campingAMicroframework.html might be a better fit. -Matt On 7/29/07, Dan Gottlieb wrote: > Hi, > > I've been looking for a light weight alternative to rails for a few > small projects, and just came across merb, which looks perfect. The > only issue is that merb seems to be tied to mongrel, and I have to > deploy to our internal infrastructure which uses FastCGI. > > How difficult would it be for me to modify merb to support a fcgi > interface (actually a rack interface - rack is middleware that > standardizes web requests between cgi, fcgi, mongrel, webrick, etc.)? > Is the merb code base very tightly coupled with Mongrel? Any suggestions on > where to start digging? > > Thanks, > Dan > _______________________________________________ > Merb-devel mailing list > Merb-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/merb-devel > -- m|a agile development -------- (760) 536-4425 Skype: mattdesktop GTalk: mattaimonetti at gmail.com blog: http://railsontherun.com From mattaimonetti at gmail.com Mon Jul 30 02:26:08 2007 From: mattaimonetti at gmail.com (Matt Aimonetti) Date: Sun, 29 Jul 2007 23:26:08 -0700 Subject: Merb test harness In-Reply-To: <6D357019-0866-48F6-877B-393DDAF659F7@octopod.info> References: <6D357019-0866-48F6-877B-393DDAF659F7@octopod.info> Message-ID: Sounds good to me. I'm willing to try working on the generator. This is what I had in mind: $ merb -g app bookshop $ merb -g model Book name:string author:string published_at:date After a collision check, merb would automatically generate: - an Active Record Model - a migration file - a fixture file - a rspec example - a unit test I would personally stick to only rspec but I'm fine with adding a unit test template and generate a test and an example per model. Regarding using ruby-sequel instead of Active Record, I think that's a good idea. I would probably have to modify the actual generator and we could add an option for the ORM you want to use. When the developer decides to generate a model, the generator could check on the ORM used and use the proper template. What do you think? Also, I have few newbie questions. How's your development/testing environment like? I guess you don't package/install the gem every time, do you? Do you just work on the files directly in your gems folder? I'm sorry, I never worked on a gem and I couldn't find the rubygems developer guide. (and I prefer to sound ignorant than to waste my time not doing things properly :) ) -Matt On 7/29/07, Chris McGrath wrote: > > > On 29 Jul 2007, at 12:54, Chris McGrath wrote: > > > Stories are good, code is better :) I think having some high level > > statements about what merb will and will not do/provide for plugins > > and testing frameworks agreed would be a good start and stories would > > be one way of getting to them. > > Replying to my own mail :) > I've had a look at the rspec_on_rails plugin in mrblog (is this the right > place?) and test_spec_on_rails from it's repo. My initial impressions are > there are several things merb should do for a test harness: > > 1. Load the test database > 2. Load the app files > 3. Provide a FakeRequest > 4. Provide MultiPart functionality > > This seems to be the common stuff between the two plugins at the moment. > > 1 & 2 are concerned with merb initialization and i'm unsure what the best > way of handling this is. > > re 3 & 4. I called the FakeRequest MockRequest yesterday, this is a bad name > as it's not a mock :). I'd like to add in a Merb::Test namespace and have > Merb::Test::FakeRequest and Merb::Test::MultiPart for the plugins to use. > > Chris > _______________________________________________ > Merb-devel mailing list > Merb-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/merb-devel > > From chris at octopod.info Mon Jul 30 03:59:43 2007 From: chris at octopod.info (Chris McGrath) Date: Mon, 30 Jul 2007 08:59:43 +0100 Subject: Merb test harness In-Reply-To: References: <6D357019-0866-48F6-877B-393DDAF659F7@octopod.info> Message-ID: <05B07878-A261-486B-9A52-7F478A466280@octopod.info> On 30 Jul 2007, at 07:26, Matt Aimonetti wrote: > Sounds good to me. > I'm willing to try working on the generator. > > This is what I had in mind: > > $ merb -g app bookshop > $ merb -g model Book name:string author:string published_at:date > > After a collision check, merb would automatically generate: > - an Active Record Model > - a migration file > - a fixture file > - a rspec example > - a unit test > > I would personally stick to only rspec but I'm fine with adding a unit > test template and generate a test and an example per model. > I like the idea of having a separate script to generate AR/rspec models, which merb -g might call by default. We can then have other scripts for AR/test-spec, ruby-sequel/rspec etc. if people want them enough to write them. They could also be installed as plugins. So you'd be able to do something like: merb -g model -t test-spec -o ruby-sequel name:string author:string but so we don't have to have merb -g know all this stuff before we can test / use it, you should be able to do something like: merb_ar _rspec -g model ... etc. > Regarding using ruby-sequel instead of Active Record, I think that's a > good idea. I would probably have to modify the actual generator and we > could add an option for the ORM you want to use. When the developer > decides to generate a model, the generator could check on the ORM used > and use the proper template. > > What do you think? > Having it autodetect which ORM / BDD library would be cool, but not as important as being able to generate the stuff first. > Also, I have few newbie questions. How's your development/testing > environment like? I guess you don't package/install the gem every > time, do you? Do you just work on the files directly in your gems > folder? I'm sorry, I never worked on a gem and I couldn't find the > rubygems developer guide. (and I prefer to sound ignorant than to > waste my time not doing things properly :) ) > > You want to checkout merb trunk somewhere locally on your machine using svn. Where $ is your terminal prompt $ svn co http://svn.devjavu.com/merb/trunk merb $ cd merb $ rake specs This makes sure everything is working on your machine. For the merb_ar script I mentioned above, I'd break it down into something like the following: bin/merb_ar lib/merb/merb_activerecord_generator/merb_activerecord.rb lib/merb/merb_activerecord_generator/templates/model.erb lib/merb/merb_activerecord_generator/templates/rspec.erb lib/merb/merb_activerecord_generator/templates/test-spec.erb specs/merb/merb_active_record_generator/merb_activerecord_spec.rb specs/merb/merb_active_record_generator/fixtures/model.rb specs/merb/merb_active_record_generator/fixtures/rspec.rb specs/merb/merb_active_record_generator/fixtures/test-spec.rb bin/merb_ar is a simple script which processes command line options and calls the appropriate methods in the merb_activerecord.rb lib. The specs would make sure that calling the methods on the lib generated the correct output by comparing with the expected output in the fixtures dir. You'd possibly need more than the fixtures I've listed here of course :) I'd start with the specs and a simple model fixture, make the lib create the fixture, then move on to the creating the rspec file the same way. You could leave off test-spec for now if you don't know it and someone else can add that. When the lib is producing what it should then you can write the bin/merb_ar script to call it. svn add all the files you've created as part of this, then run svn diff > merb_ar_generator_1.diff and upload that to a new ticket on Trac > -Matt HTH, Cheers, Chris From mattaimonetti at gmail.com Mon Jul 30 06:07:34 2007 From: mattaimonetti at gmail.com (Matt Aimonetti) Date: Mon, 30 Jul 2007 03:07:34 -0700 Subject: Merb test harness In-Reply-To: <05B07878-A261-486B-9A52-7F478A466280@octopod.info> References: <6D357019-0866-48F6-877B-393DDAF659F7@octopod.info> <05B07878-A261-486B-9A52-7F478A466280@octopod.info> Message-ID: Thanks for the help. My 'newbie question' was more related to the fact when I call merb, the request goes through the gem and not my local repo, I was wondering what was the official procedure to avoid that behaviour without breaking my other merb projects. I guess I can just call my generator directly. About the suggested structure, I was thinking more about creating a generic generator class and having many sub classes so we keep our code consistent and we make things easier for developers wanting to write new generators. I'll try to work on that asap -Matt On 7/30/07, Chris McGrath wrote: > > On 30 Jul 2007, at 07:26, Matt Aimonetti wrote: > > > Sounds good to me. > > I'm willing to try working on the generator. > > > > This is what I had in mind: > > > > $ merb -g app bookshop > > $ merb -g model Book name:string author:string published_at:date > > > > After a collision check, merb would automatically generate: > > - an Active Record Model > > - a migration file > > - a fixture file > > - a rspec example > > - a unit test > > > > I would personally stick to only rspec but I'm fine with adding a unit > > test template and generate a test and an example per model. > > > > I like the idea of having a separate script to generate AR/rspec > models, which merb -g might call by default. We can then have other > scripts for AR/test-spec, ruby-sequel/rspec etc. if people want them > enough to write them. They could also be installed as plugins. > > So you'd be able to do something like: > > merb -g model -t test-spec -o ruby-sequel name:string author:string > > but so we don't have to have merb -g know all this stuff before we > can test / use it, you should be able to do something like: > > merb_ar _rspec -g model ... > > etc. > > > Regarding using ruby-sequel instead of Active Record, I think that's a > > good idea. I would probably have to modify the actual generator and we > > could add an option for the ORM you want to use. When the developer > > decides to generate a model, the generator could check on the ORM used > > and use the proper template. > > > > What do you think? > > > > Having it autodetect which ORM / BDD library would be cool, but not > as important as being able to generate the stuff first. > > > > Also, I have few newbie questions. How's your development/testing > > environment like? I guess you don't package/install the gem every > > time, do you? Do you just work on the files directly in your gems > > folder? I'm sorry, I never worked on a gem and I couldn't find the > > rubygems developer guide. (and I prefer to sound ignorant than to > > waste my time not doing things properly :) ) > > > > > > You want to checkout merb trunk somewhere locally on your machine > using svn. > > Where $ is your terminal prompt > > $ svn co http://svn.devjavu.com/merb/trunk merb > $ cd merb > $ rake specs > > This makes sure everything is working on your machine. > > For the merb_ar script I mentioned above, I'd break it down into > something like the following: > > bin/merb_ar > lib/merb/merb_activerecord_generator/merb_activerecord.rb > lib/merb/merb_activerecord_generator/templates/model.erb > lib/merb/merb_activerecord_generator/templates/rspec.erb > lib/merb/merb_activerecord_generator/templates/test-spec.erb > specs/merb/merb_active_record_generator/merb_activerecord_spec.rb > specs/merb/merb_active_record_generator/fixtures/model.rb > specs/merb/merb_active_record_generator/fixtures/rspec.rb > specs/merb/merb_active_record_generator/fixtures/test-spec.rb > > bin/merb_ar is a simple script which processes command line options > and calls the appropriate methods in the merb_activerecord.rb lib. > The specs would make sure that calling the methods on the lib > generated the correct output by comparing with the expected output in > the fixtures dir. You'd possibly need more than the fixtures I've > listed here of course :) > > I'd start with the specs and a simple model fixture, make the lib > create the fixture, then move on to the creating the rspec file the > same way. You could leave off test-spec for now if you don't know it > and someone else can add that. When the lib is producing what it > should then you can write the bin/merb_ar script to call it. > > svn add all the files you've created as part of this, then run svn > diff > merb_ar_generator_1.diff and upload that to a new ticket on Trac > > > -Matt > > HTH, Cheers, > > Chris > _______________________________________________ > Merb-devel mailing list > Merb-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/merb-devel > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/merb-devel/attachments/20070730/ba1d43f9/attachment.html From merb at dan-gottlieb.com Mon Jul 30 07:05:28 2007 From: merb at dan-gottlieb.com (Dan Gottlieb) Date: Mon, 30 Jul 2007 07:05:28 -0400 Subject: fcgi? In-Reply-To: References: Message-ID: Thanks, Matt. I'm under the impression that Camping's meta programming "magic" make it kind of slow for high volume web apps. I still may end up using it, but was hoping to find a good alternative... Dan On 7/30/07, Dan Gottlieb wrote: > Thanks, Matt. I'm under the impression that Camping's meta > programming "magic" make it kind of slow for high volume web apps. I > still may end up using it, but was hoping to find a good > alternative... > > Dan > > On 7/29/07, Matt Aimonetti wrote: > > One of the major benefit of Merb is that it doesn't use CGI :) the > > other is that it uses Mongrel :p > > > > Camping http://redhanded.hobix.com/bits/campingAMicroframework.html > > might be a better fit. > > > > -Matt > > > > On 7/29/07, Dan Gottlieb wrote: > > > Hi, > > > > > > I've been looking for a light weight alternative to rails for a few > > > small projects, and just came across merb, which looks perfect. The > > > only issue is that merb seems to be tied to mongrel, and I have to > > > deploy to our internal infrastructure which uses FastCGI. > > > > > > How difficult would it be for me to modify merb to support a fcgi > > > interface (actually a rack interface - rack is middleware that > > > standardizes web requests between cgi, fcgi, mongrel, webrick, etc.)? > > > Is the merb code base very tightly coupled with Mongrel? Any suggestions on > > > where to start digging? > > > > > > Thanks, > > > Dan > > > _______________________________________________ > > > Merb-devel mailing list > > > Merb-devel at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/merb-devel > > > > > > > > > -- > > m|a agile development > > -------- > > (760) 536-4425 > > Skype: mattdesktop > > GTalk: mattaimonetti at gmail.com > > blog: http://railsontherun.com > > > From chris at octopod.info Mon Jul 30 07:52:22 2007 From: chris at octopod.info (Chris McGrath) Date: Mon, 30 Jul 2007 12:52:22 +0100 Subject: Merb test harness In-Reply-To: References: <6D357019-0866-48F6-877B-393DDAF659F7@octopod.info> <05B07878-A261-486B-9A52-7F478A466280@octopod.info> Message-ID: <083C74AA-7610-45E9-9C2F-FC10004DD4EB@octopod.info> On 30 Jul 2007, at 11:07, Matt Aimonetti wrote: > Thanks for the help. My 'newbie question' was more related to the > fact when I call merb, the request goes through the gem and not my > local repo, I was wondering what was the official procedure to > avoid that behaviour without breaking my other merb projects. I > guess I can just call my generator directly. My apologies, I misread and thought your were a total newbie. > > About the suggested structure, I was thinking more about creating a > generic generator class and having many sub classes so we keep our > code consistent and we make things easier for developers wanting to > write new generators. > > I'll try to work on that asap > Cool, what services would this generic class provide? > > -Matt > Cheers, Chris From ry at tinyclouds.org Mon Jul 30 09:11:27 2007 From: ry at tinyclouds.org (ry dahl) Date: Mon, 30 Jul 2007 15:11:27 +0200 Subject: streaming response Message-ID: <21ee31950707300611x4beaf917gc37c21e52eb3ec39@mail.gmail.com> hello list! I like merb a lot, it frees me from dropping to mongrel every time i want to stream something. i have an action which will stream a list of JSON objects (separated by semicolons). unfortunately because of Mongrel's write-only header hash, once a Content-Length header has been written, I can never again tell it to not send such a thing - and streaming doesn't work if there is a Content-Length header present. I've been forced into returning a Proc like this from my action Proc.new do response.write("HTTP/1.1 200 OK\n") response.write("Cache-Control: no-cache\n") response.write("Pragma: no-cache\n") response.write("Content-type: text/json\n\n") while true sleep wait response.write json end response.done = true end writing the headers myself. i'd much prefer to do something like this: Proc.new do response.send_status_no_connection_close(nil) # nil = no content-length response.send_header response.write("\n\n") while true sleep wait response.write json end response.done = true end Does anyone have suggestions on how to clean up my code so that I don't need to touch raw HTTP? Thanks! ry From ez at engineyard.com Mon Jul 30 20:21:55 2007 From: ez at engineyard.com (Ezra Zygmuntowicz) Date: Mon, 30 Jul 2007 17:21:55 -0700 Subject: streaming response In-Reply-To: <21ee31950707300611x4beaf917gc37c21e52eb3ec39@mail.gmail.com> References: <21ee31950707300611x4beaf917gc37c21e52eb3ec39@mail.gmail.com> Message-ID: <5594173D-28AF-4B3E-96ED-B6A3C31B9FB3@engineyard.com> On Jul 30, 2007, at 6:11 AM, ry dahl wrote: > hello list! > > I like merb a lot, it frees me from dropping to mongrel every time i > want to stream something. > > i have an action which will stream a list of JSON objects (separated > by semicolons). unfortunately because of Mongrel's write-only header > hash, once a Content-Length header has been written, I can never again > tell it to not send such a thing - and streaming doesn't work if there > is a Content-Length header present. > > I've been forced into returning a Proc like this from my action > > Proc.new do > response.write("HTTP/1.1 200 OK\n") > response.write("Cache-Control: no-cache\n") > response.write("Pragma: no-cache\n") > response.write("Content-type: text/json\n\n") > > while true > sleep wait > response.write json > end > response.done = true > end > > writing the headers myself. i'd much prefer to do something like this: > > Proc.new do > response.send_status_no_connection_close(nil) # nil = no > content-length > response.send_header > response.write("\n\n") > > while true > sleep wait > response.write json > end > response.done = true > end > > Does anyone have suggestions on how to clean up my code so that I > don't need to touch raw HTTP? > > Thanks! ry Hey Ry- You could wrap up that logic in a helper method like this: class Merb::Controller def render_stream(&block) Proc.new do response.write("HTTP/1.1 200 OK\n") response.write("Cache-Control: no-cache\n") response.write("Pragma: no-cache\n") response.write("Content-type: text/json\n\n") block.call response.done = true end end end then use it in an action: def someaction render_stream do streaming = true while streaming sleep wait response.write json streaming = false if some_condition end end end Untested here so let me know how it works for you. Cheers- -- Ezra Zygmuntowicz -- Founder & Ruby Hacker -- ez at engineyard.com -- Engine Yard, Serious Rails Hosting -- (866) 518-YARD (9273) From merb at dusty.name Tue Jul 31 00:02:18 2007 From: merb at dusty.name (Dusty Doris) Date: Tue, 31 Jul 2007 00:02:18 -0400 Subject: changeset 355 Message-ID: I have a question about changeset 355 for "Initial support for controllers to be nested in modules and directories." I have probably overlooked something here, but it appears to me that something is missing to be able to route to those nested controllers. Looking in Merb::Dispatcher, it looks like the workflow goes like this. route = route_path(request_uri) route_path then calls Merb::Router.match(path) klass = resolve_controller(route[:controller]) resolve_controller then splits the controller part of the route with segments = controller_name.split('/').map{|s| s.snake_case} However, it appears that Merb::Router.match isn't handing back "module/class". For example: If I setup say an Admin::Articles controller, with an articles resource, then these are the results of those methods. route = Merb::Dispatcher.route_path("/admin/articles") => {:controller=>"articles", :rest=>true, :allowed=>{:get=>"index", :post=>"create"}} Which then resolve_controller gives me: Merb::Dispatcher.resolve_controller(route[:controller]) => Articles However, if I pass it manually like this, it works. Merb::Dispatcher.resolve_controller("admin/articles") => Admin::Articles Is this a missing piece in Router.match or am I supposed to be setting up some other type of route in router.rb in order for this to all work? Sorry if its obvious, its not jumping out at me right now. Thanks Dusty Doris From ez at engineyard.com Tue Jul 31 02:10:08 2007 From: ez at engineyard.com (Ezra Zygmuntowicz) Date: Mon, 30 Jul 2007 23:10:08 -0700 Subject: changeset 355 In-Reply-To: References: Message-ID: On Jul 30, 2007, at 9:02 PM, Dusty Doris wrote: > I have a question about changeset 355 for "Initial support for > controllers to be nested in modules and directories." > > I have probably overlooked something here, but it appears to me that > something is missing to be able to route to those nested controllers. > > Looking in Merb::Dispatcher, it looks like the workflow goes like > this. > > route = route_path(request_uri) > route_path then calls Merb::Router.match(path) > > klass = resolve_controller(route[:controller]) > resolve_controller then splits the controller part of the route with > segments = controller_name.split('/').map{|s| s.snake_case} > > However, it appears that Merb::Router.match isn't handing back > "module/class". > > For example: > > If I setup say an Admin::Articles controller, with an articles > resource, then these are the results of those methods. > > route = Merb::Dispatcher.route_path("/admin/articles") > => {:controller=>"articles", :rest=>true, :allowed=>{:get=>"index", > :post=>"create"}} > > Which then resolve_controller gives me: > > Merb::Dispatcher.resolve_controller(route[:controller]) > => Articles > > However, if I pass it manually like this, it works. > > Merb::Dispatcher.resolve_controller("admin/articles") > => Admin::Articles > > Is this a missing piece in Router.match or am I supposed to be setting > up some other type of route in router.rb in order for this to all > work? > > Sorry if its obvious, its not jumping out at me right now. > > Thanks > Dusty Doris Dusty- I need to write up some docs for this somewhere but the way this works right now is that when you define the route in router.rb you have to set the :controller => 'admin/articles' so r.resources :articles, :controller => 'admin/articles' I probably need to update the routing syntax with a namespace option since you trying to use a top level articles and an admin/articles using r.resources :articles will step on each other. Thats why I said it was preliminary support ;) Cheers- -- Ezra Zygmuntowicz -- Founder & Ruby Hacker -- ez at engineyard.com -- Engine Yard, Serious Rails Hosting -- (866) 518-YARD (9273) From martindemello at gmail.com Tue Jul 31 08:24:45 2007 From: martindemello at gmail.com (Martin DeMello) Date: Tue, 31 Jul 2007 17:54:45 +0530 Subject: merb speed Message-ID: Hi, We have a rails app which is essentially a web UI to a unix filesystem, and which has been performing rather slowly. I've been looking at rewriting it in merb, so I did a quick spike where I ported over all the rails code necessary to log in as a user, and generate the same file list page that rails was serving up. However, the numbers appear quite bad (twice as slow as rails, for a naive benchmark), leading me to believe that I'm doing something wrong. I'll try to get permission to post some code, but on general principles are there any pitfalls to look for when converting rails code to merb? Also, I'm trying to do some sort of rough client-side benchmarking using the following code - is there anything obviously wrong with it? I'm getting numbers of over 10 seconds per page load when I have 50 users repeatedly requesting a dynamic page in a loop: client = HTTPAccess2::Client.new client.set_cookie_store("cookie.dat") client.post(url, {:user_login => login, :user_password => pwd}) client_time = [] all_client_avg = [] all_server_avg = [] $total_client_avg = [] $total_server_avg = [] num_iterations.times do |i| folders = YAML.load(client.get_content("#{url}/folder/all_user_folders")) folders.each do |folder| client_time << Benchmark.realtime do response_size = client.post("#{url}/resources/set_current_folder", {:folder => $folder}).content.length end end client_avg = (client_time.inject(0) {|sum, element| sum + element}) / client_time.length end I'm rather new to both web development and benchmarking, so please feel free to talk to me as if I were an idiot :) martin From rpotter at anl.gov Tue Jul 31 08:37:58 2007 From: rpotter at anl.gov (Randall Potter) Date: Tue, 31 Jul 2007 07:37:58 -0500 Subject: merb speed In-Reply-To: References: Message-ID: <46AF2D26.2030501@anl.gov> Watch this: http://peepcode.com/products/benchmarking-with-httperf and you will no longer be an idiot about benchmarking. :) --R Martin DeMello wrote: > Hi, > > We have a rails app which is essentially a web UI to a unix > filesystem, and which has been performing rather slowly. I've been > looking at rewriting it in merb, so I did a quick spike where I ported > over all the rails code necessary to log in as a user, and generate > the same file list page that rails was serving up. However, the > numbers appear quite bad (twice as slow as rails, for a naive > benchmark), leading me to believe that I'm doing something wrong. I'll > try to get permission to post some code, but on general principles are > there any pitfalls to look for when converting rails code to merb? > > Also, I'm trying to do some sort of rough client-side benchmarking > using the following code - is there anything obviously wrong with it? > I'm getting numbers of over 10 seconds per page load when I have 50 > users repeatedly requesting a dynamic page in a loop: > > client = HTTPAccess2::Client.new > client.set_cookie_store("cookie.dat") > client.post(url, {:user_login => login, :user_password => pwd}) > client_time = [] > all_client_avg = [] > all_server_avg = [] > $total_client_avg = [] > $total_server_avg = [] > num_iterations.times do |i| > folders = YAML.load(client.get_content("#{url}/folder/all_user_folders")) > folders.each do |folder| > client_time << Benchmark.realtime do > response_size = client.post("#{url}/resources/set_current_folder", > {:folder => $folder}).content.length > end > end > > client_avg = (client_time.inject(0) {|sum, element| sum + element}) / > client_time.length > end > > I'm rather new to both web development and benchmarking, so please > feel free to talk to me as if I were an idiot :) > > martin > _______________________________________________ > Merb-devel mailing list > Merb-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/merb-devel > -- ?When something is too hard it means that you?re not cheating enough.? --DHH From ry at tinyclouds.org Tue Jul 31 13:57:39 2007 From: ry at tinyclouds.org (ry dahl) Date: Tue, 31 Jul 2007 19:57:39 +0200 Subject: controller exceptions Message-ID: <21ee31950707311057o173344d7v72506524087067f1@mail.gmail.com> Since Merb has the lovely property of rendering the output of an action, using ruby-level exceptions to render error pages in Merb could be a cute way to approach error handling. Suppose one has an action for editing a product which you would like to restrict to administrators: def edit raise AdminAccessReqired unless session[:user] and session[:user].admin? @product = Product.find(params[:id]) raise UnknownProduct if @product.nil? render end Where AdminAccessReqired and UnknownProduct are ControllerExceptions. The controller exception hierarchy would be rooted with the base class, Merb::ControllerException. The Merb dispatcher would rescue any exception which was a kind_of ControllerException. Derived from ControllerException would be an exception for each of the HTTP error codes. For example: module ControllerExceptions class Unauthorized < ControllerException STATUS_CODE = 401 # ... class Forbidden < ControllerException STATUS_CODE = 403 # ... class NotFound < ControllerException STATUS_CODE = 404 # ... Application authors could place addition derivations into dist/app/exceptions. These must be children of an already defined Merb controller exception class. The user defined exceptions would have a method called 'action' which acts like typical controller action. It is called to render a page when the exception is raised. For example # dist/app/exceptions/admin_access_required.rb class AdminAccessRequired < Merb::ControllerExceptions::Unauthorized def action if session[:user].nil? redirect '/login' else render # views/exceptions/admin_access_required.rhtml end end end If the user is logged in but does not have administrative access, this will render a page describing the problem with the proper HTTP status code 401. The UnknownProduct exception might look like this: # dist/app/exceptions/unknown_product.rb class UnknownProduct < Merb::ControllerExceptions::NotFound def action @id = params[:id] render # views/exceptions/unknown_product.rhtml end end If passed a bad id, the server will respond with 404 and a page that is specific to missing a product. The advantages of this scheme are - Simplifies controller action definitions by placing exceptional logic elsewhere - Eases the conformity to HTTP by returning proper error codes - Could allow for before and after filters around a restricted type of exceptions (eg, for logging purposes) - Further modularizes testing code: one needs only to check that an action raise a particular exception Thoughts? I would gladly implement this and submit a patch if the list thinks this that it is a worth feature. The idea is from Robert Hahn: http://blog.roberthahn.ca/articles/2007/06/22/setting-http-response-codes-with-exceptions ry From ez at engineyard.com Tue Jul 31 15:16:53 2007 From: ez at engineyard.com (Ezra Zygmuntowicz) Date: Tue, 31 Jul 2007 12:16:53 -0700 Subject: controller exceptions In-Reply-To: <21ee31950707311057o173344d7v72506524087067f1@mail.gmail.com> References: <21ee31950707311057o173344d7v72506524087067f1@mail.gmail.com> Message-ID: Hi~ On Jul 31, 2007, at 10:57 AM, ry dahl wrote: > Since Merb has the lovely property of rendering the output of an > action, using ruby-level exceptions to render error pages in Merb > could be a cute way to approach error handling. > > Suppose one has an action for editing a product which you would like > to restrict to administrators: > > def edit > raise AdminAccessReqired unless session[:user] and session > [:user].admin? > @product = Product.find(params[:id]) > raise UnknownProduct if @product.nil? > render > end > > Where AdminAccessReqired and UnknownProduct are ControllerExceptions. > > The controller exception hierarchy would be rooted with the base > class, Merb::ControllerException. The Merb dispatcher would rescue any > exception which was a kind_of ControllerException. Derived from > ControllerException would be an exception for each of the HTTP error > codes. For example: > > module ControllerExceptions > > class Unauthorized < ControllerException > STATUS_CODE = 401 > # ... > > class Forbidden < ControllerException > STATUS_CODE = 403 > # ... > > class NotFound < ControllerException > STATUS_CODE = 404 > # ... > > Application authors could place addition derivations into > dist/app/exceptions. These must be children of an already defined Merb > controller exception class. The user defined exceptions would have a > method called 'action' which acts like typical controller action. It > is called to render a page when the exception is raised. For example > > # dist/app/exceptions/admin_access_required.rb > class AdminAccessRequired < Merb::ControllerExceptions::Unauthorized > def action > if session[:user].nil? > redirect '/login' > else > render # views/exceptions/admin_access_required.rhtml > end > end > end > > If the user is logged in but does not have administrative access, this > will render a page describing the problem with the proper HTTP status > code 401. > > The UnknownProduct exception might look like this: > > # dist/app/exceptions/unknown_product.rb > class UnknownProduct < Merb::ControllerExceptions::NotFound > def action > @id = params[:id] > render # views/exceptions/unknown_product.rhtml > end > end > > If passed a bad id, the server will respond with 404 and a page that > is specific to missing a product. > > The advantages of this scheme are > - Simplifies controller action definitions by placing exceptional > logic elsewhere > - Eases the conformity to HTTP by returning proper error codes > - Could allow for before and after filters around a restricted type of > exceptions (eg, for logging purposes) > - Further modularizes testing code: one needs only to check that an > action raise a particular exception > > Thoughts? > I would gladly implement this and submit a patch if the list thinks > this that it is a worth feature. > > The idea is from Robert Hahn: > http://blog.roberthahn.ca/articles/2007/06/22/setting-http-response- > codes-with-exceptions I like the idea in general but I am slightly concerned about using exceptions extensively for flow control like this because ruby exceptions are really resource intensive and slow as molasses. I've seen exception handling be the cpu bottleneck in a lot of production rails applications. Exceptions have to unwind the stack and setup a bunch of cointext stuff that makes them have a lot of overhead. I'd be willing to entertain the idea though as it does seem like a very nice api, but it would require benchmarking before I would put it in merb core. Can you make a small proof of concept patch that we can benchmark a bit and then decide? Cheers- -- Ezra Zygmuntowicz -- Founder & Ruby Hacker -- ez at engineyard.com -- Engine Yard, Serious Rails Hosting -- (866) 518-YARD (9273) From cocoa.guy at gmail.com Tue Jul 31 18:08:30 2007 From: cocoa.guy at gmail.com (Cocoa Guy) Date: Tue, 31 Jul 2007 15:08:30 -0700 Subject: Deploying with Merb Message-ID: After a half day's work I've created a Merb app to handle file uploads for a Rails app. In my dev environment, I changed the views in the Rails app to point to Merb on port 4000. But now I'm stuck trying to figure out how to deploy my new Merb app on a production server. Looks like originally this was handled with a rewrite rule More recently, the slides here mention a Merb Mongrel handler What's the current best practice for Merb running alongside Rails? Cheers, -pete