我目前有一个调用控制器和方法的表单标签。我是新手组建帮手,我想改变这个form_tag来说同样的事情只是一个form_for
的form_tag:
<%= form_tag({controller: "subscribers", action: "visit"}, method: "get") do %>
控制器:
class SubscribersController < ApplicationController
helper_method :sort_column, :sort_direction
def index
@subscriber = Subscriber.order(sort_column + " " + sort_direction)
end
def new
@subscriber = Subscriber.new
end
def create
@subscriber = Subscriber.create(subscriber_params)
if @subscriber.save
flash[:notice] = "Subscriber Has Been Successfully Created"
redirect_to new_subscriber_path(:subscriber)
else
render "new"
end
end
def search
@subscriber = Subscriber.new
end
def visit
@subscriber = Subscriber.find_by_phone_number(params[:phone_number])
if @subscriber
@subscriber.visit ||= 0
@subscriber.visit += 1
@subscriber.save
flash[:notice] = flash[:notice] = "Thank You #{@subscriber.first_name}. You have #{@subscriber.days_till_expired} until renewal"
redirect_to subscribers_info_path(:subscriber)
else
render "search"
end
end
def info
@subscriber = Subscriber.find_by_phone_number(params[:phone_number])
end
我认为这是足够的信息让我知道你是否需要更多?谢谢!