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
How to Read Files in an Eventmachine-Based App
What Does ["String"].Pack('H*') Mean
Cannot Assign Requested Address - Bind(2) (Errno::Eaddrnotavail)
Mismatched Bundler Version - Bundler 2, Ruby 2.6
Ruby Converting String Encoding from Iso-8859-1 to Utf-8 Not Working
Rails Custom Validation Based on a Regex
Ruby on Rails Multiple Http Request at the Same Time
Cannot Install Any Version of Ruby on Mojave - Internal Ranlib Command Failed
How to Inspect What Is the Default Value for Optional Parameter in Ruby's Method
Load Two Ruby Modules/Gems with the Same Name
How to Receive a JSON Object with Rack
How to Install Rails with Jruby
Cocoon Add Association, How to Limit Number of Associations
Ruby: Building a Plot of Function
Zero-Length String Being Returned from String#Split