-1

So I have a link

<%= link_to 'edit', action: :edit_employee, controller: :admin, {:class => 'dialog'} %>

And in the edit_employee action i want to say something like:

if :class = 'dialog' then render layout: false end

Is it possible to get that HTML class from the action after clicked without sending a parameter?

Devon Quick
  • 348
  • 1
  • 17
  • Without sending a parameter? No. – jvillian Dec 30 '17 at 00:58
  • 1
    just pass an extra param duplicating your class like shown here https://stackoverflow.com/questions/1898737/pass-parameter-by-link-to-ruby-on-rails – Maxence Dec 30 '17 at 00:58
  • The OP says "without sending a parameter"... – jvillian Dec 30 '17 at 00:59
  • dohhh, but why ... – Maxence Dec 30 '17 at 01:01
  • Maybe he means by not sending a param: not sending a form. He may not know he can just add the param to a link_to. Otherwise creating a specific action for each value of class. But not very dry. – Maxence Dec 30 '17 at 01:09
  • Without sending parameters it is not possible. Please share your exact requirement. Are you trying to open dialog box ? If yes than you add `remote: true` and check for `xhr?` if no than you will have to share what you are trying to achieve – Manishh Dec 30 '17 at 02:47
  • That's what i thought... The reason why I didn't want a param was because If someone copies the link, i want the layout to show. Yes it is a dialog when clicked – Devon Quick Dec 30 '17 at 06:07
  • @DevonQuick i have given you an alternative way to do this, let me know if its useful for you . thanks – Anand Dec 30 '17 at 06:39

1 Answers1

1

There is an alternative way to do this to send a hidden_field but with this you would need to use form

for example: -

<%= form_tag url_for(:controller => 'admin', :action => 'edit_employee') do  %>
  <%= hidden_field_tag 'is_dialog', 'true'  %>
  <!--you can edit this button using css to look it like `link_to` -->
  <% content_tag :button :type => :submit, :class => :your_class do %>
     Edit
  <% end %>
<%end%>

at controller you can do this: -

def edit_employee
  if params[:is_dialog] == 'true'
   #render layout: false
  else
   #your code...
  end
end

hope its clear for you,this is just an alternative way, otherwise you can do is using ajax request in which whatever you will send will not visible in url,

Anand
  • 6,457
  • 3
  • 12
  • 26