在看一个老视频
http://railscasts.com/episodes/38-multibutton-form
new.rhtml 会根据 params[:preview_button] 来显示@project.description。
view 不是只能访问 controller 中的实例变量吗?求答疑解惑
projects/new.rhtml
<% if params[:preview_button] %>
<%= textilize @project.description %>
<% end %>
...
<%= submit_tag 'Create' %>
<%= submit_tag 'Preview', :name => 'preview_button' %>
projects_controller.rb
def create
@project = Project.new(params[:project])
if params[:preview_button] || [email protected]
render :action => 'new'
else
flash[:notice] = "Successfully created project."
redirect_to project_path(@project)
end
end