Rails: link to partial?

At the moment, I am trying to do the following:

I created a few partial ones (e.g. _show_signature.html.erb) for my user. Now I want to show them when I click a link. In my user controller, I created a new action:

  def show_signature
     @is_on_show_signature = true
  end

  def show_information
     @is_on_show_information = true
  end

on my user show.html.erb I encoded this:

<% if @is_on_show_information %>
    <%= render :partial => 'show_information' %>
<% elsif @is_on_show_signature %>
    <%= render :partial => 'show_signature' %>
<% end %>

and in my "navigation bar" I wrote:

  <ul>
    <li class="profile-tab">
      <%= link_to 'Information', show_information_path %>
    </li>
    <li class="profile-tab">
      <%= link_to 'Signature', show_signature_path %>
    </li>
  </ul>

On my .rb routes, I wrote:

  map.show_information '/user-information', :controller => 'user', :action => 'show_information'
  map.show_signature '/user-signature', :controller => 'user', :action => 'show_signature'

now my problem is:

clicking on my info link will redirect me to http: // localhost: 3000 / user-information (because I told him this path in routes.rb - I think), and I get an error message:

uninitialized constant UserController

But this is not what I want ... My user path shows something like:

http: // localhost: 3000 / users / 2-loginname

(by encoding

  def to_param
     "#{id}-#{login.downcase.gsub(/[^[:alnum:]]/,'-')}".gsub(/-{2,}/,'-')
  end

in my user model)

- http://localhost:3000/users/2-test/user-information. , ? , ?

+3
1

Rails, (), () (UsersController) . , Rails , , "user = Users.first", , , , .

, , , link_to_remote, AJAX . , -, , , , .

:

<ul>
  <li class="profile-tab">
    <%= link_to_remote 'Information', show_information_path %>
  </li>
  <li class="profile-tab">
    <%= link_to_remote 'Signature', show_signature_path %>
  </li>
</ul>

, , show_information.rjs :

page.replace_html('extra_information', :partial => 'show_information')

, , :

<div id="extra_information">
  <% if @is_on_show_information %>
    <%= render :partial => 'show_information' %>
  <% elsif @is_on_show_signature %>
    <%= render :partial => 'show_signature' %>
  <% end %>
</div>
+6

Source: https://habr.com/ru/post/1727786/


All Articles