ArgumentError (2 for 1):Rails3.1.0 <%= styl

2019-08-09 07:05发布

问题:

wrong number of arguments (2 for 1) Extracted source (around line #5):

<html>
<head>
<title>Assets</title>
<%= stylesheet_link_tag 'application'%>
<%= javascript_include_tag %>
<%= csrf_meta_tags %>
</head>

I've tried:

<%= stylesheet_link_tag :all %> 

but I got:

<link href='assets/all.css' ...>

What confused me most is that I run an app on my MAC OS with almost the same config except mysql&Gemfile and it works well, but when I turn to centos5 I got these errors!

回答1:

I had this problem too, and it turned out to be due to some code still targeting an older rails version, before the new asset pipeline work. Specifically, I had a redmine plugin using the method image_path with two arguments:

image_path('database_refresh.png', :plugin => 'redmine_rate')

This was no longer possible, and needed to be replaced with code that explicitly calculated the plugin specific path. I used code based on the wiki document at http://www.redmine.org/boards/3/topics/31445#Links-and-paths-to-plugin-assets

Note that this solution was for a problem I had with redmine, not rails, but could in fact be relevant.



回答2:

<%= stylesheet_link_tag    "application" %>

Should be fine. Rails has an assets pipeline to merges all the different stylesheets into one for the productive environment. I think it is an error in the assets pipeline.

Here is a good tutorial about this pipeline: http://railscasts.com/episodes/279-understanding-the-asset-pipeline

To possibly fix your error have a look at config/environments/production.rb and try to set this to true

config.assets.compile = true

Another problem might be the configuration in the application.css have you perhaps deleted the comments or added something?

/*
 * This is a manifest file that'll automatically include all the stylesheets available in this directory
 * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
 * the top of the compiled file, but it's generally better to create a new file per style scope.
 *= require_self
 *= require_tree .
*/

But these are just guesses... but I hope this leads you towards the solution of the problem.