"No Routes Matches" When Using Current_Page in Rails 3

No routes matches when using current_page in Rails 3

You're missing the id parameter from this helper:

current_page?(:controller => "users", :action => "show", :id => "1")

It expects you to pass a full route through. If you don't want this and only want to match on the controller and action then I would recommend coding your own.

current_page?' not working on application layout

Your route needs a param (:username), which doesn't exist when you are on the homepage.

You can try this:

<% if controller.controller_name == 'merchants' &&
controller.action_name == 'show' %>
<% else %>
<%= render "shared/header" %>
<% end %>

EDIT: added controller_name

Maybe you could use content_for o partials in merchants' views.

No route matches [POST] despite Resources in my Routes file

:cement is not an object it is just a symbol, so how rails will determine where to POST form? If you inspect your form you will see form action as /blog (current page url).

You should either do

<%= form_for :cements, url: cements_path do |f| %>

or

<%= form_for Cement.new do |f| %>

Both of above will generate form action as /cements, which will submit to CementsController create action, But I see in your case you want to submit it to BlogsController so use the appropriate routes(blogs_path). You can use url in second version also.

Rails routing error No route matches [POST] /

You are missing an = in <% articles_path %>. Your <form> tag should be:

<form accept-charset="UTF-8" action="<%= articles_path %>" method="post">

Without the =, the HTML output would have contained action="", causing the form to post to the URL of the current page.

Routing error in rails using current_page?

You should pass the id as well:

<% if current_page?(:controller => 'products', :action => 'show', :id => params[:id]) %>

UPDATE:

But, however, this implementation assumes that the pages that render this partial have id as a param. If they do not, it's better to use a local variable for that.

render :partial => 'blah_blah', :locals => {:id_for_route_verification => params[:id] || 0}

and in the partial use the new local variable

<% if current_page?(:controller => 'products', :action => 'show', :id => id_for_route_verification) %>

I know this is kinda hacky. But, in the first place, you should consider using content_for to render content inside partial conditionally rather than going by current_page? approach



Related Topics



Leave a reply



Submit