0

Here are my routes:

namespace :management do
  resources :posts do 
    resources :articles
  end
end

This is my simple_form of aricle

<%= simple_form_for [@post, @article],
  :url => management_post_articles_path(@post, @article, :format => :js), :remote => true do |f| %>

Here is my create action

def create
    options = params[:management_article]
    @article = @post.articles.new(handle_post_params(options))
    @article.save
end

The problem here is on submitting this form it is expecting create.rjs file instead of create.js.erb

This is what I'm getting

ActionView::MissingTemplate - Missing template management/articles/create, application/create with {:locale=>[:en], :formats=>[:rjs], :handlers=>[:erb, :builder, :haml, :prawn, :prawn_dsl, :prawn_xxx, :rjs]}. Searched in:

Can someone please help me out..

Thanks in advance

Temerario
  • 53
  • 1
  • 9

2 Answers2

1

Adding render_rjs(page, "management/articles/create.js.erb")to create.rjs made me write my js code in create.js.erb

Temerario
  • 53
  • 1
  • 9
0

Answering to your question:

RJS is a template (similar to an html.erb file) that generates JavaScript which is executed in an eval block by the browser in response to an AJAX request. It is sometimes used (incorrectly?) to describe the JavaScript, Prototype, and Scriptaculous Helpers provided by Rails.

(Rails) What is "RJS"?

As long as you called the controller method with :js format the answer is in the same format.

Rendering a pure JS file in the view doens't make any sense, as long as it won't have any effect. Can you explain what you want to render?

I don't know why this one is not working, but you can do:

respond_to do |format|
  format.js # actually means: if the client ask for js -> return file.js
end

Inside of the controller to solve the issue.

Community
  • 1
  • 1
Jorge de los Santos
  • 4,583
  • 1
  • 17
  • 35
  • Basically mine is a ajax form and I have to show flash message if it is success or render the form with error message. The problem I'm facing here is that I want to write my js code in create.js.erb file instead of in create.rjs file. I did the same thing for my posts form and it has redirected me to a create.js.erb file. But I don't know why in this articles form it is redirecting me to create.rjs file. – Temerario Jun 15 '14 at 17:36
  • Weird behavior indeed. Edited to add solution. – Jorge de los Santos Jun 15 '14 at 18:04
  • Even that didn't work.. Finally rendering js.erb from rjs file – Temerario Jun 15 '14 at 19:25