Closed eanlain closed 9 years ago
@eanlain , can you explain where you use this helper? storytime_snippet
I tried grep
on local repository (dev branch), searching on this github repository and I can't understand where this helper was invoked. It is not obviously for me :confused:
@rusikf sure thing - text snippets are small chunks of user-editable content that can be re-used in various views in your host app. For example, here's a sample home page view using text snippets.
# app/views/pages/home.html.erb
<div class="row">
<div class="col-md-8">
<h1><%= storytime_snippet("home.header_text") %></h1>
<h2><%= storytime_snippet("home.subheader_text") %></h2>
<div class="explanation-copy">
<%= storytime_snippet("home.explanation_text") %>
</div>
</div>
<div class="col-md-4">
<%= image_tag "screenshot.png" %>
</div>
</div>
They can be managed in the Storytime dashboard, under the Text Snippets section, and allow a user to quickly edit the content of the snippet without of having to change the code and redeploy the application.
Check out Text Snippets in the wiki for more info.
@rusikf just to clarify, its not a helper that's used within the Storytime engine, it's used within the host application.
@eanlain , thank's for this clear explanation! But, now it looks, that i find another bug( or may be this is a strange feature?): I am created snippet and log outed, it looks good on host app! But if I log in, i have a strange error, which shows in trace Couldn't find Storytime::Site with 'id'=
Steps to reproduce:
1) Create sample snippet with name "my_name" and any text in it.
2.1) rails g scaffold tools name:string
2.2) root 'tools#index'
add to routes.rb
2.3) Write in tools/index.html.haml = storytime_snippet("my_name")
Screenshot
@rusikf My first guess is that it has to do with using localhost:3000 as the site's custom domain. We look up the site based on request.host - I don't think that includes the port for starters, and it might not work with localhost. If you open your hosts file and add something like this:
127.0.0.1 app.dev
and then set the site's custom domain to app.dev
you should be able to access the site at www.app.dev:3000. Or you can use POW or lvh.me (an actual web domain that maps to localhost)
@rusikf the first thing you can try is setting the site's custom domain to localhost
instead of localhost:3000
@dvanderbeek thank's for advices !
The problem is more complicated (2 problems in it) , and the problem is resolved!
1) When create new site we have the following code in app/controllers/storytime/application_controller.rb
def scope_current_site
Storytime::Site.current_id = current_storytime_site(request).id
yield
ensure
Storytime::Site.current_id = nil
end
So, ensure block runs always. That's why in app/models/storytime/site.rb
def self.current_id=(id)
Thread.current[:storytime_site_id] = id
end
calls twice, and in the second case, id is nill, that's why Snippet::Site.current
is nil ( which invoked in snippet.html.erb on pundit checking)
I added PR to fix it. #149
@eanlain , @dvanderbeek , @bcroesch what you think about this PR?
2) Year, we can't use localhost or localhost:3000 on creating new site (may be it will be nice to add checking for it?). And if we add another domain to /etc/hosts, as described above @dvanderbeek , everything will work!
When using the
storytime_snippet
method, if no snippet is found then fallback to translation file.