Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessing View Helpers From Templates #140

Open
PeterMozesMerl opened this issue Nov 16, 2015 · 3 comments
Open

Accessing View Helpers From Templates #140

PeterMozesMerl opened this issue Nov 16, 2015 · 3 comments

Comments

@PeterMozesMerl
Copy link

There is an issue (#89) with the same name. It has been closed with the argument that "View Helpers generally access non-constant data."

This is true for certain helpers. There are others:

2.2.1 :024 > puts image_tag '/{{source}}', alt: '{{alt}}'
<img alt="{{alt}}" src="/{{source}}" />
 => nil 
2.2.1 :025 > puts text_field_tag :title, '{{json_value}}'
<input type="text" name="title" id="title" value="{{json_value}}" />
 => nil 
2.2.1 :026 > puts check_box_tag :sure, '{{value}}', false, id: '{{is-sure}}'
<input type="checkbox" name="sure" id="{{is-sure}}" value="{{value}}" />
 => nil 

Sure, certain options won’t work, like setting the "checked" with JSON and without jQuery. Still, having the Rails helpers would be a huge gain. I think most of the people who use this gem would be able to figure out what works and what doesn’t.

@PeterMozesMerl
Copy link
Author

Also:

= simple_form_for User.new(first_name: '{{first_name}}', last_name: '{{last_name}}') do |f|
    = f.input :first_name
    = f.input :last_name
<form novalidate="novalidate" class="simple_form new_user" id="new_user" action="/users" accept-charset="UTF-8" method="post">
  <input name="utf8" type="hidden" value="&#x2713;" /><input type="hidden" name="authenticity_token" value="XRvodW7AhzpZRMgzYfQazRP3XzNU5MCFzAke2UmQHbfHotfFmCLqlV4zlk7cYbwiChgGx8g8/ZJ1ZNO6p40W3w==" />
  <div class="form-group string optional user_first_name">
    <label class="string optional control-label" for="user_first_name">First name</label>
    <input class="string optional form-control" type="text" value="{{first_name}}" name="user[first_name]" id="user_first_name" />
  </div>
  <div class="form-group string optional user_last_name">
    <label class="string optional control-label" for="user_last_name">Last name</label>
    <input class="string optional form-control" type="text" value="{{last_name}}" name="user[last_name]" id="user_last_name" />
  </div>
</form>

This would work fine in slimbars. The only thing that would require jQuery / whatever is the authenticity_token.

@AlexRiedler
Copy link
Collaborator

I am willing to accept PR for this, I just don't have the time right now to develop it 😞

@PeterMozesMerl
Copy link
Author

Fair enough. I should learn more about the internals of Rails anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants