No route matches assets - ruby-on-rails

Whenever I try to upload a file with Carrierwave + s3 on my Heroku app I get this error "We're sorry, but something went wrong.", looking into my log I see this error:
2012-08-20T21:18:56+00:00 app[web.1]: Started GET "/assets/" for 24.90.124.181 at 2012-08-20 21:18:56 +00002012-08-20T21:18:56+00:00 app[web.1]:2012-08-20T21:18:56+00:00 app[web.1]: ActionController::RoutingError (No route matches [GET] "/assets"):
I've did everything in this tutorial to deploy my app to Heroku on the Cedar stack, but I still see that error. I also had to add this to my application.html
<%= javascript_include_tag :defaults %> <%= javascript_include_tag "jquery" %> <%= javascript_include_tag "nested_form"%> <%= javascript_include_tag "application"%>
because having <%= javascript_include_tag "application" %> only loaded "application.js"
I've tried everything I come across trying to get my uploader to work, but I don't know what the problem is. Everything works perfectly on my local app.
This is my app on github
My Heroku app

you can easyly replace the
<%= javascript_include_tag :defaults %>
<%= javascript_include_tag "jquery" %>
<%= javascript_include_tag "nested_form"%>
<%= javascript_include_tag "application"%>
with: <%= javascript_include_tag "application" %> if your application.js file do this imports.
the default imports are:
//= require jquery
//= require jquery_ujs
//= require_tree .
if the problem is a missing javascript this should fix it
Other problem i see was this link inside app/views/deals/show.html.erb:
<%= image_tag(#deal.user.logo, :class => 'company_logo') %>
this line is returning this html:
<img alt="Assets" class="company_logo" src="/assets/">
this img src is invalid, and that is the error your are receiving on log.
if this image tag could link to an image path, like /assets/avatar.png i believe your problem will be fixed

Since you are using Carrierwave, you need to do the following:
<%= image_tag(#deal.user.logo.url, :class => 'company_logo') %>
or
<%= image_tag(#deal.user.logo.current_path, :class => 'company_logo') %>

Related

How to use datepicker in rails without gem?

I have tried with gem datepicker, but i have to use datepicker without any gem of datepicker?
i have added datepicker js files like
bootstrap-datepicker.ja.js
bootstrap-datepicker.js
this file i have loaded in view(erb)
<%= javascript_include_tag 'locales/bootstrap-datepicker.ja.js', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'bootstrap-datepicker.js', 'data-turbolinks-track' => true %>
but it's not working giving error like
in console:
ActionView::Template::Error (bootstrap-datepicker.js):
error on page:
Sprockets::Rails::Helper::AssetNotPrecompiled in MUser#index
bootstrap-datepicker.js
Check if you have jquery included, otherwise you cannot use bootstrap.
try adding <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> in your view above the other two scripts.
So your code should look something like this:
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<%= javascript_include_tag 'locales/bootstrap-datepicker.ja.js', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'bootstrap-datepicker.js', 'data-turbolinks-track' => true %>
You could also have a look at <%= form.date_field :date_attribute %> - it will use a native date picker, supported by all major browsers.
See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date
<%= form.date_field :date, attribute: 'date' %>
where the :date is your model

Rails "remote: true" works with link_to, doesn't work with form_tag

My rails app uses UJS to submit forms all over the place, but for some reason I can't get it to work here.
I'm fairly sure I have UJS set up properly (as it works in other places):
#application.html.erb
<%= javascript_include_tag 'application' %>
#assets/javascripts/application.js
//= require jquery
//= require jquery_ujs
In my view, I have both a form_tag and a link_to, both set to remote: true:
<%= form_tag apply_tag_applications_path, remote: true, method: :post do %>
<%= submit_tag "FORM TAG SUBMIT" %>
<% end %>
<%= link_to apply_tag_applications_path, remote: true, method: :post do %>
<h1>LINK TO SUBMIT</h1>
<% end %>
Clicking the link_to works as expected (the request format is JS):
Started POST "/tag_applications/apply" for ::1 at 2017-05-30 11:10:51 -0400
Processing by TagApplicationsController#apply as JS
But clicking the form_tag submits via HTML:
Started POST "/tag_applications/apply" for ::1 at 2017-05-30 11:11:02 -0400
Processing by TagApplicationsController#apply as HTML
Can anyone suggest what might be causing the second one not to work as expected?
Verify that you're referencing the jquery_ujs file in the layout or in assets.
#application.html.erb
<%= javascript_include_tag :jquery, :jquery_ujs %>
#assets/javascripts/application.js
require jquery.js
require jquery_ujs
Also, remote options will only work when you pass an object instead of path to form_for.
This will work
<%= form_for #apply_tag, remote: true, method: :post do |f| %>
<%= f.submit "FORM TAG SUBMIT" %>
<% end %>

Chartkick gem, trying to create a pie chart

I just installed the gem "chartkick" to my gemfile and copyied and pasted some code just to get the project started, this is what I used in my view.
<%= pie_chart({"Football" => 10, "Basketball" => 5}) %>
I also included
<%= javascript_include_tag "path/to/highcharts.js", "chartkick" %>
So that is not the issue but I keep getting this error
Any ideas on what I'm doing wrong?
Try this, After installing the "chartkick" gem,
replace this javascript include tag
<%= javascript_include_tag "path/to/highcharts.js", "chartkick" %>
with this
<%= javascript_include_tag "//www.google.com/jsapi", "chartkick" %>

Action Destroy redirect to Show Action in Rails

I am building a link to delete:
I tried 3 different forms but all of them redirect to Show action:
<%= link_to 'delete',{ :controller => 'admin/brands',:action => 'destroy',:id => brand.id } %>
<%= link_to 'delete',brand,:method => :delete %>
<%= link_to 'delete',:id => brand.id,:method => :delete %>
The problem is when I click the delete link it redirects to Show action. I have searched and found something like:
//= require jquery_ujs add in aplication.js - Correct !
metatags added in layout:
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
Correct!
I also found this option:
config.serve_static_assets = false
I'm using Development enviroment(I think) and not found this option; therefore I don't know why when I click the delete link app redirects to action Show.
UPDATE:
My routes are:
DELETE /en/admin/pages/:id(.:format) admin/pages#destroy {:locale=>"en"}
DELETE /admin/pages/:id(.:format) admin/pages#destroy {:locale=>"pt-BR"}
When I click on any Delete link it redirects me to action Show
Solve this executing rake assets:clean, thanks all.

Delete link sends "Get" instead of "Delete" in Rails 3 view

I'm using Rails 3 and have have a page that outputs a list of posts from the database. I'd like to be able to delete a post from a link.
The 2nd example below works, but the first doesn't. Anybody know why the first won't work? My view contains:
# this link sends a "GET" request which asks for the #show function
<%= link_to 'Delete', post, :method => :delete %>
# this link sends the proper "DELETE" request which asks for the #destroy function
<%= button_to 'Delete', post, :method => :delete %>
My routes file contains the following:
resources :posts
Make sure that your <head> section in the layout includes the following:
<%= javascript_include_tag :defaults %>
<%= csrf_meta_tag %>
In Rails 3, the delete requests are being handled with the help of JavaScript to ensure that the request is being sent correctly. If you don't have the csrf meta tags and the required JavaScript code, delete links won't work. The :defaults JavaScript files include--among others--prototype.js, and application.js. The latter contains the stuff that makes the link work, but relies on the Prototype framework.
If you don't want to use the default Prototype JavaScript libraries, there are ports of application.js for several other frameworks. You can find the jQuery one here, for instance.
Buttons will still work regardless of JavaScript, as the HTML code generated with button_to includes all necessary information by itself. This is why you're seeing the button work while the link doesn't.
looks like
<%= javascript_include_tag :defaults %>
is no longer supported
http://apidock.com/rails/ActionView/Helpers/AssetTagHelper/JavascriptTagHelpers/javascript_include_tag
Instead, you should use
<%= javascript_include_tag 'application' %>
I had the same problem in rails 5.2.3 and this helped me:
layout head:
<%= javascript_include_tag "rails-ujs" %>
config/initializers/assets
Rails.application.config.assets.precompile += %w( rails-ujs.js )
In my case, I was using following.
<%= javascript_include_tag :defaults %>
<%= csrf_meta_tag %>
I was also using jQuery by including jQuery just below default prototype JS. That was causing some sort of conflict.
Destructive actions should be performed as a form submission - http://www.w3.org/2001/tag/doc/whenToUseGet.html#checklist
You can style the button appropriately for delete method or Use Form.
I had the same issue in Rails 6.
The solution by Romalex to include:
<%= javascript_include_tag "rails-ujs" %> in head tag &
Rails.application.config.assets.precompile += %w( rails-ujs.js ) in config/initializers/assets also worked to solve an issue with destroy_user_session in devise which would not DELETE.
So this solution also applies to this question Ruby on Rails - devise users/sign_out not working
This will work. The issue is the fact that you need to pass it the right path so the route gets it.
<%= link_to 'Delete', post_path(post.id), :method => :delete %>
In my case with Rails 5, I was using following in my layout:
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
In this way:
... </title>
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
...
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>
Try this.. its a simple change..
add this to your route.rb file
get '/lists/:list_id/comments/:id' => 'comments#destroy'
I made this change and now its working..
In my case.....
In head:
<%= csrf_meta_tag %>
In config/initializers/assets.rb:
<%= javascript_include_tag :defaults %>
Was the answer! Great call!

Resources