开发者

ActionView::TemplateError (undefined method `pop_up' error In rails

开发者 https://www.devze.com 2023-01-24 21:50 出处:网络
I am very new to Rails . I am trying to get a lightbox on hover the User name.. In my code , i am having a line like

I am very new to Rails .

I am trying to get a lightbox on hover the User name..

In my code , i am having a line like

 <%= hcard_link_to_user h(@blog.user.fullname), @blog.user, :class 开发者_开发技巧=> "underline" %>  

which displays the User name of the person who put the blog.

For a trial i have tried as,

In the View show.html.erb

      <%= pop_up @blog %>

And in the Controller - blog , i have added the method pop_up

 def pop_up
   render :partial => 'shared/pop_up', :layout => false, :locals => {:node => @blog}
 end

Also i had edited the lines in the top the controller as access_control :DEFAULT => 'view_blogs',:pop_up => 'pop_up', [:comment, :reply] => 'comment'

But when i open blog as

http://localhost:3000/blogs/new-blog , i am getting the error as

  Development mode eh? Here is the error - #<ActionView::TemplateError: ActionView::TemplateError (undefined method `pop_up' for #<ActionView::Base:0xb5a8c61c>) on line #25 of app/views/blogs/show.html.erb:

And I have a partial file under shared folder.

Finally in the routes I had edited the lines as ,

  map.resources :questions, :collection => {:pop_up=> :get}


The methods in a controller are actions, as far as I know you can't call them with the method name. I found two possible solutions:

  1. render :action: # Renders the template for the action "goal" within the current controller render :action => "goal", http://rails.rubyonrails.org/classes/ActionController/Base.html#M000464
  2. you could set either a target="_blank" or a JavaScript popup link to that action and submit the @blog via GET or POST. There's a :popup parameter in the link_to helper (http://apidock.com/rails/ActionView/Helpers/UrlHelper/link_to)
0

精彩评论

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

关注公众号