gpt4 book ai didi

ruby-on-rails - rails 404 错误

转载 作者:行者123 更新时间:2023-12-04 05:31:54 24 4
gpt4 key购买 nike

首先我会说我对 Rails 没有任何了解,但必须找到解决 Rails 问题的方法。

基本上有一个上传图片的表单,上传完成后它应该重定向到一个显示感谢消息的页面。现在图像上传工作正常,但重定向不工作,并出现错误 404

这是表格:

<%= form_for(@weather_photo, :html => { :multipart => true }) do |f| %>

<div class="identity">
<p style="color: #00597C;font-weight: bold;">Τα στοιχεία σου</p>
<div class="form-line">
<%= f.label :first_name, 'Όνομα:' %><%= f.text_field :first_name, :size => 22 %>
</div>
<%=render :partial=>"/cmanager/error_msg",:locals=>{:field =>'first_name',:element=>@weather_photo}%>
<div class="form-line">
<%= f.label :last_name, 'Επίθετο:' %><%= f.text_field :last_name, :size => 22 %>
</div>
<%=render :partial=>"/cmanager/error_msg",:locals=>{:field =>'last_name',:element=>@weather_photo}%>
<div class="form-line">
<%= f.label :email, 'Email:' %><%= f.text_field :email, :size => 22 %>
</div>
<%=render :partial=>"/cmanager/error_msg",:locals=>{:field =>'email',:element=>@weather_photo}%>
<div class="form-line">
<%= f.label :description, 'Περιγραφή :' %><%= f.text_field :description %>
</div>
<%=render :partial=>"/cmanager/error_msg",:locals=>{:field =>'description',:element=>@weather_photo}%>
<div class="form-line">
<label>Ελλάδα ή Εξωτερικό : </label><%=select("world", "world_id", [["Ελλάδα",1],["Κόσμος",2]])%>
</div>
<div class="form-line">
<label>Περιοχή ή Χώρα : </label><%=select("region", "region_id",Region.where("id not in (14,15,17,18)").order("name").collect {|p| [ p.name, p.id ] } )%>
</div>
<div class="form-line">
<%= f.label :position_id, 'Πόλη :' %><%=f.select(:position_id,Position.where("region_id=21").order("name").collect {|p| [ p.name, p.id ] })%>
</div>


</div>
<div class="form-line">

<label style="margin-bottom:5px;" for="poi_poi_img">Φωτογραφία:</label>
<%= f.file_field :weather_photo_img %>

</div>
<%=render :partial=>"/cmanager/error_msg",:locals=>{:field =>'weather_photo_img_file_size',:element=>@weather_photo}%>
<%=render :partial=>"/cmanager/error_msg",:locals=>{:field =>'weather_photo_img_content_type',:element=>@weather_photo}%>

<div class="clear"></div>
<div style="clear:both;width: 150px; margin:30px 0 10px 60px;">
<%= f.submit "Καταχώρηση", :class=>"button"%>
</div>

这是 Controller :

class WeatherPhotosController < InheritedResources::Base
layout :resolve_layout, :except=>[:photo_ajax]
protect_from_forgery :only => [ :destroy]
def index
@weather_photos=WeatherPhoto.order("created_at DESC").all.paginate :page => params[:page] || 1, :per_page =>40
end
def photo

@photo=WeatherPhoto.find(params[:id].to_s)

end
def photo_ajax

@photo=WeatherPhoto.find(params[:id].to_s)

respond_to do |format|
format.html
# format.js {render :partial => "/weather_photos/photo_ajax_js"}
end
end
def create

@weather_photo=WeatherPhoto.new(params[:weather_photo])
respond_to do |format|
if @weather_photo.save
NewsLetterMailer.contact_email(params[:weather_photo]["first_name"],
params[:weather_photo]["last_name"],
params[:weather_photo]["email"],
params[:weather_photo]["tel"],
params[:weather_photo]["description"],
@weather_photo.weather_photo_img.path(:original),
@weather_photo.weather_photo_img_file_name
).deliver
format.html { redirect_to({:controller=>"weather_photos", :action=>"show", :id=>@weather_photo}, :notice => 'Το Email σας στάλθηκε επιτυχώς') }
format.xml { head :ok }
else
p @weather_photo.errors
format.html { render :controller=>"weather_photos", :action=>"new"}
format.xml { render :xml => @weather_photo.errors, :status => :unprocessable_entity }
end
end

end
def resolve_layout
case action_name
when "photo"
"photo"
else
"main"
end
end

end

有谁能找出这一切中的问题所在?感谢您的任何建议

最佳答案

尝试更改以下行:

format.html { redirect_to({:controller=>"weather_photos", :action=>"show", :id=>@weather_photo}, :notice => 'Το Email σας στάλθηκε επιτυχώς') }

收件人:

format.html { redirect_to({:controller=>"weather_photos", :action=>"photo", :id=>@weather_photo}, :notice => 'Το Email σας στάλθηκε επιτυχώς') }

您没有show 操作,而是在您的 Controller 中有一个photo 操作。

关于ruby-on-rails - rails 404 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31001935/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com