ok I am trying to invoke a DELETE HTTP command using embedded ruby.
SO my code is:
<li><%= link_to "Sign out", signout_path, method: "delete" %></li>
in my routes I got
#Note the use of via: :delete for the signout route, which indicated that it should be invoked using an HTTP DELETE request
match '/signout', to: 'sessions#destroy', via: :delete
but I get this error!
No route matches [GET] "/signout"
I wrote "method: "delete" !! so why does it give me a GET error? ?
guys applying what you told me, including application.js breaks my js code!!
Here is my head code:
</head>
<!-- Ruby Code -->
<%= stylesheet_link_tag "scaffold" %>
<%= stylesheet_link_tag "myCSS/home.css", :media => "all" %>
<%= stylesheet_link_tag "myCSS/JS_dropdown_menu.css", :media => "all" %>
<%= javascript_include_tag "myJS/jquery-1.7.js" %>
<%= javascript_include_tag "myJS/hoverIntent.js" %>
<%= javascript_include_tag "myJS/jquery.dropdown.js" %>
<%= javascript_include_tag "application.js" %>
<%= csrf_meta_tags %>
</head>
You're attempting to make a GET request to a route that would only respond to DELETE.
Why isn't this working? You probably haven't included application.js using this:
<%= javascript_include_tag :application %>
This would include the jquery.js and jquery_ujs.js files that would provide the method: "delete" functionality for your link.
The functionality of passing method: 'delete' relies on having a functioning UJS library. The first thing I would do is make sure that jquery and jquery_ujs JavaScript files are being included correctly.
Related
I have legacy rails 3 app, where I need to modify a page to use tinymce to edit a text_area.
There are existing pages in this app that already use tinymce.
For reasons I cannot go into here, I cannot use any of the tinymce plugins that are available.
Now my problem is as follows.
I have a model called Sections, that has two attributes, section_name and html.
I want to be able to edit the html using tinymce.
My view has a form which is as follows
<%= form_for #section , :url => update_section_path , :method => :put do |f| %>
<%= f.hidden_field :id %>
<%= f.label :section_name , "Section Name" %>
<%= f.text_field :section_name %> <br />
<%= f.label :html, "Html" %>
<%= f.text_area :html %>
<%= f.submit "Update" %>
<% end %>
The form appears as expected.
The TinyMCE editor also appears on the page with the original html.
The problem is that when I click on the Update button, the put query sent to my server, does not contain the new modified content of the Html text_area. It sends back the original text that was in that text_area.
Could anyone help me understand why.
Thanks in advance
=Puneet
I found an issue in my html which was causing this. Once I fixed that issue it worked fine
I am having a weird issue with Devise. I have lists with tasks on them. When you delete a task all of the sudden I get a template error having to do with the User.
It seems like the delete method causes the session to logout and therefore can't find the User when trying to load the template.
I have no idea why this is happening:
_task.html
<div class="tasks">
<%= div_for task do %>
<%= link_to 'Delete', task_path(task), :method => :delete, :class => "delete", :remote => true %> | <%= content_tag(:div, task.task, :class => "task-body") %>
<% end %>
</div>
destroy.js.erb
$("#task_<%= #task.id %>").fadeOut();
ERROR AFTER RELOADING PAGE, THIS IS FOR THE ACCOUNT, LOGOUT ETC in HEADER
No route matches {:action=>"show", :controller=>"users"}
Extracted source (around line #5):
2: <div id ="login">
3: <ul>
4: <li><%= link_to "Sign out", destroy_user_session_path %></li>
5: <li><%= link_to "Account", user_path(current_user) %></li>
6: <li><%= link_to "Things", user_things_path(current_user) %></li>
7:
8: </ul>
Thanks in advance!
After a little more searching I found the answer here on stackoverflow, so credit should go to justsee from this previous question
The request will not include the required CSRF data, and as of
Rails 3.0.4 the session is silently reset instead of throwing an
ActionController::InvalidAuthenticityToken error.
To fix this include the following in your layout:
<%= javascript_include_tag :defaults %>
<%= csrf_meta_tag %>
How can i add multiple css files in rails project ?
I do,
<%= stylesheet_link_tag :cssone %>
Now i need to add more css file.
There are some method to achieve this. First of all, you can specify each manually :
<%= stylesheet_link_tag "first.css" %>
<%= stylesheet_link_tag "second.css" %>
<%= stylesheet_link_tag "third.css" %>
Then, you can wrap those 3 lines in a single one :
<%= stylesheet_link_tag "first.css", "second.css", "third.css" %>
Also, if you want to include all of your stylesheets in the dedicated rails folder (/public/stylesheets/), you can do :
<%= stylesheet_link_tag :all %>
If you have subfolders in the dedicated folder, you have to include the :recursive option
<%= stylesheet_link_tag :all, :recursive => true %>
<%= stylesheet_link_tag :cssone, :csstwo, and so on... %>
In your (assets/stylesheets)
Add your multiple css file let us take eg-a.css,b.css and c.css
NOW
In application.rb write
<%= stylesheet_link_tag "first.css", "second.css", "third.css" %>
In my Rails3 app I have:
<%= link_to "Sign out", destroy_user_session_path %>
I know how to localize text, but how to localize link text? I defined "sign_out" in tried:
<%= link_to t( sign_out ), destroy_user_session_path %>
But it generates an error:
undefined local variable or method `sign_out'
What is the correct syntax?
PS: It is even more basic than this question, but I could not find any answer.
<%= link_to t('sign_out'), destroy_user_session_path %>
And you must define the key sign_out: in your local yml file after
How about link_to t("sign_out"), destroy_user_session_path?
<%= link_to t(:sign_out), destroy_user_session_path %>
or
<%= link_to t('sign_out'), destroy_user_session_path %>
You can check other details here.
I'm migrating from rails2 to rails3 and I came across the following error:
Unknown action
The action 'show' could not be found for SessionLocalesController
that's because I have a link_to with a method: post inside.
My previous research indicates that I should use button instead or add <%= javascript_include_tag :defaults %> line to my code, because rails3 is unobtrusive javascrtipt:
1.Button is not a solution because the same problem is happening elsewhere so making this work as it is will solve it as well.
2.The <%= javascript_include_tag :defaults %> seems to work, but it give this error instead:
Routing Error
No route matches "/dropup"
I'm stuck now. Thanks in advance for your time.
As asked, here's the code:
<% for locale in (I18n.available_locales) -%>
<%= link_to image_tag("flags/" + locale.to_s + ".png", :title=>locale.to_s) + " " + locale.to_s, session_locale_path(:new_locale => locale.to_s), :method => :post %> <%=link_to t('language'), 'dropup', {:id=>"language_select", :class=>"language_select",:title => t('translate.change')} %>
<ul id="language_menu" style="display:none">
<% for locale in (I18n.available_locales) -%>
<li><%= link_to image_tag("flags/" + locale.to_s + ".png", :title=>locale.to_s) + " " + locale.to_s, session_locale_path(:new_locale => locale.to_s), :method => :post %> </li>
I've solved this. That same problem has been solved before here in stackoverflow many times, but only after finding the solution I noticed it. Well, here it is>
http://www.simonecarletti.com/blog/2010/06/unobtrusive-javascript-in-rails-3/
Get jQuery and add the following to your layouts:
<%= javascript_include_tag :defaults %>
<%= csrf_meta_tag %>
More info on the link I supplied.