开发者

Rails beginner help with making a custom order form

So what I basically would like to do is make an order form. In this order form, users will submit information about their company members, and there will also be a part at the end of the order form where the user can select option services that are added by my client from a backend. I am new to rails so I would just like someone to help me make sure that I am going to do this using the best possible practice. Here is what I think I need to do:

  1. Make an Order model
  2. Make a Member model
  3. Make a Field model

In my order model make

has_many :members
has_many :fields

In my member model make belongs_to :order and in my field model make belongs_to :order. Then what I need to do in my orders controller is @fields = Field.all and extract it in a @fields.each block.

P.S. there is one other thing I have to do an开发者_C百科d that is to make the order form displays 3 types of headers: Corporation, LLC, and Non-profit. What I thought would be smart is if in the url I made it like type=1 and type=2 and type=3 and in my model use an if statement like:

def order_type(type)
   if type === "1"
     "corporation"
   elsif type === "2"
     "llc"
   else
     "nonprofit"
  end
end

I think using an if statement is kinda sloppy so for that so if someone could please explain to me the best practice that would be great. Please don't try and answer with a railscasts episode because I have checked out a lot of them already. What I would like is an explanation if possible

Thanks guys it means a lot


Are your fields really so complicated that they require their own model? If your "fields" are a one column list just include them as a column in the model they are applied too.

The problem with using the URL method that you suggested is as follows. Say a user creates a model object and assigns it as a "LLC.". Then your URL would have type=1 somewhere in it as you suggested. Now a user bookmarks this URL and afterwards someone realized it was a typo and instead of LLC the heading should be something else. Now you have a unRESTful situation where you are creating dead links on the Internet or you have urls that are encoded. URL encoding should be used for querying data not dceciding what the data should be.

I would not mess with the urls for the heading question. Instead just add a heading field to the main model that will be displayed and have that field either be LLC etc. Then in the view just have a variable that loads in the value for the object being displayed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜