Sunday 15 July 2012

html - No route matches {:action=>"search", :controller=>"devise/index"} -



html - No route matches {:action=>"search", :controller=>"devise/index"} -

i'm having problem research routes. accuse error:

actioncontroller::urlgenerationerror in devise::sessions#new no route matches {:action=>"search", :controller=>"devise/index"}

my application:

<!doctype html> <html> <head> <title>javendi</title> <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> <%= csrf_meta_tags %> </head> <body> <div class = 'search', style="display:none"> <%= form_for root_path, :url => {:action => 'search', :controller=>"index"} |f|%> <%= text_field_tag "ad[price_min]", @ads_min, :placeholder => 'price min', class: 'price' %> <%= text_field_tag "ad[price_max]", @ads_max, :placeholder => 'price max', class: 'price' %><br> <%= text_field_tag "ad[title]", @ads_text, :placeholder => 'ad name', class: 'titlesearch' %><br> <div class='categorysearch'> <%= collection_select :ad, :category_id, category.all,:id,:name,:prompt => true, :selected => @ads_category_id %> <br></div> <%= f.submit'searc', class: 'bottomsearch' %> <%end%> </div> <div class="cima"> <!-- <a href="https://www.google.com.br/?gfe_rd=cr&ei=hnnovnvjnyim8aab2ihocw&gws_rd=ssl"><img src="assets/2.gif" border="0" onmouseover="this.src='assets/7.gif'" onmouseout="this.src='assets/2.gif'"></a> --> <div class= 'logout'> <% if user_signed_in? %> <%= link_to image_tag('exit.png', width: '50px', height:'50px'),destroy_user_session_path, method: :delete %> <%else%> <%end%> </div> <div class= "home"> <%= link_to image_tag('logo.png'),root_path %> </div> <div class="javendi"> <% if user_signed_in? %> <button class= 'botton1'> <%= link_to 'editar perfil', edit_user_registration_path %>| <%= link_to 'novo anĂșncio', new_ad_path %>| <%= link_to 'meus anĂșncios', my_ads_path %>| <%= link_to 'meus favoritos', fav_ads_path %> </button> <%else%> <button class= 'botton'> <%= link_to 'cadastre-se', new_user_registration_path %> | <%= link_to 'login', new_user_session_path %> </button> <%end%> <div class='triangule'> <div class="seta-cima"> </div> </div> </div> <% if user_signed_in? %> <div id='iconsearh2'> <%= image_tag("search.png") %> </div> <%else%> <div id='iconsearh'> <%= image_tag("search.png") %> </div> <%end%> </div> <script type="text/javascript"> $('#iconsearh').click(function(){ if($('.search').is(':visible')){ $('.search').slideup('fast') $('.seta-cima').css("display","none"); }else{ $('.search').slidedown('fast') $('.seta-cima').show(); } }); </script> <script type="text/javascript"> $('#iconsearh2').click(function(){ if($('.search').is(':visible')){ $('.search').slideup('fast') $('.seta-cima').css("display","none"); }else{ $('.search').slidedown('fast') $('.seta-cima').show(); } }); </script> <div class='cima2'> <div class='welcome'> <% if current_user.present?%> welcome <%=current_user.name%> <%end%> </div> <div class= 'createad'> <%= image_tag('7.gif', width: '50px', height:'50px')%> </div> </div> <div class="results"> <%= yield %> </div> <div class= "bot"> &nbsp </div> </div> </body> </html>

my ads model:

class advertisement < activerecord::base validates_presence_of :title, message: "deve ser preenchido" validates_presence_of :price, message: "deve ser preenchido" validates_presence_of :adress, message: "deve ser preenchido" validates_presence_of :email, message: "deve ser preenchido" validates_presence_of :phone, message: "deve ser preenchido" belongs_to :user belongs_to :category has_many :photos, :dependent => :destroy accepts_nested_attributes_for :photos, :allow_destroy => true has_many :user_ad_favs def can_edit?(current_user) if current_user.present? homecoming current_user.id == self.user_id end end def self.search(query) category = query[:category_id].present? ? "category_id = #{query[:category_id]}" : nil title = query[:title].present? ? "title '%#{query[:title]}%'" : nil price_min = query[:price_min].present? ? "price >= #{query[:price_min].to_f}" : nil price_max = query[:price_max].present? ? "price <= #{query[:price_max].to_f}" : nil query = [category, title, price_min, price_max].compact.join(" , ") homecoming ad.where ( query ) end def user_fav(user) homecoming self.user_ad_favs.find_by_user_id_and_ad_id(user.id, self.id) end end

my ads controller:

class adscontroller < applicationcontroller before_action :set_ad, only: [:show, :edit, :update, :destroy, :fav_ad,:unfav_ad, :search,] # /ads # /ads.json def index @ads = ad.all end # /ads/1 # /ads/1.json def show end # /ads/new def new @ad = current_user.ads.build 1.times { @ad.photos.build} end # /ads/1/edit def edit end def search @ads_min = params[:ad][:price_min] @ads_max = params[:ad][:price_max] @ads_title = params[:ad][:title] @ads_category_id = params[:ad][:category_id] @ads = ad.search(params[:ad]) render :action => 'index' end # post /ads # post /ads.json def create @ad = current_user.ads.build(ad_params) respond_to |format| if @ad.save format.html { redirect_to @ad, notice: 'ad created.' } format.json { render :show, status: :created, location: @ad } else format.html { render :new } format.json { render json: @ad.errors, status: :unprocessable_entity } end end end # patch/put /ads/1 # patch/put /ads/1.json def update respond_to |format| if @ad.update(ad_params) format.html { redirect_to @ad, notice: 'ad updated.' } format.json { render :show, status: :ok, location: @ad } else format.html { render :edit } format.json { render json: @ad.errors, status: :unprocessable_entity } end end end # delete /ads/1 # delete /ads/1.json def destroy @ad.destroy respond_to |format| format.html { redirect_to ads_url, notice: 'ad destroyed.' } format.json { head :no_content } end end def fav_ad user_ad_fav = @ad.user_fav(current_user) if user_ad_fav.present? user_ad_fav.update_attribute(:fav, true) else @ad.user_ad_favs.create(:user_id => current_user.id,:ad_id => @ad.id,:fav => true) end respond_to |format| format.js {render inline: "location.reload();"} end end def unfav_ad @ad.user_fav(current_user).update_attribute(:fav, false) if @ad.user_fav(current_user).present? respond_to |format| format.js {render inline: "location.reload();"} end end private # utilize callbacks share mutual setup or constraints between actions. def set_ad @ad = ad.find(params[:id]) end # never trust parameters scary internet, allow white list through. def ad_params params.require(:ad).permit(:title, :price, :adress, :city, :state, :description, :email, :phone, :phone_type, :category_id, :photos_attributes =>[:photo]) end end

you made error in :controller parameter in form_for:

<%= form_for root_path, :url => {:action => 'search', :controller=>"index"} |f|%>

first of all, :controller should 'ads' since search action in adscontroller provided sample of.

second, you're using form_for wrong. you're passing in 2 different paths, root_path , :url hash. first parameter should model you're trying create form for. don't need here, want search form, utilize form_tag instead:

<%= form_tag :action => 'search', :controller=>"ads" %>

http://api.rubyonrails.org/classes/actionview/helpers/formtaghelper.html#method-i-form_tag

html ruby-on-rails devise

No comments:

Post a Comment