I use form_for to save a model object site
<% form_for :site :url => {:controller => 'site', :action => 'add_site' } do |f| -%>
开发者_如何学Go <%= f.text_field :protocol, :size => 127, :style => 'width:255px' , :value => "http://"%>
<%= f.text_field :site_name, :size => 127, :style => 'width:255px' , :value => "www."%>
<%= f.hidden_field :user_id, :value => @user.id %>
<%= f.hidden_field :status, :value => 'Not Verified' %>
<% end -%>
here the field protocol is not a instance of the model site
. but i just want to pass to the action add_site so that i can use as params[:protocol]
what should i do to achieve this?
You can set something like this:
<%= text_field_tag :protocol %>
To the action of the controller you can refer to this as params[:protocol]
Add it to your site model as an attribute accessor:
attr_accessor :protocol
See http://railscasts.com/episodes/16-virtual-attributes .
精彩评论