Rails error 404

I'll just start by not knowing any rails, but have to find a solution to the rails problem.

Basically, there is a form that uploads an image, and after the upload is complete, it should be redirected to a page that displays a thank you message. Image upload is working right now, but no redirection occurs and 404 error occurs

this is the form:

<%= 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>

      

and this is the 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

      

Can anyone identify what happened in all of this? Thanks for any suggestions

+3


source to share


3 answers


It turns out there was a change in the mail server settings and it was devastating when trying to connect to the smtp server



0


source


Try changing the following line:

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

      

To:



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

      

You don't have an action show

, but instead you have an action in your controller photo

.

0


source


you need to add show method to your controller

def show 
end

      

add show.html.haml (or erb slim etc.) to your app / views / weather _photos /

if it still doesn't work, insert the line back to see more details.

[UPDATE]

I think the problem in the layout, do you have main.html.erb

to app/views/layouts

?

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

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

      

0


source







All Articles