Re: views - html form duplication

2014-04-28 Thread Sebastjan Hribar

Hi,

thank you again for your help.

Firstly, I should apologize for asking something that I could've derived 
from the blog example where partials are well structured and apparent.


Secondly, in the pattern below I couldn't make sense of the 
_post_fields. How is this setup together?


When I implemented

def edit
  form :action = R(PostsNEdit), :method = :post do
_post_fields
  end
end

... I got bad route error.

Then I fixed it by modifying the route like so: R(PostsNEdit, @post) and 
the I got


undefined local variable or method `_post_fields' for 
#Test::Controllers::PostNEdit:0x007f1f95485128.



Anyway, I went back and studied the partials and I've came up with this 
simple test app that works:


https://gist.github.com/sebastjan-hribar/11371787


Another note, in the blog example in the line 96 the update_attributes 
method takes  a hash, but I got an activerecord error, which indicated 
the method needs to have passed in the name and the key: 
@post.update_attribute(:title, input.title).


The app in the gist works by having this implemented.


regards,
seba

P.S.: I'm thinking of putting together a FAQ of all my beginner 
questions and answers provided (or those that I figured out myself). If 
it would be useful I can provide it when finished.



On 24. 04. 2014 22:34, Magnus Holm wrote:

On Thu, Apr 24, 2014 at 10:08 PM, Sebastjan Hribar
sebastjan.hri...@gmail.com wrote:

Hi,

I have a question about duplicating a html form in my views.

To create a new review form in the app I've composed a html form which is a
table and I've ended up with 200+ lines of code due to table row and data
blocks.

This is the input review form for a user to fill out and submit.

My question is about editing an already existing review form. Is there any
way of avoiding the duplication of the html form and reusing the existing
html form? As I understand the inly difference in the edit view is that I
explicitly call the object attributes from the db and represent them in the
input fields. If I can't avoid the duplication I'll end up with another 200+
lines and I should probably then separate my models, views and controllers
into separate files. Right?

This is a common pattern:

   class PostsNew
 def get
   @post = Post.new # new, empty Post-object
   render :new
 end
   end

   class PostsNEdit
 def get(id)
@post = Post.find(id)
render :edit
 end
   end

   module App::Views
 def edit
   form :action = R(PostsNEdit), :method = :post do
 _post_fields
   end
 end

 def new
   form :action = R(Posts), :method = :post do
 _post_fields
   end
 end

 def _form
   input :name = :title, :value = @post.title
 end
   end
___
Camping-list mailing list
Camping-list@rubyforge.org
http://rubyforge.org/mailman/listinfo/camping-list



___
Camping-list mailing list
Camping-list@rubyforge.org
http://rubyforge.org/mailman/listinfo/camping-list


Re: views - html form duplication

2014-04-24 Thread Magnus Holm
On Thu, Apr 24, 2014 at 10:08 PM, Sebastjan Hribar
sebastjan.hri...@gmail.com wrote:
 Hi,

 I have a question about duplicating a html form in my views.

 To create a new review form in the app I've composed a html form which is a
 table and I've ended up with 200+ lines of code due to table row and data
 blocks.

 This is the input review form for a user to fill out and submit.

 My question is about editing an already existing review form. Is there any
 way of avoiding the duplication of the html form and reusing the existing
 html form? As I understand the inly difference in the edit view is that I
 explicitly call the object attributes from the db and represent them in the
 input fields. If I can't avoid the duplication I'll end up with another 200+
 lines and I should probably then separate my models, views and controllers
 into separate files. Right?

This is a common pattern:

  class PostsNew
def get
  @post = Post.new # new, empty Post-object
  render :new
end
  end

  class PostsNEdit
def get(id)
   @post = Post.find(id)
   render :edit
end
  end

  module App::Views
def edit
  form :action = R(PostsNEdit), :method = :post do
_post_fields
  end
end

def new
  form :action = R(Posts), :method = :post do
_post_fields
  end
end

def _form
  input :name = :title, :value = @post.title
end
  end
___
Camping-list mailing list
Camping-list@rubyforge.org
http://rubyforge.org/mailman/listinfo/camping-list