Rails3 custom route format

In routes.rb I was forced to add:

post 'admin/user_update'

to get my form_tag to work:

form_tag( { :action => :update_user, :id => @user.id }, :remote => :true )

Now I get:

Template is missing

Missing template admin/update_user with {:handlers=>[:erb, :rjs, :builder,
:rhtml, :rxml], :formats=>[:html], :locale=>[:en, :en]} in view paths
"/rails/test/app/views"

My template is update_user.js.erb:

$('#user-edit-<%= @user.id %>').html("&nbsp;");
$('#tr-user-edit-<%= @user.id %>').hide();

How can I get the route to accept that I want to process the request using js?

How can I add js to the :formats?

Please do not use the word "resources" in your reply. I'm aware this is a custom route.

Answers


If I'm understanding correctly, this is a jquery issue (though you never explicitly mentioned jquery)

Try adding:

$(document).ready(function() {
    $.ajaxSetup({ 
        'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")}
    });
});

to your application.js file.


You can add

match 'update_user/:id' => 'admin#update_user', :as => :update_user, :via => :put

to your routes.

In view, you can do,

form_for(@user, :url => update_user_path(@user.id), :remote => true) do |f|
.
.
.

I think as per request type, it should pick up appropriate format file, else you can do is after your controller code,

def update_user
  .
  .
  .
  respond_to do |format|
    format.js
  end
end

Need Your Help

HiJavafx tableview scrollbar thickness by css

css javafx-2 fxml

is it possible to customize TableView's default scrollbar (vertical one) make it thicker?

Data Binding with WPF and MVVM/Model-View-ViewModel

wpf mvvm data-binding

I'm having difficulty correctly Data Binding my models in the view. I have a MainWindowViewModel which contains a list of AlbumViewModels. Each AlbumViewModel holds an AlbumModel. So I have mult...