Rails 404错误

时间:2015-06-23 11:46:01

标签: ruby-on-rails

我首先要说的是我对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>

这是控制器:

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

有人能发现所有这些都有什么问题吗?感谢您的任何建议

3 个答案:

答案 0 :(得分:0)

尝试更改以下行:

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操作,而是在控制器中执行photo操作。

答案 1 :(得分:0)

您需要在控制器中添加show方法

def show 
end

在app / views / weather_photos /

中添加show.html.haml(或erb slim等...)

如果仍然无效,请粘贴您的回溯以查看更多详细信息。

[UPDATE]

我认为问题出在布局上,你的main.html.erb中有app/views/layouts吗?

layout :resolve_layout, :except=>[:photo_ajax]

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

答案 2 :(得分:0)

原来邮件服务器设置发生了变化,尝试连接到smtp服务器时崩溃了