Ruby on rails 表单_标签提交rails
因此,我一直在使用RubyonRails开发一个web应用程序。我的主页上有表单标签,但当我单击“提交”时,它无法将信息保存到来宾或当前用户(我正在使用Desive)并重定向到其他页面。应用程序没有给我任何错误,它只是不接收信息。提前感谢您的帮助Ruby on rails 表单_标签提交rails,ruby-on-rails,forms,devise,Ruby On Rails,Forms,Devise,因此,我一直在使用RubyonRails开发一个web应用程序。我的主页上有表单标签,但当我单击“提交”时,它无法将信息保存到来宾或当前用户(我正在使用Desive)并重定向到其他页面。应用程序没有给我任何错误,它只是不接收信息。提前感谢您的帮助 class PageController < ApplicationController def home unless @button.nil? @location = Place.create(:address
class PageController < ApplicationController
def home
unless @button.nil?
@location = Place.create(:address => params[:place], :phone_number => params[:phone], :name => params[:title], :status => "not_purchased", :user_id => current_or_guest_user.id)
@location.save!
if @location.save && !@location.address.nil?
redirect_to places_path
end
end
end
def index
end
def show
respond_to do |format|
format.html # show.html.erb
format.json { render json: @location }
end
end
def new
end
def create
unless @button.nil?
@location = Place.create(:address => params[:place], :phone_number => params[:phone], :name => params[:title], :status => "not_purchased", :user_id => current_or_guest_user.id)
@location.save!
if @location.save
format.html { redirect_to places_path}
format.json { render action: 'index', status: :created, location: places_path }
else
format.html { render action: 'new' }
format.json { render json: @location.errors, status: :unprocessable_entity }
end
end
end
def map
end
end
class PageController参数[:地点],:电话号码=>参数[:电话],:姓名=>参数[:标题],:状态=>“未购买”,:用户id=>当前或客户用户id)
@地点。保存!
如果@location.save&@location.address.nil?
将\u重定向到位置\u路径
结束
结束
结束
def索引
结束
def秀
回应待办事项|格式|
format.html#show.html.erb
format.json{render json:@location}
结束
结束
def新
结束
def创建
除非@button.nil?
@地点=地点。创建(:地址=>参数[:地点],:电话号码=>参数[:电话],:姓名=>参数[:标题],:状态=>“未购买”,:用户id=>当前或客户用户id)
@地点。保存!
如果@location.save
format.html{redirect_to places_path}
format.json{render action:'index',status::created,location:places\u path}
其他的
format.html{呈现操作:'new'}
format.json{render json:@location.errors,status::unprocessable_entity}
结束
结束
结束
def映射
结束
结束
page/home.html.erb
<section id="content">
<div class="container">
<div class="inside">
<div class="wrapper row-1">
<div class="box col-1 maxheight">
<div class="border-right maxheight">
<div class="border-bot maxheight">
<div class="border-left maxheight">
<div class="left-top-corner maxheight">
<div class="right-top-corner maxheight">
<div class="right-bot-corner maxheight">
<div class="left-bot-corner maxheight">
<div class="inner">
<h3>Check Availability</h3>
<section style="border: 1px solid black;padding: 10px; margin:10px">
<h5>Add your site(s)</h5>
<b><%= field_set_tag '' do %> </b>
<%= form_tag do %>
<p>
<%= label_tag 'title', "Name of Site"%>
<%= text_field_tag 'title', nil, :placeholder => "Enter your site name", :size => 40%><br/>
</p>
<p>
<%= label_tag 'place', "Address"%>
<%= text_field_tag 'place', nil, :placeholder => "Enter your address", :size => 40%><br/>
</p>
<p>
<%= label_tag 'phone', "Phone number"%>
<%= text_field_tag 'phone', nil, :placeholder => "Enter your phone number", :size => 40%><br/>
</p>
<p><span><span><%=@button = submit_tag "Add me!", data: {:confirm => "Are you sure?"}%></span></span></p>
<% end %>
<% end %>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="clear"></div>
</div>
</div>
</div>
</div>
</section>
检查可用性
添加您的站点
“输入您的站点名称”,:size=>40%>
“输入您的地址”:大小=>40%>
“输入您的电话号码”:大小=>40%>
“你确定吗?”}%>
您可能可以在表单之前删除该字段\u set\u标记。我不知道你的目的是什么,因为你没有传递任何东西给它
然后在表单标签中添加以下内容:
<%= form_tag @location do %>
你不是在那里创造的。您正在create
操作中创建它。因此,在您的“主页”操作中,只需实例化@location
是什么:
@location = Place.new user_id: current_or_guest_user.id
在页面/home.html.erb视图中,form_标签
需要指向控制器操作的URL。它是空的ATM机,因此默认为POST操作,但它没有发布任何内容。尝试:
<%= form_tag @location do %>
此外,@button实例变量总是等于nil,因为它似乎没有在任何地方初始化
<%= form_tag @location do %>