开发者

Trying to add ajax to RoR app

I get an ActionView::MissingTemplate error trying to add ajax to开发者_运维百科 a Twitter-like micropost controller. Here's the full error:

ActionView::MissingTemplate (Missing template microposts/create with {:handlers=>[:rhtml, :erb, :rxml, :builder, :rjs], :locale=>[:en, :en], :formats=>[:js, :html]} in view paths "/rubyprograms/sample_app/app/views"):
app/controllers/microposts_controller.rb:9:in `create'

Here's my create method. Btw line 9 is the respond_to line:

  def create
@micropost  = current_user.microposts.build(params[:micropost])
if @micropost.save
  flash[:success] = "Micropost created!"
  respond_to do |format|
    format.html { redirect_to root_path }
    format.js
  end
else
  @feed_items = []
  render 'pages/home'
 end
end

What am I doing wrong?

UPDATE: I have my .rjs file in my views folder. Is that where it should be? Should the file have a specific name? It's currently called create.rjs


The create.rjs should be under app/views/microposts


The name of the file should be

create.js.erb

Then in your controller you must use a:

respond_to do |format|
  format.js # view create.js.erb
end


In order to use rjs in rails 3, use *

prototype-rails

* gem

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜